#include <bsoncxx/v1/document/view.hpp>
A non-owning, read-only BSON document.
An "invalid" view, as indicated by operator bool() const, does not satisfy the minimum requirements of a valid BSON document, which are that:
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.
Classes | |
| class | const_iterator |
| A const iterator over the elements of a view. More... | |
Public Types | |
| enum class | errc |
| Errors codes which may be returned by bsoncxx::v1::document::view. More... | |
| using | iterator = const_iterator |
| Equivalent to const_iterator. | |
Public Member Functions | |
| view () | |
| Initialize as an empty view. | |
| view (std::uint8_t const *data) | |
| Initialize with the given BSON bytes. | |
| view (std::uint8_t const *data, std::size_t length) | |
| Equivalent to view(std::uint8_t const* data), but validates the embedded length against length. | |
| const_iterator | begin () const |
| Return a const iterator to the beginning of the range of BSON elements within this view. | |
| const_iterator | cbegin () const |
| Return a const iterator to the beginning of the range of BSON elements within this view. | |
| const_iterator | cend () const |
| Return a const iterator to the end of the range of BSON elements within this view. | |
| std::uint8_t const * | data () const |
| Return a pointer to the BSON bytes being represented. | |
| bool | empty () const |
| Return true when the BSON bytes represents an empty view: | |
| const_iterator | end () const |
| Return a const iterator to the end of the range of BSON elements within this view. | |
| const_iterator | find (v1::stdx::string_view key) const |
| Return a const iterator to the element within the represented BSON document whose key compares equal to key. | |
| std::size_t | length () const |
| Return the length of the BSON bytes being represented. | |
| operator bool () const | |
| Return true when this view is valid. | |
| 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::size_t | size () const |
| Return the length of the BSON bytes being represented. | |
Static Public Member Functions | |
| static std::error_category const & | error_category () |
| The error category for bsoncxx::v1::document::view::errc. | |
Friends | |
| std::error_code | make_error_code (errc v) |
| Support implicit conversion to std::error_code. | |
| bool | operator== (view lhs, view rhs) |
| Compare equal when the BSON bytes represented by lhs and rhs compare equal. | |
| bool | operator!= (view lhs, view rhs) |
| Compare equal when the BSON bytes represented by lhs and rhs compare equal. | |
Equivalent to const_iterator.
|
strong |
Errors codes which may be returned by bsoncxx::v1::document::view.
| Enumerator | |
|---|---|
| zero | Zero. |
| invalid_length | Length is invalid. |
| invalid_data | Data is invalid. |
| bsoncxx::v1::document::view::view | ( | ) |
|
inlineexplicit |
| bsoncxx::v1::document::view::view | ( | std::uint8_t const * | data, |
| std::size_t | length ) |
Equivalent to view(std::uint8_t const* data), but validates the embedded length against length.
| bsoncxx::v1::exception | with bsoncxx::v1::document::view::errc::invalid_length if `length` is less than 5 or less than this->size(). |
|
inline |
Return a const iterator to the beginning of the range of BSON elements within this view.
If this view is invalid, returns an end iterator.
| bsoncxx::v1::exception | with bsoncxx::v1::document::view::errc::invalid_data if this operation failed due to invalid BSON bytes. |
| const_iterator bsoncxx::v1::document::view::cbegin | ( | ) | const |
Return a const iterator to the beginning of the range of BSON elements within this view.
If this view is invalid, returns an end iterator.
| bsoncxx::v1::exception | with bsoncxx::v1::document::view::errc::invalid_data if this operation failed due to invalid BSON bytes. |
|
inline |
Return a const iterator to the end of the range of BSON elements within this view.
|
inline |
Return a pointer to the BSON bytes being represented.
|
inline |
|
inline |
Return a const iterator to the end of the range of BSON elements within this view.
|
static |
The error category for bsoncxx::v1::document::view::errc.
| const_iterator bsoncxx::v1::document::view::find | ( | v1::stdx::string_view | key | ) | const |
Return a const iterator to the element within the represented BSON document whose key compares equal to key.
If this view is invalid or the requested field is not found, returns an end iterator.
| bsoncxx::v1::exception | with bsoncxx::v1::document::view::errc::invalid_data if this operation failed due to invalid BSON bytes. |
|
inline |
Return the length of the BSON bytes being represented.
If this->data() is null, returns 0.
|
inlineexplicit |
Return true when this view is valid.
|
inline |
Return the first element within the represented BSON document whose key compares equal to key.
| bsoncxx::v1::exception | with bsoncxx::v1::document::view::errc::invalid_data if this operation failed due to invalid BSON bytes. |
|
inline |
Return the length of the BSON bytes being represented.
If this->data() is null, returns 0.
|
friend |
Support implicit conversion to std::error_code.
Compare equal when the BSON bytes represented by lhs and rhs compare equal.
An invalid view only compares equal to another invalid view. The underlying BSON bytes (if any) is ignored for an invalid document.
Compare equal when the BSON bytes represented by lhs and rhs compare equal.
An invalid view only compares equal to another invalid view. The underlying BSON bytes (if any) is ignored for an invalid document.