MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
bsoncxx::v1::oid Class Reference

#include <bsoncxx/v1/oid.hpp>

Description

A BSON ObjectID.

Attention
This feature is experimental! It is not ready for use!

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.

Attention
This feature is experimental! It is not ready for use!
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
bytesA pointer to the ObjectID byte representation.
lenThe length of the array pointed to by bytes.
Exceptions
bsoncxx::v1::exceptionwith bsoncxx::v1::oid::errc::null_bytes_ptr if bytes is null.
bsoncxx::v1::exceptionwith 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
strA valid ObjectID represented.
Exceptions
bsoncxx::v1::exceptionwith bsoncxx::v1::oid::errc::empty_string if str is empty.
bsoncxx::v1::exceptionwith 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.

Attention
This feature is experimental! It is not ready for use!

◆ 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 ( )
inlinestatic

Return k_oid_length.

◆ to_string()

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

Return the hexadecimal representation.

◆ make_error_code

std::error_code make_error_code ( errc v)
friend

Support implicit conversion to std::error_code.

Attention
This feature is experimental! It is not ready for use!

◆ 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
staticconstexpr

The number of bytes required to represent an ObjectID.


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