#include <bsoncxx/v1/element/view.hpp>
A non-owning, read-only BSON element.
An "invalid" element, as indicated by operator bool() const, does not represent a BSON element and does not have an underlying key or value. Attempting to query the key or value of an invalid element will throw an exception. However, subscripting will not throw an exception when the requested field does not exist; instead it will return an invalid element to facilitate chaining.
Do not chain subscripts (e.g. doc["a"]["b"]) or immediately query element properties (e.g. doc["x"].key()) if you need to identify which field may be missing.
The BSON bytes being represented is only validated as minimally required to satisfy a requested operation. When an operation is not satisfiable due to invalid data, the operation will throw an bsoncxx::v1::exception with bsoncxx::v1::document::view::errc::invalid_data.
Public Types | |
| enum class | errc |
| Errors codes which may be returned by bsoncxx::v1::element::view. More... | |
Public Member Functions | |
| view () | |
| Initialize as an invalid element without any associated BSON bytes. | |
| view (view const &other) noexcept | |
| Copy (or move) construction. | |
| ~view () | |
| Destroy this object. | |
| v1::stdx::string_view | key () const |
| Return the key. | |
| std::uint32_t | keylen () const |
| Return the "keylen" component of the underlying BSON bytes. | |
| std::uint32_t | length () const |
| Return the "length" component of the underlying BSON bytes. | |
| std::uint32_t | offset () const |
| Return the "offset" component of the underlying BSON bytes. | |
| operator bool () const | |
| Return true when this is a valid element. | |
| view & | operator= (view const &other) noexcept |
| Copy (or move) assignment. | |
| v1::element::view | operator[] (std::uint32_t idx) const |
| Return the first element within the represented BSON array whose key compares equal to i. | |
| v1::element::view | operator[] (v1::stdx::string_view key) const |
| Return the first element within the represented BSON document whose key compares equal to key. | |
| std::uint8_t const * | raw () const |
| Return the "raw" component of the underlying BSON bytes. | |
| v1::types::id | type_id () const |
| Return the type. | |
| v1::types::value | type_value () const |
| Return a deep copy of the underlying BSON type value. | |
| v1::types::view | type_view () const |
| Return a view of the underlying BSON type value. | |
| v1::types::b_minkey | get_minkey () const |
| Return the underlying BSON type value. | |
| v1::types::b_double | get_double () const |
| Return the underlying BSON type value. | |
| v1::types::b_string | get_string () const |
| Return the underlying BSON type value. | |
| v1::types::b_document | get_document () const |
| Return the underlying BSON type value. | |
| v1::types::b_array | get_array () const |
| Return the underlying BSON type value. | |
| v1::types::b_binary | get_binary () const |
| Return the underlying BSON type value. | |
| v1::types::b_undefined | get_undefined () const |
| Return the underlying BSON type value. | |
| v1::types::b_oid | get_oid () const |
| Return the underlying BSON type value. | |
| v1::types::b_bool | get_bool () const |
| Return the underlying BSON type value. | |
| v1::types::b_date | get_date () const |
| Return the underlying BSON type value. | |
| v1::types::b_null | get_null () const |
| Return the underlying BSON type value. | |
| v1::types::b_regex | get_regex () const |
| Return the underlying BSON type value. | |
| v1::types::b_dbpointer | get_dbpointer () const |
| Return the underlying BSON type value. | |
| v1::types::b_code | get_code () const |
| Return the underlying BSON type value. | |
| v1::types::b_symbol | get_symbol () const |
| Return the underlying BSON type value. | |
| v1::types::b_codewscope | get_codewscope () const |
| Return the underlying BSON type value. | |
| v1::types::b_int32 | get_int32 () const |
| Return the underlying BSON type value. | |
| v1::types::b_timestamp | get_timestamp () const |
| Return the underlying BSON type value. | |
| v1::types::b_int64 | get_int64 () const |
| Return the underlying BSON type value. | |
| v1::types::b_decimal128 | get_decimal128 () const |
| Return the underlying BSON type value. | |
| v1::types::b_maxkey | get_maxkey () const |
| Return the underlying BSON type value. | |
Static Public Member Functions | |
| static std::error_category const & | error_category () |
| The error category for bsoncxx::v1::element::view::errc. | |
Friends | |
| std::error_code | make_error_code (errc v) |
| Support implicit conversion to std::error_code. | |
|
strong |
Errors codes which may be returned by bsoncxx::v1::element::view.
| Enumerator | |
|---|---|
| zero | Zero. |
| invalid_view | View is invalid. |
| invalid_data | Data is invalid. |
| bsoncxx::v1::element::view::~view | ( | ) |
Destroy this object.
|
noexcept |
Copy (or move) construction.
| bsoncxx::v1::element::view::view | ( | ) |
Initialize as an invalid element without any associated BSON bytes.
|
static |
The error category for bsoncxx::v1::element::view::errc.
| v1::types::b_array bsoncxx::v1::element::view::get_array | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_binary bsoncxx::v1::element::view::get_binary | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_bool bsoncxx::v1::element::view::get_bool | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_code bsoncxx::v1::element::view::get_code | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_codewscope bsoncxx::v1::element::view::get_codewscope | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_date bsoncxx::v1::element::view::get_date | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_dbpointer bsoncxx::v1::element::view::get_dbpointer | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_decimal128 bsoncxx::v1::element::view::get_decimal128 | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_document bsoncxx::v1::element::view::get_document | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_double bsoncxx::v1::element::view::get_double | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_int32 bsoncxx::v1::element::view::get_int32 | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_int64 bsoncxx::v1::element::view::get_int64 | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_maxkey bsoncxx::v1::element::view::get_maxkey | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_minkey bsoncxx::v1::element::view::get_minkey | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_null bsoncxx::v1::element::view::get_null | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_oid bsoncxx::v1::element::view::get_oid | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_regex bsoncxx::v1::element::view::get_regex | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_string bsoncxx::v1::element::view::get_string | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_symbol bsoncxx::v1::element::view::get_symbol | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_timestamp bsoncxx::v1::element::view::get_timestamp | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::types::b_undefined bsoncxx::v1::element::view::get_undefined | ( | ) | const |
Return the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| bsoncxx::v1::exception | with bsoncxx::v1::types::view::errc::type_mismatch if the BSON type value does not match the requested type. |
| v1::stdx::string_view bsoncxx::v1::element::view::key | ( | ) | const |
Return the key.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| std::uint32_t bsoncxx::v1::element::view::keylen | ( | ) | const |
Return the "keylen" component of the underlying BSON bytes.
The value is unspecified when this element is invalid.
| std::uint32_t bsoncxx::v1::element::view::length | ( | ) | const |
Return the "length" component of the underlying BSON bytes.
The value is unspecified when this element is invalid.
| std::uint32_t bsoncxx::v1::element::view::offset | ( | ) | const |
Return the "offset" component of the underlying BSON bytes.
The value is unspecified when this element is invalid.
|
explicit |
Return true when this is a valid element.
Copy (or move) assignment.
| v1::element::view bsoncxx::v1::element::view::operator[] | ( | std::uint32_t | idx | ) | const |
Return the first element within the represented BSON array whose key compares equal to i.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_data if this operation failed due to invalid BSON bytes. |
| v1::element::view bsoncxx::v1::element::view::operator[] | ( | v1::stdx::string_view | key | ) | const |
Return the first element within the represented BSON document whose key compares equal to key.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_data if this operation failed due to invalid BSON bytes. |
| std::uint8_t const * bsoncxx::v1::element::view::raw | ( | ) | const |
Return the "raw" component of the underlying BSON bytes.
The value is unspecified when this element is invalid.
| v1::types::id bsoncxx::v1::element::view::type_id | ( | ) | const |
Return the type.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| v1::types::value bsoncxx::v1::element::view::type_value | ( | ) | const |
Return a deep copy of the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
| v1::types::view bsoncxx::v1::element::view::type_view | ( | ) | const |
Return a view of the underlying BSON type value.
| bsoncxx::v1::exception | with bsoncxx::v1::element::view::errc::invalid_view if this element is invalid. |
|
friend |
Support implicit conversion to std::error_code.