MongoDB C++ Driver mongocxx-3.7.1
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
bsoncxx::types::bson_value::value Class Reference

A variant owning type that represents any BSON type. More...

#include <value.hpp>

Public Member Functions

 value (const char *v)
 Constructs a BSON UTF-8 string value.
 
 value (std::string v)
 Constructs a BSON UTF-8 string value.
 
 value (stdx::string_view v)
 Constructs a BSON UTF-8 string value.
 
 value (int32_t v)
 Constructs a BSON 32-bit signed integer value.
 
 value (int64_t v)
 Constructs a BSON 64-bit signed integer value.
 
 value (double v)
 Constructs a BSON double value.
 
 value (bool v)
 Constructs a BSON boolean value.
 
 value (oid v)
 Constructs a BSON ObjectId value.
 
 value (decimal128 v)
 Constructs a BSON Decimal128 value.
 
 value (std::chrono::milliseconds v)
 Constructs a BSON date value.
 
 value (std::nullptr_t)
 Constructs a BSON null value.
 
 value (bsoncxx::document::view v)
 Constructs a BSON document value.
 
 value (bsoncxx::array::view v)
 Constructs a BSON array value.
 
 value (std::vector< unsigned char > v, const binary_sub_type sub_type={})
 Constructs a BSON binary data value.
 
 value (const uint8_t *data, size_t size, const binary_sub_type sub_type={})
 Constructs a BSON binary data value.
 
 value (stdx::string_view collection, oid value)
 Constructs a BSON DBPointer value.
 
 value (stdx::string_view code, bsoncxx::document::view_or_value scope)
 Constructs a BSON JavaScript code with scope value.
 
 value (stdx::string_view regex, stdx::string_view options)
 Constructs a BSON regex value with options.
 
 value (const type id, stdx::string_view v)
 Constructs one of the following BSON values (each specified by the parenthesized type):
 
 value (const type id)
 Constructs one of the following BSON values (each specified by the parenthesized type):
 
 value (const type id, uint64_t a, uint64_t b)
 Constructs one of the following BSON values (each specified by the parenthesized type):
 
 value (const view &)
 Create an owning copy of a bson_value::view.
 
bson_value::view view () const noexcept
 Get a view over the bson_value owned by this object.
 
 operator bson_value::view () const noexcept
 Conversion operator that provides a bson_value::view given a bson_value::value.
 

Friends

class bsoncxx::document::element
 

Related Functions

(Note that these are not member functions.)

bool operator== (const value &lhs, const value &rhs)
 Compares values for (in)-equality.
 
bool operator== (const value &lhs, const view &rhs)
 Compares a value with a view for (in)-equality.
 

Detailed Description

A variant owning type that represents any BSON type.

Owns its underlying buffer. When a bson_value::value goes out of scope, its underlying buffer is freed.

For accessors into this type and to extract the various BSON types out, please use bson_value::view.

Constructor & Destructor Documentation

◆ value() [1/8]

bsoncxx::types::bson_value::value::value ( std::vector< unsigned char >  v,
const binary_sub_type  sub_type = {} 
)

Constructs a BSON binary data value.

Parameters
va stream of bytes
sub_typean optional binary sub type. Defaults to type::k_binary

◆ value() [2/8]

bsoncxx::types::bson_value::value::value ( const uint8_t *  data,
size_t  size,
const binary_sub_type  sub_type = {} 
)

Constructs a BSON binary data value.

Parameters
datapointer to a stream of bytes
sizethe size of the stream of bytes
sub_typean optional binary sub type. Defaults to type::k_binary

◆ value() [3/8]

bsoncxx::types::bson_value::value::value ( stdx::string_view  collection,
oid  value 
)

Constructs a BSON DBPointer value.

Parameters
collectionthe collection name
valuethe object id
Deprecated:
A BSON DBPointer (aka DBRef) is still supported but deprecated.

◆ value() [4/8]

bsoncxx::types::bson_value::value::value ( stdx::string_view  code,
bsoncxx::document::view_or_value  scope 
)

Constructs a BSON JavaScript code with scope value.

Parameters
codethe JavaScript code
scopea bson document view holding the scope environment

◆ value() [5/8]

bsoncxx::types::bson_value::value::value ( stdx::string_view  regex,
stdx::string_view  options 
)

Constructs a BSON regex value with options.

Parameters
regexThe regex pattern
optionsThe regex options

◆ value() [6/8]

bsoncxx::types::bson_value::value::value ( const type  id,
stdx::string_view  v 
)

Constructs one of the following BSON values (each specified by the parenthesized type):

  • BSON code value (type::k_code)
  • BSON regex value (type::k_regex)
  • BSON symbol value (type::k_symbol)
Parameters
idthe type of BSON value to construct.
vthe symbol, JavaScript code, or regex pattern for the BSON symbol, code, or regex value respectively.
Exceptions
bsoncxx::exceptionif the type's value is not k_code, k_regex, or k_symbol.
Deprecated:

The BSON symbol type is deprecated and use by clients is discouraged.

The BSON undefined type is deprecated and use by clients is discouraged.

◆ value() [7/8]

bsoncxx::types::bson_value::value::value ( const type  id)

Constructs one of the following BSON values (each specified by the parenthesized type):

  • BSON maxkey value (type::k_maxkey)
  • BSON minkey value (type::k_minkey)
  • BSON undefined value (type::k_undefined)
Parameters
idthe type of BSON value to construct.
Exceptions
bsoncxx::exceptionif the type's value is not k_maxkey, k_minkey, or k_undefined.

◆ value() [8/8]

bsoncxx::types::bson_value::value::value ( const type  id,
uint64_t  a,
uint64_t  b 
)

Constructs one of the following BSON values (each specified by the parenthesized type):

  • BSON decimal128 value (type::k_decimal128)
  • BSON timestamp value (type::k_timestamp)
Parameters
idthe type of the BSON value to construct.
aIf a BSON decimal128 value is to be constructed, this is the high value. If a BSON timestamp value is to be constructed, this is the increment.
bIf a BSON decimal128 value is to be constructed, this is the low value. If a BSON timestamp value is to be constructed, this is the timestamp.
Exceptions
bsoncxx::exceptionif the specified type is missing its required arguments.
Warning
The BSON timestamp type is used internally by the MongoDB server - use by clients is discouraged.

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