MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
bsoncxx::v1::array::value Class Reference

#include <bsoncxx/v1/array/value.hpp>

Description

A BSON array.

Attention
This feature is experimental! It is not ready for use!

Public Types

using const_iterator = v1::document::view::const_iterator
 A const iterator over the elements of a view.
using default_deleter_type = v1::document::value::default_deleter_type
 The deleter used to free copied BSON bytes when a user-provided deleter is not specified.
using deleter_type = v1::document::value::deleter_type
 The type of the deleter used to free the underlying BSON bytes.
using iterator = const_iterator
 Equivalent to const_iterator.
using unique_ptr_type = v1::document::value::unique_ptr_type
 The type of the unique pointer used to manage the underlying BSON bytes.

Public Member Functions

 value ()=default
 Initialize as an empty document (or array).
 value (std::uint8_t *data)
 Initialize as owning data which will be freed with default_deleter_type.
template<typename Deleter, detail::enable_if_t< is_valid_deleter< Deleter >::value > * = nullptr>
 value (std::uint8_t *data, Deleter deleter)
 Initialize as owning data which will be freed with deleter.
 value (std::uint8_t *data, std::size_t length)
 Equivalent to value(std::uint8_t* data), but validates the embedded length against length.
template<typename Deleter, detail::enable_if_t< is_valid_deleter< Deleter >::value > * = nullptr>
 value (std::uint8_t *data, std::size_t length, Deleter deleter)
 Equivalent to value(std::uint8_t* data, Deleter deleter), but validates the embedded length against length.
 value (unique_ptr_type ptr)
 Initialize as owning ptr.
 value (unique_ptr_type ptr, std::size_t length)
 Equivalent to value(unique_ptr_type ptr), but validates the embedded length against length.
 value (v1::array::view view)
 Initialize with a copy of the BSON bytes referenced by view.
 value (value &&other) noexcept=default
 Move construction. noexcept
 value (value const &other)
 Copy construction.
 ~value ()=default
 Destroy this object.
v1::array::view::const_iterator begin () const
 Return a const iterator to the beginning of the range of BSON elements within this view.
v1::array::view::const_iterator cbegin () const
 Return a const iterator to the beginning of the range of BSON elements within this view.
v1::array::view::const_iterator cend () const
 Return a const iterator to the end of the range of BSON elements within this view.
std::uint8_t const * data () const
 Return a pointer to the BSON bytes being represented.
bool empty () const
 Return true when the BSON bytes represents an empty view:
v1::array::view::const_iterator end () const
 Return a const iterator to the end of the range of BSON elements within this view.
v1::array::view::const_iterator find (std::uint32_t i) const
 Return a const iterator to the element within the represented BSON array at index i via key string comparison.
deleter_type const & get_deleter () const
 Return the current deleter.
std::size_t length () const
 Return the length of the BSON bytes being represented.
 operator bool () const
 Return true when this view is valid.
 operator v1::array::view () const
 Implicitly convert to this->view().
valueoperator= (v1::array::view view)
 Equivalent to this->reset(view).
valueoperator= (value &&other) noexcept=default
 Move assignment. noexcept
valueoperator= (value const &other)
 Copy assignment.
v1::element::view operator[] (std::uint32_t i) const
 Return the first element within the represented BSON array whose key compares equal to i.
unique_ptr_type release ()
 Release ownership of the underlying BSON bytes.
void reset (v1::array::view v)
 Replace the underlying BSON bytes with a copy of v.
void reset (value v)
 Replace the underlying BSON bytes with v.
std::size_t size () const
 Return the length of the BSON bytes being represented.
v1::array::view view () const
 Return a view of the BSON bytes as an array.

Friends

bool operator!= (value const &lhs, value const &rhs)
 Compare equal when the BSON bytes represented by lhs and rhs compare equal.
bool operator== (value const &lhs, value const &rhs)
 Compare equal when the BSON bytes represented by lhs and rhs compare equal.

Member Typedef Documentation

◆ const_iterator

A const iterator over the elements of a view.

Note
This iterator almost satisfies Cpp17ForwardIterator, but std::iterator_traits<T>::reference is defined as value_type, similar to std::vector<bool>::iterator and std::istreambuf_iterator<T>. Therefore, this iterator only fully satisfies Cpp17InputIterator.
Attention
This feature is experimental! It is not ready for use!

◆ default_deleter_type

The deleter used to free copied BSON bytes when a user-provided deleter is not specified.

◆ deleter_type

The type of the deleter used to free the underlying BSON bytes.

A deleter D that is wrapped by deleter_type must:

  • be std::is_nothrow_destructible<D>,
  • be std::is_nothrow_move_constructible<D>,
  • not throw an exception when invoked with a std::uint8_t*.

These requirements are the same as those for a std::unique_ptr<T, D> deleter D, but do not include nothrow move assignability due to being wrapped by deleter_type.

Important
Despite being a std::function<T>, deleter_type is assumed to behave like a C++23 std::move_only_function<T>. That is, it is assumed to be nothrow destructible, nothrow move constructible, and nothrow move assignable.

◆ iterator

◆ unique_ptr_type

The type of the unique pointer used to manage the underlying BSON bytes.

Constructor & Destructor Documentation

◆ ~value()

bsoncxx::v1::array::value::~value ( )
default

Destroy this object.

◆ value() [1/10]

bsoncxx::v1::array::value::value ( value && other)
defaultnoexcept

Move construction. noexcept

Postconditions:

◆ value() [2/10]

bsoncxx::v1::array::value::value ( value const & other)
inline

Copy construction.

The copied value is allocated using operator new[] and the deleter is set to default_deleter_type.

◆ value() [3/10]

bsoncxx::v1::array::value::value ( )
default

Initialize as an empty document (or array).

The value is equivalent to a default-initialized bsoncxx::v1::document::view and the deleter is set to bsoncxx::v1::document::value::noop_deleter.

Warning
Modifying the pointed-to data after default construction is undefined behavior.

◆ value() [4/10]

template<typename Deleter, detail::enable_if_t< is_valid_deleter< Deleter >::value > * = nullptr>
bsoncxx::v1::array::value::value ( std::uint8_t * data,
Deleter deleter )
inline

Initialize as owning data which will be freed with deleter.

Constraints:
  • Deleter must satisfy the requirements described by deleter_type.
Preconditions:
  • If data is not null, the size of the storage region pointed to by data must be greater than or equal to 5.
  • The embedded length must be less than or equal to the size of the storage region pointed to by data.
  • deleter must be capable of freeing the storage region pointed to by data.

◆ value() [5/10]

template<typename Deleter, detail::enable_if_t< is_valid_deleter< Deleter >::value > * = nullptr>
bsoncxx::v1::array::value::value ( std::uint8_t * data,
std::size_t length,
Deleter deleter )
inline

Equivalent to value(std::uint8_t* data, Deleter deleter), but validates the embedded length against length.

Preconditions:
  • If data is not null, the size of the storage region pointed to by data must be greater than or equal to length.
Exceptions
bsoncxx::v1::exceptionwith bsoncxx::v1::document::view::errc::invalid_length if `length` is less than 5 or less than this->size().

◆ value() [6/10]

bsoncxx::v1::array::value::value ( std::uint8_t * data)
inlineexplicit

Initialize as owning data which will be freed with default_deleter_type.

Preconditions:
  • If data is not null, the size of the storage region pointed to by data must be greater than or equal to 5.
  • The embedded length must be less than or equal to the size of the storage region pointed to by data.

◆ value() [7/10]

bsoncxx::v1::array::value::value ( std::uint8_t * data,
std::size_t length )
inline

Equivalent to value(std::uint8_t* data), but validates the embedded length against length.

Preconditions:
  • If data is not null, the size of the storage region pointed to by data must be greater than or equal to length.
Exceptions
bsoncxx::v1::exceptionwith bsoncxx::v1::document::view::errc::invalid_length if `length` is less than 5 or less than this->size().

◆ value() [8/10]

bsoncxx::v1::array::value::value ( unique_ptr_type ptr)
inlineexplicit

Initialize as owning ptr.

Preconditions:
  • If data is not null, the size of the storage region pointed to by data must be greater than or equal to 5.
  • The embedded length must be less than or equal to the size of the storage region pointed to by data.

◆ value() [9/10]

bsoncxx::v1::array::value::value ( unique_ptr_type ptr,
std::size_t length )
inline

Equivalent to value(unique_ptr_type ptr), but validates the embedded length against length.

Preconditions:
  • If ptr is not null, the size of the storage region pointed to by data must be greater than or equal to length.
Exceptions
bsoncxx::v1::exceptionwith bsoncxx::v1::document::view::errc::invalid_length if `length` is less than 5 or less than this->size().

◆ value() [10/10]

bsoncxx::v1::array::value::value ( v1::array::view view)
inlineexplicit

Initialize with a copy of the BSON bytes referenced by view.

If view is equivalent to a default-initialized bsoncxx::v1::document::view, this value is equivalent to value().

If view is invalid, this value is equivalent to value{nullptr}.

Otherwise, the copied value is allocated using operator new[] and the deleter is set to default_deleter_type.

Member Function Documentation

◆ begin()

v1::array::view::const_iterator bsoncxx::v1::array::value::begin ( ) const
inline

Return a const iterator to the beginning of the range of BSON elements within this view.

If this view is invalid, returns an end iterator.

Exceptions
bsoncxx::v1::exceptionwith bsoncxx::v1::document::view::errc::invalid_data if this operation failed due to invalid BSON bytes.

◆ cbegin()

v1::array::view::const_iterator bsoncxx::v1::array::value::cbegin ( ) const
inline

Return a const iterator to the beginning of the range of BSON elements within this view.

If this view is invalid, returns an end iterator.

Exceptions
bsoncxx::v1::exceptionwith bsoncxx::v1::document::view::errc::invalid_data if this operation failed due to invalid BSON bytes.

◆ cend()

v1::array::view::const_iterator bsoncxx::v1::array::value::cend ( ) const
inline

Return a const iterator to the end of the range of BSON elements within this view.

◆ data()

std::uint8_t const * bsoncxx::v1::array::value::data ( ) const
inline

Return a pointer to the BSON bytes being represented.

◆ empty()

bool bsoncxx::v1::array::value::empty ( ) const
inline

Return true when the BSON bytes represents an empty view:

  • data() is not null,
  • size() is equal to 5, and
  • the pointed-to BSON bytes are terminated with a null byte.
Note
This does not return true when this view is invalid.

◆ end()

v1::array::view::const_iterator bsoncxx::v1::array::value::end ( ) const
inline

Return a const iterator to the end of the range of BSON elements within this view.

◆ find()

v1::array::view::const_iterator bsoncxx::v1::array::value::find ( std::uint32_t i) const
inline

Return a const iterator to the element within the represented BSON array at index i via key string comparison.

If this view is invalid or the requested field is not found, returns an end iterator.

Complexity
Linear.
Exceptions
bsoncxx::v1::exceptionwith bsoncxx::v1::document::view::errc::invalid_data if this operation failed due to invalid BSON bytes.

◆ get_deleter()

deleter_type const & bsoncxx::v1::array::value::get_deleter ( ) const
inline

Return the current deleter.

◆ length()

std::size_t bsoncxx::v1::array::value::length ( ) const
inline

Return the length of the BSON bytes being represented.

If this->data() is null, returns 0.

Note
This returns the embedded length as indicated by the pointed-to BSON bytes. The result is always within the range [0, INT32_MAX] when preconditions are satisfied.

◆ operator bool()

bsoncxx::v1::array::value::operator bool ( ) const
inlineexplicit

Return true when this view is valid.

Note
This does not validate the BSON bytes being represented.

◆ operator v1::array::view()

bsoncxx::v1::array::value::operator v1::array::view ( ) const
inline

Implicitly convert to this->view().

◆ operator=() [1/3]

value & bsoncxx::v1::array::value::operator= ( v1::array::view view)
inline

Equivalent to this->reset(view).

◆ operator=() [2/3]

value & bsoncxx::v1::array::value::operator= ( value && other)
defaultnoexcept

Move assignment. noexcept

Postconditions:

◆ operator=() [3/3]

value & bsoncxx::v1::array::value::operator= ( value const & other)
inline

Copy assignment.

The copied value is allocated using operator new[] and the deleter is set to default_deleter_type.

◆ operator[]()

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

Return the first element within the represented BSON array whose key compares equal to i.

Returns
An invalid element if this view is invalid or the requested field is not found.
Complexity
Linear.
Exceptions
bsoncxx::v1::exceptionwith bsoncxx::v1::document::view::errc::invalid_data if this operation failed due to invalid BSON bytes.

◆ release()

unique_ptr_type bsoncxx::v1::array::value::release ( )
inline

Release ownership of the underlying BSON bytes.

◆ reset() [1/2]

void bsoncxx::v1::array::value::reset ( v1::array::view v)
inline

Replace the underlying BSON bytes with a copy of v.

If v is invalid, reset to a default-initialized value.

The copied value is allocated using operator new[] and the deleter is set to default_deleter_type.

◆ reset() [2/2]

void bsoncxx::v1::array::value::reset ( value v)
inline

Replace the underlying BSON bytes with v.

◆ size()

std::size_t bsoncxx::v1::array::value::size ( ) const
inline

Return the length of the BSON bytes being represented.

If this->data() is null, returns 0.

Note
This returns the embedded length as indicated by the pointed-to BSON bytes. The result is always within the range [0, INT32_MAX] when preconditions are satisfied.

◆ view()

v1::array::view bsoncxx::v1::array::value::view ( ) const
inline

Return a view of the BSON bytes as an array.

◆ operator!=

bool operator!= ( value const & lhs,
value const & rhs )
friend

Compare equal when the BSON bytes represented by lhs and rhs compare equal.

An invalid view only compares equal to another invalid view. The underlying BSON bytes (if any) is ignored for an invalid document.

◆ operator==

bool operator== ( value const & lhs,
value const & rhs )
friend

Compare equal when the BSON bytes represented by lhs and rhs compare equal.

An invalid view only compares equal to another invalid view. The underlying BSON bytes (if any) is ignored for an invalid document.


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