Loading...
Searching...
No Matches
bsoncxx::v1::oid Class Reference

`#include <bsoncxx/v1/oid.hpp>`

## Description

A BSON ObjectID.

## Public Types

enum class | errc
| Errors codes may be returned by bsoncxx::v1::oid. More...

## Public Member Functions

| oid ()
| Initialize with a unique ObjectID.
| oid (std::uint8_t const *bytes, std::size_t len)
| Initialize with the given ObjectID byte representation.
| oid (v1::stdx::string_view str)
| Initialize with the given ObjectID hexadecimal string representation.
std::uint8_t const * | bytes () const
| Return a pointer to the byte representation.
int | compare (oid const &other) const
| Equivalent to bson_oid_compare.
std::time_t | get_time_t () const
| Return the timestamp component.
std::string | to_string () const
| Return the hexadecimal representation.

## Static Public Member Functions

static std::error_category const & | error_category ()
| The error category for bsoncxx::v1::oid::errc.
static std::size_t | size ()
| Return k_oid_length.

## Static Public Attributes

static constexpr std::size_t | k_oid_length = 12
| The number of bytes required to represent an ObjectID.

## Friends

std::error_code | make_error_code (errc v)
| Support implicit conversion to std::error_code.
bool | operator!= (oid const &lhs, oid const &rhs)
| Equivalent to lhs.compare(rhs) != 0.
bool | operator< (oid const &lhs, oid const &rhs)
| Equivalent to lhs.compare(rhs) < 0.
bool | operator<= (oid const &lhs, oid const &rhs)
| Equivalent to lhs.compare(rhs) <= 0.
bool | operator== (oid const &lhs, oid const &rhs)
| Equivalent to lhs.compare(rhs) == 0.
bool | operator> (oid const &lhs, oid const &rhs)
| Equivalent to lhs.compare(rhs) > 0.
bool | operator>= (oid const &lhs, oid const &rhs)
| Equivalent to lhs.compare(rhs) >= 0.

## Member Enumeration Documentation

## errc

enum class bsoncxx::v1::oid::errc

strong

Errors codes may be returned by bsoncxx::v1::oid.

Enumerator
zero | Zero.
null_bytes_ptr | Bytes pointer must not be null.
invalid_length | Byte length must equal bsoncxx::v1::oid::k_oid_length.
empty_string | String must not be empty.
invalid_string | String is not a valid ObjectID representation.

## Constructor & Destructor Documentation

## oid() [1/3]

bsoncxx::v1::oid::oid | ( |  | ) |

Initialize with a unique ObjectID.

The ObjectID is generated using the bson library's bson_oid_init function with the default bson_context_t.

Important
  On Windows only, the first call to this function initializes a static local variable which loads the Winsock DLL by calling WSAStartup(). The Winsock DLL is unloaded by calling WSACleanup() when the static local variable is destroyed.

Exceptions

  bsoncxx::v1::exception | (on Windows only) with a std::system_category() error code (as returned by WSAGetLastError()) on failure to initialize the Winsock library with WSAStartup().

## oid() [2/3]

bsoncxx::v1::oid::oid | ( | std::uint8_t const * | bytes,
|  | std::size_t | len )

Initialize with the given ObjectID byte representation.

Parameters

  bytes | A pointer to the ObjectID byte representation.
  len | The length of the array pointed to by bytes.

Exceptions

  bsoncxx::v1::exception | with bsoncxx::v1::oid::errc::null_bytes_ptr if bytes is null.
  bsoncxx::v1::exception | with bsoncxx::v1::oid::errc::invalid_length if len is not equal to k_oid_length.

## oid() [3/3]

bsoncxx::v1::oid::oid | ( | v1::stdx::string_view | str | ) |

explicit

Initialize with the given ObjectID hexadecimal string representation.

Parameters

  str | A valid ObjectID represented.

Exceptions

  bsoncxx::v1::exception | with bsoncxx::v1::oid::errc::empty_string if str is empty.
  bsoncxx::v1::exception | with bsoncxx::v1::oid::errc::invalid_string if str is invalid.

## Member Function Documentation

## bytes()

std::uint8_t const * bsoncxx::v1::oid::bytes | ( |  | ) | const

inline

Return a pointer to the byte representation.

## compare()

int bsoncxx::v1::oid::compare | ( | oid const & | other | ) | const

Equivalent to bson_oid_compare.

## error_category()

std::error_category const & bsoncxx::v1::oid::error_category | ( |  | ) |

static

The error category for bsoncxx::v1::oid::errc.

## get_time_t()

std::time_t bsoncxx::v1::oid::get_time_t | ( |  | ) | const

Return the timestamp component.

## size()

std::size_t bsoncxx::v1::oid::size | ( |  | ) |

inline static

Return k_oid_length.

## to_string()

std::string bsoncxx::v1::oid::to_string | ( |  | ) | const

Return the hexadecimal representation.

## Friends And Related Symbol Documentation

## make_error_code

std::error_code make_error_code | ( | errc | v | ) |

friend

Support implicit conversion to std::error_code.

## operator!=

bool operator!= | ( | oid const & | lhs,
|  | oid const & | rhs )

friend

Equivalent to lhs.compare(rhs) != 0.

## operator<

bool operator< | ( | oid const & | lhs,
|  | oid const & | rhs )

friend

Equivalent to lhs.compare(rhs) < 0.

## operator<=

bool operator<= | ( | oid const & | lhs,
|  | oid const & | rhs )

friend

Equivalent to lhs.compare(rhs) <= 0.

## operator==

bool operator== | ( | oid const & | lhs,
|  | oid const & | rhs )

friend

Equivalent to lhs.compare(rhs) == 0.

## operator>

bool operator> | ( | oid const & | lhs,
|  | oid const & | rhs )

friend

Equivalent to lhs.compare(rhs) > 0.

## operator>=

bool operator>= | ( | oid const & | lhs,
|  | oid const & | rhs )

friend

Equivalent to lhs.compare(rhs) >= 0.

## Member Data Documentation

## k_oid_length

std::size_t bsoncxx::v1::oid::k_oid_length = 12

static constexpr

The number of bytes required to represent an ObjectID.

The documentation for this class was generated from the following file:

- bsoncxx/v1/oid.hpp