Loading...
Searching...
No Matches
value.hpp
Go to the documentation of this file.
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <bsoncxx/v1/array/value-fwd.hpp> // IWYU pragma: export
//
#include <bsoncxx/v1/detail/prelude.hpp>
#include <bsoncxx/v1/array/view.hpp> // IWYU pragma: export
#include <bsoncxx/v1/detail/type_traits.hpp>
#include <bsoncxx/v1/document/value.hpp> // IWYU pragma: export
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include <utility>
namespace bsoncxx {
namespace v1 {
namespace array {
class value {
private:
v1::document::value _value;
template <typename T>
struct is_valid_deleter : std::is_constructible<v1::document::value, std::uint8_t*, T> {};
public:
using deleter_type = v1::document::value::deleter_type;
using default_deleter_type = v1::document::value::default_deleter_type;
using unique_ptr_type = v1::document::value::unique_ptr_type;
using const_iterator = v1::document::view::const_iterator;
using iterator = const_iterator;
~value() = default;
value(value&& other) noexcept = default;
value& operator=(value&& other) noexcept = default;
value(value const& other) : _value(other._value) {}
value& operator=(v1::array::view view) {
this->reset(view);
return *this;
}
value& operator=(value const& other) {
_value = other._value;
return *this;
}
value() = default;
template <typename Deleter, detail::enable_if_t<is_valid_deleter<Deleter>::value>* = nullptr>
value(std::uint8_t* data, Deleter deleter) : _value{data, std::move(deleter)} {}
template <typename Deleter, detail::enable_if_t<is_valid_deleter<Deleter>::value>* = nullptr>
value(std::uint8_t* data, std::size_t length, Deleter deleter) : _value{data, length, std::move(deleter)} {}
explicit value(std::uint8_t* data) : _value{data} {}
value(std::uint8_t* data, std::size_t length) : _value{data, length} {}
explicit value(unique_ptr_type ptr) : _value{std::move(ptr)} {}
value(unique_ptr_type ptr, std::size_t length) : _value{std::move(ptr), length} {}
explicit value(v1::array::view view) : _value{view} {}
deleter_type const& get_deleter() const {
return _value.get_deleter();
}
unique_ptr_type release() {
return _value.release();
}
void reset(value v) {
_value = std::move(v._value);
}
void reset(v1::array::view v) {
*this = value{v};
}
v1::array::view view() const {
return v1::array::view{_value.data()};
}
/* explicit(false) */ operator v1::array::view() const {
return this->view();
}
v1::array::view::const_iterator cbegin() const {
return this->view().cbegin();
}
v1::array::view::const_iterator cend() const {
return this->view().cend();
}
v1::array::view::const_iterator begin() const {
return this->view().begin();
}
v1::array::view::const_iterator end() const {
return this->view().end();
}
v1::array::view::const_iterator find(std::uint32_t i) const {
return this->view().find(i);
}
v1::element::view operator[](std::uint32_t i) const {
return this->view()[i];
}
std::uint8_t const* data() const {
return this->view().data();
}
std::size_t size() const {
return this->view().size();
}
std::size_t length() const {
return this->view().length();
}
bool empty() const {
return this->view().empty();
}
explicit operator bool() const {
return this->view().operator bool();
}
friend bool operator==(value const& lhs, value const& rhs) {
return lhs.view() == rhs.view();
}
friend bool operator!=(value const& lhs, value const& rhs) {
return !(lhs == rhs);
}
};
} // namespace array
} // namespace v1
} // namespace bsoncxx
#include <bsoncxx/v1/detail/postlude.hpp>
postlude.hpp
The bsoncxx v1 macro guard postlude header.
prelude.hpp
The bsoncxx v1 macro guard prelude header.
bsoncxx::v1::array::value::cend
v1::array::view::const_iterator cend() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition value.hpp:152
bsoncxx::v1::array::value::value
value(value const &other)
Copy construction.
Definition value.hpp:72
bsoncxx::v1::array::value::value
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:95
bsoncxx::v1::array::value::value
value(unique_ptr_type ptr)
Initialize as owning ptr.
Definition value.hpp:104
bsoncxx::v1::array::value::operator=
value & operator=(value const &other)
Copy assignment.
Definition value.hpp:81
bsoncxx::v1::array::value::get_deleter
deleter_type const & get_deleter() const
Return the current deleter.
Definition value.hpp:113
bsoncxx::v1::array::value::size
std::size_t size() const
Return the length of the BSON bytes being represented.
Definition value.hpp:182
bsoncxx::v1::array::value::const_iterator
v1::document::view::const_iterator const_iterator
A const iterator over the elements of a view.
Definition value.hpp:57
bsoncxx::v1::array::value::operator==
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:202
bsoncxx::v1::array::value::find
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 co...
Definition value.hpp:167
bsoncxx::v1::array::value::begin
v1::array::view::const_iterator begin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition value.hpp:157
bsoncxx::v1::array::value::view
v1::array::view view() const
Return a view of the BSON bytes as an array.
Definition value.hpp:135
bsoncxx::v1::array::value::cbegin
v1::array::view::const_iterator cbegin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition value.hpp:147
bsoncxx::v1::array::value::length
std::size_t length() const
Return the length of the BSON bytes being represented.
Definition value.hpp:187
bsoncxx::v1::array::value::data
std::uint8_t const * data() const
Return a pointer to the BSON bytes being represented.
Definition value.hpp:177
bsoncxx::v1::array::value::~value
~value()=default
Destroy this object.
bsoncxx::v1::array::value::value
value(std::uint8_t *data)
Initialize as owning data which will be freed with default_deleter_type.
Definition value.hpp:98
bsoncxx::v1::array::value::operator=
value & operator=(v1::array::view view)
Equivalent to this->reset(view).
Definition value.hpp:75
bsoncxx::v1::array::value::deleter_type
v1::document::value::deleter_type deleter_type
The type of the deleter used to free the underlying BSON bytes.
Definition value.hpp:48
bsoncxx::v1::array::value::reset
void reset(value v)
Replace the underlying BSON bytes with v.
Definition value.hpp:123
bsoncxx::v1::array::value::value
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:101
bsoncxx::v1::array::value::empty
bool empty() const
Return true when the BSON bytes represents an empty view:
Definition value.hpp:192
bsoncxx::v1::array::value::release
unique_ptr_type release()
Release ownership of the underlying BSON bytes.
Definition value.hpp:118
bsoncxx::v1::array::value::iterator
const_iterator iterator
Equivalent to const_iterator.
Definition value.hpp:60
bsoncxx::v1::array::value::value
value(std::uint8_t *data, Deleter deleter)
Initialize as owning data which will be freed with deleter.
Definition value.hpp:91
bsoncxx::v1::array::value::end
v1::array::view::const_iterator end() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition value.hpp:162
bsoncxx::v1::array::value::operator[]
v1::element::view operator[](std::uint32_t i) const
Return the first element within the represented BSON array whose key compares equal to i.
Definition value.hpp:172
bsoncxx::v1::array::value::value
value(v1::array::view view)
Initialize with a copy of the BSON bytes referenced by view.
Definition value.hpp:110
bsoncxx::v1::array::value::operator=
value & operator=(value &&other) noexcept=default
Move assignment. noexcept
bsoncxx::v1::array::value::operator!=
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:207
bsoncxx::v1::array::value::reset
void reset(v1::array::view v)
Replace the underlying BSON bytes with a copy of v.
Definition value.hpp:128
bsoncxx::v1::array::value::value
value()=default
Initialize as an empty document (or array).
bsoncxx::v1::array::value::value
value(value &&other) noexcept=default
Move construction. noexcept
bsoncxx::v1::array::value::default_deleter_type
v1::document::value::default_deleter_type default_deleter_type
The deleter used to free copied BSON bytes when a user-provided deleter is not specified.
Definition value.hpp:51
bsoncxx::v1::array::value::unique_ptr_type
v1::document::value::unique_ptr_type unique_ptr_type
The type of the unique pointer used to manage the underlying BSON bytes.
Definition value.hpp:54
bsoncxx::v1::array::value::value
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:107
bsoncxx::v1::array::view
A non-owning, read-only BSON array.
Definition view.hpp:47
bsoncxx::v1::array::view::data
std::uint8_t const * data() const
Return a pointer to the BSON bytes being represented.
Definition view.hpp:69
bsoncxx::v1::array::view::begin
const_iterator begin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition view.hpp:104
bsoncxx::v1::array::view::length
std::size_t length() const
Return the length of the BSON bytes being represented.
Definition view.hpp:79
bsoncxx::v1::array::view::cbegin
const_iterator cbegin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition view.hpp:94
bsoncxx::v1::array::view::empty
bool empty() const
Return true when the BSON bytes represents an empty view:
Definition view.hpp:84
bsoncxx::v1::array::view::const_iterator
v1::document::view::const_iterator const_iterator
A const iterator over the elements of a view.
Definition view.hpp:50
bsoncxx::v1::array::view::size
std::size_t size() const
Return the length of the BSON bytes being represented.
Definition view.hpp:74
bsoncxx::v1::array::view::find
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 co...
bsoncxx::v1::array::view::cend
const_iterator cend() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition view.hpp:99
bsoncxx::v1::array::view::end
const_iterator end() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition view.hpp:109
bsoncxx::v1::document::value
A BSON document.
Definition value.hpp:44
bsoncxx::v1::document::value::unique_ptr_type
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
bsoncxx::v1::document::value::deleter_type
std::function< void(std::uint8_t *)> deleter_type
The type of the deleter used to free the underlying BSON bytes.
Definition value.hpp:62
bsoncxx::v1::document::value::default_deleter_type
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
bsoncxx::v1::document::view::const_iterator
A const iterator over the elements of a view.
Definition view.hpp:264
bsoncxx::v1::element::view
A non-owning, read-only BSON element.
Definition view.hpp:82
bsoncxx::v1::array
Declares entities representing a BSON array.
bsoncxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
bsoncxx
The top-level namespace within which all bsoncxx library entities are declared.
value-fwd.hpp
Declares bsoncxx::v1::array::value.
view.hpp
Provides bsoncxx::v1::array::view.
type_traits.hpp
For internal use only!
value.hpp
Provides bsoncxx::v1::document::value.