90 using is_value = detail::is_alike<T, value>;
93 using to_bson_expr =
decltype(to_bson(std::declval<T const&>(), std::declval<value&>()));
96 struct has_to_bson : detail::conjunction<detail::negation<is_value<T>>, detail::is_detected<to_bson_expr, T>> {};
99 using from_bson_expr =
decltype(from_bson(std::declval<T&>(), std::declval<v1::document::view>()));
101 template <
typename T>
102 struct has_from_bson : detail::conjunction<detail::negation<is_value<T>>, detail::is_detected<from_bson_expr, T>> {
105 template <
typename T>
106 struct is_valid_deleter
107 : detail::disjunction<
110 std::is_same<T, deleter_type>,
114 std::is_convertible<T, deleter_type>,
115 std::is_nothrow_destructible<T>,
116 std::is_nothrow_move_constructible<T>>> {};
188 template <typename Deleter, detail::enable_if_t<is_valid_deleter<Deleter>::value>* =
nullptr>
189 value(std::uint8_t*
data, Deleter deleter) : _data{
data, std::move(deleter)} {}
202 template <typename Deleter, detail::enable_if_t<is_valid_deleter<Deleter>::value>* =
nullptr>
275 std::memcpy(_data.get(),
view.data(),
view.size());
286 template <typename T, detail::enable_if_t<has_to_bson<T>::value>* =
nullptr>
306 template <typename T, detail::enable_if_t<has_to_bson<T>::value>* =
nullptr>
319 template <typename T, detail::enable_if_t<has_from_bson<T>::value>* =
nullptr>
321 from_bson(v, this->
view());
334 detail::enable_if_t<detail::conjunction<std::is_default_constructible<T>, has_from_bson<T>>
::value>* =
nullptr>
345 return _data.get_deleter();
352 return std::move(_data);
359 *
this = std::move(v);
415 return this->
view()[key];
419 std::uint8_t
const*
data()
const {
439 explicit operator bool()
const {
440 return this->
view().operator bool();
450 return !(lhs == rhs);
Provides macros to control the set of symbols exported in the ABI.
#define BSONCXX_ABI_CDECL
Expands to __cdecl when built with MSVC on Windows.
Definition export.hpp:49
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition export.hpp:52
The bsoncxx v1 macro guard postlude header.
The bsoncxx v1 macro guard prelude header.
A BSON document.
Definition value.hpp:46
static void noop_deleter(std::uint8_t *)
The deleter used to avoid freeing preallocated storage representing an empty BSON document.
v1::document::view view() const
Return a view of the BSON bytes as a document.
Definition value.hpp:377
void reset(value v)
Replace the underlying BSON bytes with v.
Definition value.hpp:358
value(unique_ptr_type ptr)
Initialize as owning ptr.
Definition value.hpp:237
const_iterator cend() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition value.hpp:394
value(unique_ptr_type ptr, std::size_t length)
Equivalent to value(unique_ptr_type ptr), but validates the embedded length against length.
Definition value.hpp:249
void reset(v1::document::view v)
Replace the underlying BSON bytes with a copy of v.
Definition value.hpp:370
const_iterator find(v1::stdx::string_view key) const
Return a const iterator to the element within the represented BSON document whose key compares equal ...
Definition value.hpp:409
friend bool operator==(value const &lhs, value const &rhs)
Compare equal when the BSON bytes represented by lhs and rhs compare equal.
Definition value.hpp:444
v1::element::view operator[](v1::stdx::string_view key) const
Return the first element within the represented BSON document whose key compares equal to key.
Definition value.hpp:414
value & operator=(T const &v)
Equivalent to *this = value{v}.
Definition value.hpp:307
value(v1::document::view view)
Initialize with a copy of the BSON bytes referenced by view.
Definition value.hpp:264
void get(T &v) const
Equivalent to from_bson(v, this->view()).
Definition value.hpp:320
deleter_type const & get_deleter() const
Return the current deleter.
Definition value.hpp:344
bool empty() const
Return true when the BSON bytes represents an empty view:
Definition value.hpp:434
std::unique_ptr< std::uint8_t[], deleter_type > unique_ptr_type
The type of the unique pointer used to manage the underlying BSON bytes.
Definition value.hpp:84
std::function< void(std::uint8_t *)> deleter_type
The type of the deleter used to free the underlying BSON bytes.
Definition value.hpp:64
const_iterator begin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition value.hpp:399
void( *)(std::uint8_t *) noop_deleter_type
The type of a pointer to noop_deleter.
Definition value.hpp:74
value(value &&other) noexcept=default
Move construction.
value & operator=(value const &other)
Copy assignment.
Definition value.hpp:162
value(T const &v)
Equivalent to to_bson(v, *this); after default-initialization.
Definition value.hpp:287
std::size_t length() const
Return the length of the BSON bytes being represented.
Definition value.hpp:429
std::default_delete< std::uint8_t[]> default_deleter_type
The deleter used to free copied BSON bytes when a user-provided deleter is not specified.
Definition value.hpp:69
value & operator=(value &&other) noexcept=default
Move assignment.
value(std::uint8_t *data, std::size_t length)
Equivalent to value(std::uint8_t* data), but validates the embedded length against length.
Definition value.hpp:226
const_iterator cbegin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition value.hpp:389
value(std::uint8_t *data, Deleter deleter)
Initialize as owning data which will be freed with deleter.
Definition value.hpp:189
~value()=default
Destroy this object.
const_iterator iterator
Equivalent to const_iterator.
Definition value.hpp:123
std::uint8_t const * data() const
Return a pointer to the BSON bytes being represented.
Definition value.hpp:419
value & operator=(v1::document::view view)
Equivalent to this->reset(view).
Definition value.hpp:294
unique_ptr_type release()
Release ownership of the underlying BSON bytes.
Definition value.hpp:351
value(value const &other)
Copy construction.
Definition value.hpp:154
T get() const
Equivalent to T value; this->get(value); return value;.
Definition value.hpp:335
friend bool operator!=(value const &lhs, value const &rhs)
Compare equal when the BSON bytes represented by lhs and rhs compare equal.
Definition value.hpp:449
std::size_t size() const
Return the length of the BSON bytes being represented.
Definition value.hpp:424
value()
Initialize as an empty document (or array).
Definition value.hpp:175
v1::document::view::const_iterator const_iterator
A const iterator over the elements of a view.
Definition value.hpp:120
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 l...
Definition value.hpp:203
const_iterator end() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition value.hpp:404
value(std::uint8_t *data)
Initialize as owning data which will be freed with default_deleter_type.
Definition value.hpp:214
A const iterator over the elements of a view.
Definition view.hpp:274
A non-owning, read-only BSON document.
Definition view.hpp:54
bool empty() const
Return true when the BSON bytes represents an empty view:
Definition view.hpp:134
std::size_t length() const
Return the length of the BSON bytes being represented.
Definition view.hpp:121
const_iterator begin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition view.hpp:377
const_iterator cend() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition view.hpp:373
const_iterator end() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition view.hpp:381
std::size_t size() const
Return the length of the BSON bytes being represented.
Definition view.hpp:261
const_iterator find(v1::stdx::string_view key) const
Return a const iterator to the element within the represented BSON document whose key compares equal ...
const_iterator cbegin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
A non-owning, read-only BSON element.
Definition view.hpp:84
A polyfill for std::string_view.
Definition string_view.hpp:412
Declares entities representing a BSON document.
Declares entities whose ABI stability is guaranteed for documented symbols.
The top-level namespace within which all bsoncxx library entities are declared.
Declares bsoncxx::v1::document::value.
Provides bsoncxx::v1::document::view.
Provides bsoncxx::v1::element::view.
Provides std::string_view-related polyfills for library API usage.