MongoDB C++ Driver  mongocxx-3.10.2
Classes | Public Member Functions | List of all members
bsoncxx::v_noabi::array::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 an array view. More...
 

Public Member Functions

const_iterator cbegin () const
 
const_iterator cend () const
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator find (std::uint32_t i) const
 Indexes into this BSON array. More...
 
element operator[] (std::uint32_t i) const
 Indexes into this BSON array. More...
 
 view ()
 Default constructs a view. More...
 
 view (const std::uint8_t *data, std::size_t length)
 Constructs a view from a buffer. More...
 
const std::uint8_t * data () const
 Access the raw bytes of the underlying array. More...
 
std::size_t length () const
 Gets the length of the underlying buffer. More...
 
bool empty () const
 Checks if the underlying buffer is empty, i.e. More...
 
 operator document::view () const
 Conversion operator unwrapping a document::view.
 
bool operator== (view, view)
 Compare two views for (in)-equality.
 
bool operator!= (view, view)
 Compare two views for (in)-equality.
 

Detailed Description

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

Constructor & Destructor Documentation

◆ view() [1/2]

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

Default constructs a view.

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

◆ view() [2/2]

bsoncxx::v_noabi::array::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 array.
lengthThe size of the buffer, in bytes.

Member Function Documentation

◆ begin()

const_iterator bsoncxx::v_noabi::array::view::begin ( ) const
Returns
A const_iterator to the first element of the array.

◆ cbegin()

const_iterator bsoncxx::v_noabi::array::view::cbegin ( ) const
Returns
A const_iterator to the first element of the array.

◆ cend()

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

◆ data()

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

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

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

it is equivalent to the trivial array '[]'.

Returns
true if the underlying document is empty.

◆ end()

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

◆ 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

Gets the length of the underlying buffer.

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

◆ operator[]()

element bsoncxx::v_noabi::array::view::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.

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

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