88 using is_value = detail::is_alike<T, value>;
91 using to_bson_expr =
decltype(to_bson(std::declval<T const&>(), std::declval<value&>()));
94 struct has_to_bson : detail::conjunction<detail::negation<is_value<T>>, detail::is_detected<to_bson_expr, T>> {};
97 using from_bson_expr =
decltype(from_bson(std::declval<T&>(), std::declval<v1::document::view>()));
100 struct has_from_bson : detail::conjunction<detail::negation<is_value<T>>, detail::is_detected<from_bson_expr, T>> {
103 template <
typename T>
104 struct is_valid_deleter
105 : detail::disjunction<
108 std::is_same<T, deleter_type>,
112 std::is_convertible<T, deleter_type>,
113 std::is_nothrow_destructible<T>,
114 std::is_nothrow_move_constructible<T>>> {};
186 template <typename Deleter, detail::enable_if_t<is_valid_deleter<Deleter>::value>* =
nullptr>
187 value(std::uint8_t*
data, Deleter deleter) : _data{
data, std::move(deleter)} {}
200 template <typename Deleter, detail::enable_if_t<is_valid_deleter<Deleter>::value>* =
nullptr>
273 std::memcpy(_data.get(),
view.data(),
view.size());
284 template <typename T, detail::enable_if_t<has_to_bson<T>::value>* =
nullptr>
304 template <typename T, detail::enable_if_t<has_to_bson<T>::value>* =
nullptr>
317 template <typename T, detail::enable_if_t<has_from_bson<T>::value>* =
nullptr>
319 from_bson(v, this->
view());
332 detail::enable_if_t<detail::conjunction<std::is_default_constructible<T>, has_from_bson<T>>
::value>* =
nullptr>
343 return _data.get_deleter();
350 return std::move(_data);
357 *
this = std::move(v);
413 return this->
view()[key];
417 std::uint8_t
const*
data()
const {
437 explicit operator bool()
const {
438 return this->
view().operator bool();
448 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:44
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:375
void reset(value v)
Replace the underlying BSON bytes with v.
Definition value.hpp:356
value(unique_ptr_type ptr)
Initialize as owning ptr.
Definition value.hpp:235
const_iterator cend() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition value.hpp:392
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:247
void reset(v1::document::view v)
Replace the underlying BSON bytes with a copy of v.
Definition value.hpp:368
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:407
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:442
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:412
value & operator=(T const &v)
Equivalent to *this = value{v}.
Definition value.hpp:305
value(v1::document::view view)
Initialize with a copy of the BSON bytes referenced by view.
Definition value.hpp:262
void get(T &v) const
Equivalent to from_bson(v, this->view()).
Definition value.hpp:318
deleter_type const & get_deleter() const
Return the current deleter.
Definition value.hpp:342
bool empty() const
Return true when the BSON bytes represents an empty view:
Definition value.hpp:432
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:82
std::function< void(std::uint8_t *)> deleter_type
The type of the deleter used to free the underlying BSON bytes.
Definition value.hpp:62
const_iterator begin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition value.hpp:397
void( *)(std::uint8_t *) noop_deleter_type
The type of a pointer to noop_deleter.
Definition value.hpp:72
value(value &&other) noexcept=default
Move construction.
value & operator=(value const &other)
Copy assignment.
Definition value.hpp:160
value(T const &v)
Equivalent to to_bson(v, *this); after default-initialization.
Definition value.hpp:285
std::size_t length() const
Return the length of the BSON bytes being represented.
Definition value.hpp:427
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:67
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:224
const_iterator cbegin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition value.hpp:387
value(std::uint8_t *data, Deleter deleter)
Initialize as owning data which will be freed with deleter.
Definition value.hpp:187
~value()=default
Destroy this object.
const_iterator iterator
Equivalent to const_iterator.
Definition value.hpp:121
std::uint8_t const * data() const
Return a pointer to the BSON bytes being represented.
Definition value.hpp:417
value & operator=(v1::document::view view)
Equivalent to this->reset(view).
Definition value.hpp:292
unique_ptr_type release()
Release ownership of the underlying BSON bytes.
Definition value.hpp:349
value(value const &other)
Copy construction.
Definition value.hpp:152
T get() const
Equivalent to T value; this->get(value); return value;.
Definition value.hpp:333
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:447
std::size_t size() const
Return the length of the BSON bytes being represented.
Definition value.hpp:422
value()
Initialize as an empty document (or array).
Definition value.hpp:173
v1::document::view::const_iterator const_iterator
A const iterator over the elements of a view.
Definition value.hpp:118
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:201
const_iterator end() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition value.hpp:402
value(std::uint8_t *data)
Initialize as owning data which will be freed with default_deleter_type.
Definition value.hpp:212
A const iterator over the elements of a view.
Definition view.hpp:264
A non-owning, read-only BSON document.
Definition view.hpp:52
bool empty() const
Return true when the BSON bytes represents an empty view:
Definition view.hpp:132
std::size_t length() const
Return the length of the BSON bytes being represented.
Definition view.hpp:119
const_iterator begin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition view.hpp:367
const_iterator cend() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition view.hpp:363
const_iterator end() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition view.hpp:371
std::size_t size() const
Return the length of the BSON bytes being represented.
Definition view.hpp:253
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:82
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.