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
  - bsoncxx::v_noabi::array::element

## 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.

## Related Symbols

(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]

bsoncxx::v_noabi::document::element::element | ( |  | ) |

default

Construct an invalid element.

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

## element() [2/2]

bsoncxx::v_noabi::document::element::element | ( | v1::element::view const & | v | ) |

inline

Construct with the bsoncxx::v1 equivalent.

## Member Function Documentation

## get_array()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_binary()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_bool()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_code()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_codewscope()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_date()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_dbpointer()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_decimal128()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_document()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_double()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_int32()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_int64()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_maxkey()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_minkey()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_null()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_oid()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_owning_value()

v_noabi::types::bson_value::value bsoncxx::v_noabi::document::element::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.

Deprecated
  Use type_value() const instead (renamed).

Returns
  an owning version of the element's value.

## get_regex()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_string()

v_noabi::types::b_string bsoncxx::v_noabi::document::element::get_string | ( |  | ) | const

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_symbol()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_timestamp()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_undefined()

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

Return the BSON type value of this element.

Exceptions

  bsoncxx::v_noabi::exception | if this element is not the requested type.

## get_value()

v_noabi::types::bson_value::view bsoncxx::v_noabi::document::element::get_value | ( |  | ) | const

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

v1::stdx::string_view bsoncxx::v_noabi::document::element::key | ( |  | ) | const

Getter for the element's key.

Returns
  the element's key.

Exceptions

  bsoncxx::v_noabi::exception | if 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

inline explicit

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

inline explicit

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

  i | The 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

  key | The 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()

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

Getter for the type of the element.

Returns
  the element's type.

Exceptions

  bsoncxx::v_noabi::exception | if this element is invalid.

## type_value()

v_noabi::types::bson_value::value bsoncxx::v_noabi::document::element::type_value | ( |  | ) | const

Equivalent to get_owning_value() const.

To support incremental migration to bsoncxx::v1::element::view::type_value() const.

## type_view()

v_noabi::types::bson_value::view bsoncxx::v_noabi::document::element::type_view | ( |  | ) | const

Equivalent to get_value() const.

To support incremental migration to bsoncxx::v1::element::view::type_view() const.

## Friends And Related Symbol Documentation

## 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:

- bsoncxx/v_noabi/bsoncxx/document/element.hpp