Loading...
Searching...
No Matches
bsoncxx::document::view Class Reference

`#include <bsoncxx/v_noabi/bsoncxx/document/view.hpp>`

## Description

A read-only, non-owning view of a BSON document.

## Classes

class | const_iterator
| A const iterator over the contents of a document view. More...

## Public Types

using | iterator = const_iterator
| Equivalent to const_iterator.

## Public Member Functions

| view ()
| Default constructs a view.
| view (std::uint8_t const *data, std::size_t length)
| Constructs a view from a buffer. The caller is responsible for ensuring that the lifetime of the resulting view is a subset of the buffer's.
| view (v1::document::view const &v)
| Construct with the bsoncxx::v1 equivalent.
const_iterator | begin () const
const_iterator | cbegin () const
const_iterator | cend () const
std::uint8_t const * | data () const
| Access the raw bytes of the underlying document.
bool | empty () const
| Return true when this->length() == 5.
const_iterator | end () const
const_iterator | find (v1::stdx::string_view key) const
| Finds the first element of the document with the provided key. If there is no such element, the past-the-end iterator will be returned. The runtime of find() is linear in the length of the document. This method only searches the top-level document, and will not recurse to any subdocuments.
std::size_t | length () const
| Gets the length of the underlying buffer in bytes.
| operator v1::document::view () const
| Convert to the bsoncxx::v1 equivalent.
v_noabi::document::element | operator[] (v1::stdx::string_view key) const
| Finds the first element of the document with the provided key. If there is no such element, the invalid document::element will be returned. The runtime of operator[] is linear in the length of the document.
std::size_t | size () const
| Gets the length of the underlying buffer in bytes.

## Related Symbols

(Note that these are not member symbols.)
bool | operator== (view lhs, view rhs)
| Compare two document views for (in)-equality.
bool | operator!= (view lhs, view rhs)
| Compare two document views for (in)-equality.

## Member Typedef Documentation

## iterator

using bsoncxx::v_noabi::document::view::iterator = const_iterator

Equivalent to const_iterator.

## Constructor & Destructor Documentation

## view() [1/3]

bsoncxx::v_noabi::document::view::view | ( |  | ) |

inline

Default constructs a view.

Postconditions:
  - this->data() != nullptr
  - this->size() == 5
  - this->empty() == true

## view() [2/3]

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

inline

Construct with the bsoncxx::v1 equivalent.

## view() [3/3]

bsoncxx::v_noabi::document::view::view | ( | std::uint8_t const * | data,
|  | std::size_t | length )

inline

Constructs a view from a buffer. The caller is responsible for ensuring that the lifetime of the resulting view is a subset of the buffer's.

Warning
  For backward compatibility, length is NOT validated. When length is inconsistent with the embedded length as indicated by the BSON bytes, the BSON bytes may be parsed as "invalid" despite the BSON bytes themselves being valid.

Parameters

  data | A pointer to valid BSON data.
  length | The size of the BSON data in bytes.

## Member Function Documentation

## begin()

view::const_iterator bsoncxx::v_noabi::document::view::begin | ( |  | ) | const

inline

Returns
  A const_iterator to the first element of the document.

## cbegin()

const_iterator bsoncxx::v_noabi::document::view::cbegin | ( |  | ) | const

Returns
  A const_iterator to the first element of the document.

## cend()

view::const_iterator bsoncxx::v_noabi::document::view::cend | ( |  | ) | const

inline

Returns
  A const_iterator to the past-the-end element of the document.

## data()

std::uint8_t const * bsoncxx::v_noabi::document::view::data | ( |  | ) | const

inline

Access the raw bytes of the underlying document.

Returns
  A (non-owning) pointer to the view's buffer.

## empty()

bool bsoncxx::v_noabi::document::view::empty | ( |  | ) | const

inline

Return true when this->length() == 5.

Warning
  For backward compatibility, this function does NOT check if the underlying BSON bytes represent a valid empty document.

## end()

view::const_iterator bsoncxx::v_noabi::document::view::end | ( |  | ) | const

inline

Returns
  A const_iterator to the past-the-end element of the document.

## find()

const_iterator bsoncxx::v_noabi::document::view::find | ( | v1::stdx::string_view | key | ) | const

Finds the first element of the document with the provided key. If there is no such element, the past-the-end iterator will be returned. The runtime of find() is linear in the length of the document. This method only searches the top-level document, and will not recurse to any subdocuments.

Remarks
  In BSON, keys are not required to be unique. If there are multiple elements with a matching key in the document, the first matching element from the start will be returned.

Parameters

  key | The key to search for.

Returns
  An iterator to the matching element, if found, or the past-the-end iterator.

## length()

std::size_t bsoncxx::v_noabi::document::view::length | ( |  | ) | const

inline

Gets the length of the underlying buffer in bytes.

Remarks
  This is not the number of BSON elements. To compute the number of elements, use std::distance.

Returns
  The length of the document, in bytes.

## operator v1::document::view()

bsoncxx::v_noabi::document::view::operator v1::document::view | ( |  | ) | const

inline explicit

Convert to the bsoncxx::v1 equivalent.

Preconditions:
  - If this->data() is not null, the size of the storage region pointed to by data must be greater than or equal to 5.
  - The "total number of bytes comprising the document" as indicated by the BSON bytes pointed-to by this->data() must be less than or equal to the size of the storage region pointed to by data.

Note
  this->size() is ignored.

## operator[]()

v_noabi::document::element bsoncxx::v_noabi::document::view::operator[] | ( | v1::stdx::string_view | key | ) | const

inline

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

Parameters

  key | The key to search for.

Returns
  The matching element, if found, or the invalid element.

## size()

std::size_t bsoncxx::v_noabi::document::view::size | ( |  | ) | const

inline

Gets the length of the underlying buffer in bytes.

Remarks
  This is not the number of BSON elements. To compute the number of elements, use std::distance.

Returns
  The length of the document, in bytes.

## Friends And Related Symbol Documentation

## operator!=

bool operator!= | ( | view | lhs,
|  | view | rhs )

friend

Compare two document views for (in)-equality.

## operator==

bool operator== | ( | view | lhs,
|  | view | rhs )

friend

Compare two document views for (in)-equality.

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

- bsoncxx/v_noabi/bsoncxx/document/view.hpp