MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
bsoncxx::v_noabi::array::view Class Reference

#include <bsoncxx/v_noabi/bsoncxx/array/view.hpp>

Description

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

Classes

class  const_iterator
 A const iterator over the contents of an array view. More...

Public Types

using iterator = const_iterator
 Equivalent to const_iterator.

Public Member Functions

 view ()=default
 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::array::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 array.
bool empty () const
 Return true when this->length() == 5.
const_iterator end () const
const_iterator find (std::uint32_t i) const
 Indexes into this BSON array. If the index is out-of-bounds, a past-the-end iterator will be returned. As BSON represents arrays as documents, the runtime of find() is linear in the length of the array.
std::size_t length () const
 Gets the length of the underlying buffer in bytes.
 operator v1::array::view () const
 Convert to the bsoncxx::v1 equivalent.
 operator v_noabi::document::view () const
 Conversion operator unwrapping a document::view.
v_noabi::array::element operator[] (std::uint32_t i) const
 Indexes into this BSON array. If the index is out-of-bounds, the invalid array::element will be returned. As BSON represents arrays as documents, the runtime of operator[] is linear in the length of the array.
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 views for (in)-equality.
bool operator!= (view lhs, view rhs)
 Compare two views for (in)-equality.

Member Typedef Documentation

◆ iterator

Constructor & Destructor Documentation

◆ view() [1/3]

bsoncxx::v_noabi::array::view::view ( )
default

Default constructs a view.

Postconditions:

◆ view() [2/3]

bsoncxx::v_noabi::array::view::view ( v1::array::view const & v)
inline

Construct with the bsoncxx::v1 equivalent.

◆ view() [3/3]

bsoncxx::v_noabi::array::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()

view::const_iterator bsoncxx::v_noabi::array::view::begin ( ) const
inline

Returns
A const_iterator to the first element of the document.

◆ cbegin()

const_iterator bsoncxx::v_noabi::array::view::cbegin ( ) const

Returns
A const_iterator to the first element of the document.

◆ cend()

view::const_iterator bsoncxx::v_noabi::array::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::array::view::data ( ) const
inline

Access the raw bytes of the underlying array.

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

◆ empty()

bool bsoncxx::v_noabi::array::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::array::view::end ( ) const
inline

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

◆ find()

const_iterator bsoncxx::v_noabi::array::view::find ( std::uint32_t i) const

Indexes into this BSON array. If the index is out-of-bounds, a past-the-end iterator will be returned. As BSON represents arrays as documents, the runtime of find() is linear in the length of the array.

Parameters
iThe index of the element.
Returns
An iterator to the element if it exists, or the past-the-end iterator.

◆ length()

std::size_t bsoncxx::v_noabi::array::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::array::view()

bsoncxx::v_noabi::array::view::operator v1::array::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::view()

bsoncxx::v_noabi::array::view::operator v_noabi::document::view ( ) const
inline

Conversion operator unwrapping a document::view.

◆ operator[]()

v_noabi::array::element bsoncxx::v_noabi::array::view::operator[] ( std::uint32_t i) const
inline

Indexes into this BSON array. If the index is out-of-bounds, the invalid array::element will be returned. As BSON represents arrays as documents, the runtime of operator[] is linear in the length of the array.

Parameters
iThe index of the element.
Returns
The element if it exists, or the invalid element.

◆ size()

std::size_t bsoncxx::v_noabi::array::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 views for (in)-equality.

◆ operator==

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

Compare two views for (in)-equality.


The documentation for this class was generated from the following file:
  • bsoncxx/v_noabi/bsoncxx/array/view.hpp