MongoDB C++ Driver 4.2.0
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.

(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

Constructor & Destructor Documentation

◆ view() [1/3]

Default constructs a view.

Postconditions:

◆ view() [2/3]

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
dataA pointer to valid BSON data.
lengthThe size of the BSON data in bytes.

Member Function Documentation

◆ begin()

Returns
A const_iterator to the first element of the document.

◆ cbegin()

Returns
A const_iterator to the first element of the document.

◆ cend()

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

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

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

◆ find()

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
keyThe 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
inlineexplicit

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

◆ 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