MongoDB C++ Driver mongocxx-3.1.1
Loading...
Searching...
No Matches
Public Member Functions | List of all members
bsoncxx::document::element Class Reference

A variant view type that accesses values in serialized BSON documents. More...

#include <element.hpp>

+ Inheritance diagram for bsoncxx::document::element:

Public Member Functions

 element ()
 Construct an invalid element.
 
 element (const std::uint8_t *raw, std::uint32_t length, std::uint32_t offset)
 Construct an element as an offset into a buffer of bson bytes.
 
 operator bool () const
 Conversion operator to bool which is true for valid elements.
 
const std::uint8_t * raw () const
 Getter for the raw bson bytes the element points to.
 
void raw (const std::uint8_t *raw)
 Setter for the raw bson bytes the element points to.
 
std::uint32_t length () const
 Getter for length of the raw bson bytes the element points to.
 
void length (std::uint32_t length)
 Setter for length of the raw bson bytes the element points to.
 
std::uint32_t offset () const
 Getter for the offset into the raw bson bytes the element points to.
 
void offset (std::uint32_t offset)
 Setter for the offset into the raw bson bytes the element points to.
 
bsoncxx::type type () const
 Getter for the type of the element.
 
stdx::string_view key () const
 Getter for the element's key.
 
types::b_double get_double () const
 Getter for elements of the b_double type.
 
types::b_utf8 get_utf8 () const
 Getter for elements of the b_utf8 type.
 
types::b_document get_document () const
 Getter for elements of the b_document type.
 
types::b_array get_array () const
 Getter for elements of the b_array type.
 
types::b_binary get_binary () const
 Getter for elements of the b_binary type.
 
types::b_undefined get_undefined () const
 Getter for elements of the b_undefined type.
 
types::b_oid get_oid () const
 Getter for elements of the b_oid type.
 
types::b_bool get_bool () const
 Getter for elements of the b_bool type.
 
types::b_date get_date () const
 Getter for elements of the b_date type.
 
types::b_null get_null () const
 Getter for elements of the b_null type.
 
types::b_regex get_regex () const
 Getter for elements of the b_regex type.
 
types::b_dbpointer get_dbpointer () const
 Getter for elements of the b_dbpointer type.
 
types::b_code get_code () const
 Getter for elements of the b_code type.
 
types::b_symbol get_symbol () const
 Getter for elements of the b_symbol type.
 
types::b_codewscope get_codewscope () const
 Getter for elements of the b_codewscope type.
 
types::b_int32 get_int32 () const
 Getter for elements of the b_int32 type.
 
types::b_timestamp get_timestamp () const
 Getter for elements of the b_timestamp type.
 
types::b_int64 get_int64 () const
 Getter for elements of the b_int64 type.
 
types::b_decimal128 get_decimal128 () const
 Getter for elements of the b_decimal128 type.
 
types::b_minkey get_minkey () const
 Getter for elements of the b_minkey type.
 
types::b_maxkey get_maxkey () const
 Getter for elements of the b_maxkey type.
 
types::value get_value () const
 Getter for a types::value variant wrapper of the value portion of the element.
 
element operator[] (stdx::string_view key) const
 If this element is a document, finds the first element of the document with the provided key.
 
array::element operator[] (std::uint32_t i) const
 If this element is an array, indexes into this BSON array.
 

Detailed Description

A variant view type that accesses values in serialized BSON documents.

Element functions as a variant type, where the kind of the element can be interrogated by calling type(), the key can be extracted by calling key() and a specific value can be extracted through get_X() accessors.

Constructor & Destructor Documentation

◆ element() [1/2]

bsoncxx::document::element::element ( )

Construct an invalid element.

This is useful when mapping the end iterator of a document or array view.

◆ element() [2/2]

bsoncxx::document::element::element ( const std::uint8_t *  raw,
std::uint32_t  length,
std::uint32_t  offset 
)
explicit

Construct an element as an offset into a buffer of bson bytes.

Parameters
rawA pointer to the raw bson bytes.
lengthThe size of the bson buffer.
offsetThe element's offset into the buffer.

Member Function Documentation

◆ get_array()

types::b_array bsoncxx::document::element::get_array ( ) const

Getter for elements of the b_array type.

Exceptions
bsoncxx::exceptionif this element is not a b_array.
Returns
the element's value.

◆ get_binary()

types::b_binary bsoncxx::document::element::get_binary ( ) const

Getter for elements of the b_binary type.

Exceptions
bsoncxx::exceptionif this element is not a b_binary.
Returns
the element's value.

◆ get_bool()

types::b_bool bsoncxx::document::element::get_bool ( ) const

Getter for elements of the b_bool type.

Exceptions
bsoncxx::exceptionif this element is not a b_bool.
Returns
the element's value.

◆ get_code()

types::b_code bsoncxx::document::element::get_code ( ) const

Getter for elements of the b_code type.

Exceptions
bsoncxx::exceptionif this element is not a b_code.
Returns
the element's value.

◆ get_codewscope()

types::b_codewscope bsoncxx::document::element::get_codewscope ( ) const

Getter for elements of the b_codewscope type.

Exceptions
bsoncxx::exceptionif this element is not a b_codewscope.
Returns
the element's value.

◆ get_date()

types::b_date bsoncxx::document::element::get_date ( ) const

Getter for elements of the b_date type.

Exceptions
bsoncxx::exceptionif this element is not a b_date.
Returns
the element's value.

◆ get_dbpointer()

types::b_dbpointer bsoncxx::document::element::get_dbpointer ( ) const

Getter for elements of the b_dbpointer type.

Exceptions
bsoncxx::exceptionif this element is not a b_dbpointer.
Returns
the element's value.

◆ get_decimal128()

types::b_decimal128 bsoncxx::document::element::get_decimal128 ( ) const

Getter for elements of the b_decimal128 type.

Exceptions
bsoncxx::exceptionif this element is not a b_decimal128.
Returns
the element's value.

◆ get_document()

types::b_document bsoncxx::document::element::get_document ( ) const

Getter for elements of the b_document type.

Exceptions
bsoncxx::exceptionif this element is not a b_document.
Returns
the element's value.

◆ get_double()

types::b_double bsoncxx::document::element::get_double ( ) const

Getter for elements of the b_double type.

Exceptions
bsoncxx::exceptionif this element is not a b_double.
Returns
the element's value.

◆ get_int32()

types::b_int32 bsoncxx::document::element::get_int32 ( ) const

Getter for elements of the b_int32 type.

Exceptions
bsoncxx::exceptionif this element is not a b_int32.
Returns
the element's value.

◆ get_int64()

types::b_int64 bsoncxx::document::element::get_int64 ( ) const

Getter for elements of the b_int64 type.

Exceptions
bsoncxx::exceptionif this element is not a b_int64.
Returns
the element's value.

◆ get_maxkey()

types::b_maxkey bsoncxx::document::element::get_maxkey ( ) const

Getter for elements of the b_maxkey type.

Exceptions
bsoncxx::exceptionif this element is not a b_maxkey.
Returns
the element's value.

◆ get_minkey()

types::b_minkey bsoncxx::document::element::get_minkey ( ) const

Getter for elements of the b_minkey type.

Exceptions
bsoncxx::exceptionif this element is not a b_minkey.
Returns
the element's value.

◆ get_null()

types::b_null bsoncxx::document::element::get_null ( ) const

Getter for elements of the b_null type.

Exceptions
bsoncxx::exceptionif this element is not a b_null.
Returns
the element's value.

◆ get_oid()

types::b_oid bsoncxx::document::element::get_oid ( ) const

Getter for elements of the b_oid type.

Exceptions
bsoncxx::exceptionif this element is not a b_oid.
Returns
the element's value.

◆ get_regex()

types::b_regex bsoncxx::document::element::get_regex ( ) const

Getter for elements of the b_regex type.

Exceptions
bsoncxx::exceptionif this element is not a b_regex.
Returns
the element's value.

◆ get_symbol()

types::b_symbol bsoncxx::document::element::get_symbol ( ) const

Getter for elements of the b_symbol type.

Exceptions
bsoncxx::exceptionif this element is not a b_symbol.
Returns
the element's value.

◆ get_timestamp()

types::b_timestamp bsoncxx::document::element::get_timestamp ( ) const

Getter for elements of the b_timestamp type.

Exceptions
bsoncxx::exceptionif this element is not a b_timestamp.
Returns
the element's value.

◆ get_undefined()

types::b_undefined bsoncxx::document::element::get_undefined ( ) const

Getter for elements of the b_undefined type.

Exceptions
bsoncxx::exceptionif this element is not a b_undefined.
Returns
the element's value.

◆ get_utf8()

types::b_utf8 bsoncxx::document::element::get_utf8 ( ) const

Getter for elements of the b_utf8 type.

Exceptions
bsoncxx::exceptionif this element is not a b_utf8.
Returns
the element's value.

◆ get_value()

types::value bsoncxx::document::element::get_value ( ) const

Getter for a types::value variant wrapper of the value portion of the element.

Returns
the element's value.

◆ key()

stdx::string_view bsoncxx::document::element::key ( ) const

Getter for the element's key.

Returns
the element's key.
Exceptions
bsoncxx::exceptionif this element is invalid.

◆ length() [1/2]

std::uint32_t bsoncxx::document::element::length ( ) const

Getter for length of the raw bson bytes the element points to.

Returns
a pointer to the length of the raw bson bytes.

◆ length() [2/2]

void bsoncxx::document::element::length ( std::uint32_t  length)

Setter for length of the raw bson bytes the element points to.

Parameters
lengthThe length of the bytes this element points to.

◆ offset() [1/2]

std::uint32_t bsoncxx::document::element::offset ( ) const

Getter for the offset into the raw bson bytes the element points to.

Returns
the offset into the raw bson bytes.

◆ offset() [2/2]

void bsoncxx::document::element::offset ( std::uint32_t  offset)

Setter for the offset into the raw bson bytes the element points to.

Parameters
offsetThe offset into the bytes this element points to.

◆ operator[]() [1/2]

array::element bsoncxx::document::element::operator[] ( std::uint32_t  i) const

If this element is an array, indexes into this BSON array.

If the index is out-of-bounds, an invalid array::element will be returned. As BSON represents arrays as documents, the runtime of operator[] is linear in the length of the array.

If this element is not an array, an invalid array::element will be returned.

Parameters
iThe index of the element.
Returns
The element if it exists, or an invalid element.

◆ operator[]() [2/2]

element bsoncxx::document::element::operator[] ( stdx::string_view  key) const

If this element is a document, finds the first element of the document with the provided key.

If there is no such element, an invalid document::element will be returned. The runtime of operator[] is linear in the length of the document.

If this element is not a document, an invalid document::element will be returned.

Parameters
keyThe key to search for.
Returns
The matching element, if found, or an invalid element.

◆ raw() [1/2]

const std::uint8_t * bsoncxx::document::element::raw ( ) const

Getter for the raw bson bytes the element points to.

Returns
a pointer to the raw bson bytes.

◆ raw() [2/2]

void bsoncxx::document::element::raw ( const std::uint8_t *  raw)

Setter for the raw bson bytes the element points to.

Parameters
rawThe bytes this element should point to.

◆ type()

bsoncxx::type bsoncxx::document::element::type ( ) const

Getter for the type of the element.

Returns
the element's type.
Exceptions
bsoncxx::exceptionif this element is invalid.

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