MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
bsoncxx::document::element Class Reference

#include <bsoncxx/v_noabi/bsoncxx/document/element.hpp>

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.

See also

Public Member Functions

 element ()=default
 Construct an invalid element.
 element (v1::element::view const &v)
 Construct with the bsoncxx::v1 equivalent.
v_noabi::types::bson_value::value get_owning_value () const
 Getter for a types::bson_value::value variant wrapper of the value portion of the element. The returned object will make a copy of the buffer from this object.
v_noabi::types::bson_value::view get_value () const
 Getter for a types::bson_value::view variant wrapper of the value portion of the element.
v1::stdx::string_view key () const
 Getter for the element's key.
std::uint32_t keylen () const
 Getter for the element's key length.
std::uint32_t length () const
 Getter 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.
 operator bool () const
 Conversion operator to bool which is true for valid elements and false for invalid elements.
 operator v1::element::view () const
 Convert to the bsoncxx::v1 equivalent.
v_noabi::array::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.
element operator[] (v1::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.
std::uint8_t const * raw () const
 Getter for the raw bson bytes the element points to.
v_noabi::type type () const
 Getter for the type of the element.
v_noabi::types::bson_value::value type_value () const
 Equivalent to get_owning_value() const.
v_noabi::types::bson_value::view type_view () const
 Equivalent to get_value() const.
v_noabi::types::b_minkey get_minkey () const
 Return the BSON type value of this element.
v_noabi::types::b_double get_double () const
 Return the BSON type value of this element.
v_noabi::types::b_string get_string () const
 Return the BSON type value of this element.
v_noabi::types::b_document get_document () const
 Return the BSON type value of this element.
v_noabi::types::b_array get_array () const
 Return the BSON type value of this element.
v_noabi::types::b_binary get_binary () const
 Return the BSON type value of this element.
v_noabi::types::b_undefined get_undefined () const
 Return the BSON type value of this element.
v_noabi::types::b_oid get_oid () const
 Return the BSON type value of this element.
v_noabi::types::b_bool get_bool () const
 Return the BSON type value of this element.
v_noabi::types::b_date get_date () const
 Return the BSON type value of this element.
v_noabi::types::b_null get_null () const
 Return the BSON type value of this element.
v_noabi::types::b_regex get_regex () const
 Return the BSON type value of this element.
v_noabi::types::b_dbpointer get_dbpointer () const
 Return the BSON type value of this element.
v_noabi::types::b_code get_code () const
 Return the BSON type value of this element.
v_noabi::types::b_symbol get_symbol () const
 Return the BSON type value of this element.
v_noabi::types::b_codewscope get_codewscope () const
 Return the BSON type value of this element.
v_noabi::types::b_int32 get_int32 () const
 Return the BSON type value of this element.
v_noabi::types::b_timestamp get_timestamp () const
 Return the BSON type value of this element.
v_noabi::types::b_int64 get_int64 () const
 Return the BSON type value of this element.
v_noabi::types::b_decimal128 get_decimal128 () const
 Return the BSON type value of this element.
v_noabi::types::b_maxkey get_maxkey () const
 Return the BSON type value of this element.

(Note that these are not member symbols.)

bool operator== (element const &lhs, v_noabi::types::bson_value::view const &rhs)
 Convenience methods to compare for equality against a bson_value.
bool operator== (v_noabi::types::bson_value::view const &lhs, element const &rhs)
 Convenience methods to compare for equality against a bson_value.
bool operator!= (element const &lhs, v_noabi::types::bson_value::view const &rhs)
 Convenience methods to compare for equality against a bson_value.
bool operator!= (v_noabi::types::bson_value::view const &lhs, element const &rhs)
 Convenience methods to compare for equality against a bson_value.

Constructor & Destructor Documentation

◆ element() [1/2]

Construct an invalid element.

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

◆ element() [2/2]

Construct with the bsoncxx::v1 equivalent.

Member Function Documentation

◆ get_array()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_binary()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_bool()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_code()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_codewscope()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_date()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_dbpointer()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_decimal128()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_document()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_double()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_int32()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_int64()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_maxkey()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_minkey()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_null()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_oid()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_owning_value()

Getter for a types::bson_value::value variant wrapper of the value portion of the element. The returned object will make a copy of the buffer from this object.

Deprecated
Use type_value() const instead (renamed).
Returns
an owning version of the element's value.

◆ get_regex()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_string()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_symbol()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_timestamp()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_undefined()

Return the BSON type value of this element.

Exceptions
bsoncxx::v_noabi::exceptionif this element is not the requested type.

◆ get_value()

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

Deprecated
Use type_view() const instead (renamed).
Returns
the element's value.

◆ key()

Getter for the element's key.

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

◆ keylen()

std::uint32_t bsoncxx::v_noabi::document::element::keylen ( ) const
inline

Getter for the element's key length.

Returns
the element's key length.

◆ length()

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

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

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

◆ offset()

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

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

Returns
the offset into the raw bson bytes.

◆ operator bool()

bsoncxx::v_noabi::document::element::operator bool ( ) const
inlineexplicit

Conversion operator to bool which is true for valid elements and false for invalid elements.

◆ operator v1::element::view()

bsoncxx::v_noabi::document::element::operator v1::element::view ( ) const
inlineexplicit

Convert to the bsoncxx::v1 equivalent.

◆ operator[]() [1/2]

v_noabi::array::element bsoncxx::v_noabi::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::v_noabi::document::element::operator[] ( v1::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()

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

Getter for the raw bson bytes the element points to.

Returns
a pointer to the raw bson bytes.

◆ type()

Getter for the type of the element.

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

◆ type_value()

◆ type_view()

◆ operator!=() [1/2]

bool operator!= ( element const & lhs,
v_noabi::types::bson_value::view const & rhs )
related

Convenience methods to compare for equality against a bson_value.

Compares equal if the element contains a matching bson_value. Otherwise, compares unequal.

◆ operator!=() [2/2]

bool operator!= ( v_noabi::types::bson_value::view const & lhs,
element const & rhs )
related

Convenience methods to compare for equality against a bson_value.

Compares equal if the element contains a matching bson_value. Otherwise, compares unequal.

◆ operator==() [1/2]

bool operator== ( element const & lhs,
v_noabi::types::bson_value::view const & rhs )
related

Convenience methods to compare for equality against a bson_value.

Compares equal if the element contains a matching bson_value. Otherwise, compares unequal.

◆ operator==() [2/2]

bool operator== ( v_noabi::types::bson_value::view const & lhs,
element const & rhs )
related

Convenience methods to compare for equality against a bson_value.

Compares equal if the element contains a matching bson_value. Otherwise, compares unequal.


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