MongoDB C++ Driver mongocxx-3.10.1
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
bsoncxx::v_noabi::document::view Class Reference

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

#include <view.hpp>

Classes

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

Public Member Functions

 view ()
 Default constructs a view.
 
 view (const std::uint8_t *data, std::size_t length)
 Constructs a view from a buffer.
 
const_iterator cbegin () const
 
const_iterator cend () const
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator find (stdx::string_view key) const
 Finds the first element of the document with the provided key.
 
element operator[] (stdx::string_view key) const
 Finds the first element of the document with the provided key.
 
const std::uint8_t * data () const
 Access the raw bytes of the underlying document.
 
std::size_t length () const
 Gets the length of the underlying buffer.
 
bool empty () const
 Checks if the underlying document is empty, i.e.
 

Detailed Description

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

Constructor & Destructor Documentation

◆ view() [1/2]

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

Default constructs a view.

The resulting view will be initialized to point at an empty BSON document.

◆ view() [2/2]

bsoncxx::v_noabi::document::view::view ( const std::uint8_t *  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.

Parameters
dataA buffer containing a valid BSON document.
lengthThe size of the buffer, in bytes.

Member Function Documentation

◆ begin()

const_iterator bsoncxx::v_noabi::document::view::begin ( ) const
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()

const_iterator bsoncxx::v_noabi::document::view::cend ( ) const
Returns
A const_iterator to the past-the-end element of the document.

◆ data()

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

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

Checks if the underlying document is empty, i.e.

it is equivalent to the trivial document '{}'.

Returns
true if the underlying document is empty.

◆ end()

const_iterator bsoncxx::v_noabi::document::view::end ( ) const
Returns
A const_iterator to the past-the-end element of the document.

◆ find()

const_iterator bsoncxx::v_noabi::document::view::find ( 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
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

Gets the length of the underlying buffer.

Remarks
This is not the number of elements in the document. To compute the number of elements, use std::distance.
Returns
The length of the document, in bytes.

◆ operator[]()

element bsoncxx::v_noabi::document::view::operator[] ( 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.

Parameters
keyThe key to search for.
Returns
The matching element, if found, or the invalid element.

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( view  ,
view   
)
friend

Compare two document views for (in)-equality.

◆ operator==

bool operator== ( view  ,
view   
)
friend

Compare two document views for (in)-equality.


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