2020
2121#include < bsoncxx/v1/detail/prelude.hpp>
2222
23+ #include < bsoncxx/v1/array/view.hpp>
24+ #include < bsoncxx/v1/config/export.hpp>
25+ #include < bsoncxx/v1/document/value.hpp>
26+
27+ #include < cstdint>
28+ #include < cstring>
29+ #include < functional>
30+ #include < memory>
31+ #include < type_traits>
32+ #include < utility>
33+
2334namespace bsoncxx {
2435namespace v1 {
2536namespace array {
@@ -29,7 +40,165 @@ namespace array {
2940// /
3041// / @attention This feature is experimental! It is not ready for use!
3142// /
32- class value {};
43+ class value {
44+ private:
45+ v1::document::value _value;
46+
47+ template <typename T>
48+ struct is_valid_deleter : std::is_constructible<v1::document::value, std::uint8_t *, std::size_t , T> {};
49+
50+ public:
51+ // / @copydoc v1::document::value::deleter_type
52+ using deleter_type = v1::document::value::deleter_type;
53+
54+ // / @copydoc v1::document::value::default_deleter_type
55+ using default_deleter_type = v1::document::value::default_deleter_type;
56+
57+ // / @copydoc v1::document::value::unique_ptr_type
58+ using unique_ptr_type = v1::document::value::unique_ptr_type;
59+
60+ // / @copydoc v1::document::view::const_iterator
61+ using const_iterator = v1::document::view::const_iterator;
62+
63+ // / @copydoc v1::document::view::iterator
64+ using iterator = const_iterator;
65+
66+ // / @copydoc v1::document::value::~value()
67+ ~value () = default ;
68+
69+ // / @copydoc v1::document::value::value(v1::document::value&& other) noexcept
70+ value (value&& other) noexcept : _value{std::move (other._value )} {}
71+
72+ // / @copydoc v1::document::value::operator=(v1::document::value&& other) noexcept
73+ value& operator =(value&& other) noexcept {
74+ _value = std::move (other._value );
75+ return *this ;
76+ }
77+
78+ // / @copydoc v1::document::value::value(v1::document::value const& other)
79+ value (value const & other) : _value(other._value) {}
80+
81+ // / @copydoc v1::document::value::operator=(v1::document::value const& other)
82+ value& operator =(value const & other) {
83+ _value = other._value ;
84+ return *this ;
85+ }
86+
87+ // / @copydoc v1::document::value::value()
88+ value () = default ;
89+
90+ // / @copydoc v1::document::value::value(std::uint8_t* data, std::size_t length, Deleter deleter)
91+ template <typename Deleter, detail::enable_if_t <is_valid_deleter<Deleter>::value>* = nullptr >
92+ value (std::uint8_t * data, std::size_t length, Deleter deleter) : _value{data, length, std::move (deleter)} {}
93+
94+ // / @copydoc v1::document::value::value(std::uint8_t* data, std::size_t length)
95+ value (std::uint8_t * data, std::size_t length) : _value{data, length} {}
96+
97+ // / @copydoc v1::document::value::value(v1::document::value::unique_ptr_type ptr, std::size_t length)
98+ value (unique_ptr_type ptr, std::size_t length) : _value{std::move (ptr), length} {}
99+
100+ // / @copydoc v1::document::value::value(v1::document::view const& view)
101+ explicit value (v1::array::view view) : _value{view} {}
102+
103+ // / @copydoc v1::document::value::get_deleter() const
104+ deleter_type const & get_deleter () const {
105+ return _value.get_deleter ();
106+ }
107+
108+ // / @copydoc v1::document::value::release()
109+ unique_ptr_type release () {
110+ return _value.release ();
111+ }
112+
113+ // / @copydoc v1::document::value::reset(v1::document::value v)
114+ void reset (value v) {
115+ _value = std::move (v._value );
116+ }
117+
118+ // / @copydoc v1::document::value::reset(v1::document::view const& v)
119+ void reset (v1::array::view v) {
120+ *this = value{v};
121+ }
122+
123+ // /
124+ // / Return a view of the BSON binary data as an array.
125+ // /
126+ v1::array::view view () const {
127+ return {_value.data (), _value.size ()};
128+ }
129+
130+ // /
131+ // / Implicitly convert to `this->view()`.
132+ // /
133+ /* explicit(false) */ operator v1::array::view () const {
134+ return this ->view ();
135+ }
136+
137+ // / @copydoc v1::array::view::cbegin() const
138+ v1::array::view::const_iterator cbegin () const {
139+ return this ->view ().cbegin ();
140+ }
141+
142+ // / @copydoc v1::array::view::cend() const
143+ v1::array::view::const_iterator cend () const {
144+ return this ->view ().cend ();
145+ }
146+
147+ // / @copydoc v1::array::view::begin() const
148+ v1::array::view::const_iterator begin () const {
149+ return this ->view ().begin ();
150+ }
151+
152+ // / @copydoc v1::array::view::end() const
153+ v1::array::view::const_iterator end () const {
154+ return this ->view ().end ();
155+ }
156+
157+ // / @copydoc v1::array::view::find(std::uint32_t i) const
158+ v1::array::view::const_iterator find (std::uint32_t i) const {
159+ return this ->view ().find (i);
160+ }
161+
162+ // / @copydoc v1::array::view::operator[](std::uint32_t i) const
163+ v1::element::view operator [](std::uint32_t i) const {
164+ return this ->view ()[i];
165+ }
166+
167+ // / @copydoc v1::array::view::data() const
168+ std::uint8_t const * data () const {
169+ return this ->view ().data ();
170+ }
171+
172+ // / @copydoc v1::array::view::size() const
173+ std::size_t size () const {
174+ return this ->view ().size ();
175+ }
176+
177+ // / @copydoc v1::array::view::length() const
178+ std::size_t length () const {
179+ return this ->view ().length ();
180+ }
181+
182+ // / @copydoc v1::array::view::empty() const
183+ bool empty () const {
184+ return this ->view ().empty ();
185+ }
186+
187+ // / @copydoc v1::array::view::operator bool() const
188+ explicit operator bool () const {
189+ return this ->view ().operator bool ();
190+ }
191+
192+ // / @copydoc v1::array::view::operator==(v1::array::view const& lhs, v1::array::view const& rhs)
193+ friend bool operator ==(value const & lhs, value const & rhs) {
194+ return lhs.view () == rhs.view ();
195+ }
196+
197+ // / @copydoc v1::array::view::operator!=(v1::array::view const& lhs, v1::array::view const& rhs)
198+ friend bool operator !=(value const & lhs, value const & rhs) {
199+ return !(lhs == rhs);
200+ }
201+ };
33202
34203} // namespace array
35204} // namespace v1
@@ -41,3 +210,8 @@ class value {};
41210// / @file
42211// / Provides @ref bsoncxx::v1::array::value.
43212// /
213+ // / @par Includes
214+ // / - @ref bsoncxx/v1/array/view.hpp
215+ // / - @ref bsoncxx/v1/document/value.hpp
216+ // / - @ref bsoncxx/v1/element/view.hpp
217+ // /
0 commit comments