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 < type_traits>
29+ #include < utility>
30+
2331namespace bsoncxx {
2432namespace v1 {
2533namespace array {
@@ -29,7 +37,178 @@ namespace array {
2937// /
3038// / @attention This feature is experimental! It is not ready for use!
3139// /
32- class value {};
40+ class value {
41+ private:
42+ v1::document::value _value;
43+
44+ template <typename T>
45+ struct is_valid_deleter : std::is_constructible<v1::document::value, std::uint8_t *, T> {};
46+
47+ public:
48+ // / @copydoc v1::document::value::deleter_type
49+ using deleter_type = v1::document::value::deleter_type;
50+
51+ // / @copydoc v1::document::value::default_deleter_type
52+ using default_deleter_type = v1::document::value::default_deleter_type;
53+
54+ // / @copydoc v1::document::value::unique_ptr_type
55+ using unique_ptr_type = v1::document::value::unique_ptr_type;
56+
57+ // / @copydoc v1::document::view::const_iterator
58+ using const_iterator = v1::document::view::const_iterator;
59+
60+ // / @copydoc v1::document::view::iterator
61+ using iterator = const_iterator;
62+
63+ // / @copydoc v1::document::value::~value()
64+ ~value () = default ;
65+
66+ // / @copydoc v1::document::value::value(v1::document::value&& other) noexcept
67+ value (value&& other) noexcept = default ;
68+
69+ // / @copydoc v1::document::value::operator=(v1::document::value&& other) noexcept
70+ value& operator =(value&& other) noexcept = default ;
71+
72+ // / @copydoc v1::document::value::value(v1::document::value const& other)
73+ value (value const & other) : _value(other._value) {}
74+
75+ // / @copydoc v1::document::value::operator=(v1::document::view view)
76+ value& operator =(v1::array::view view) {
77+ this ->reset (view);
78+ return *this ;
79+ }
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, Deleter deleter)
91+ template <typename Deleter, detail::enable_if_t <is_valid_deleter<Deleter>::value>* = nullptr >
92+ value (std::uint8_t * data, Deleter deleter) : _value{data, std::move (deleter)} {}
93+
94+ // / @copydoc v1::document::value::value(std::uint8_t* data, std::size_t length, Deleter deleter)
95+ template <typename Deleter, detail::enable_if_t <is_valid_deleter<Deleter>::value>* = nullptr >
96+ value (std::uint8_t * data, std::size_t length, Deleter deleter) : _value{data, length, std::move (deleter)} {}
97+
98+ // / @copydoc v1::document::value::value(std::uint8_t* data)
99+ explicit value (std::uint8_t * data) : _value{data} {}
100+
101+ // / @copydoc v1::document::value::value(std::uint8_t* data, std::size_t length)
102+ value (std::uint8_t * data, std::size_t length) : _value{data, length} {}
103+
104+ // / @copydoc v1::document::value::value(v1::document::value::unique_ptr_type ptr)
105+ explicit value (unique_ptr_type ptr) : _value{std::move (ptr)} {}
106+
107+ // / @copydoc v1::document::value::value(v1::document::value::unique_ptr_type ptr, std::size_t length)
108+ value (unique_ptr_type ptr, std::size_t length) : _value{std::move (ptr), length} {}
109+
110+ // / @copydoc v1::document::value::value(v1::document::view view)
111+ explicit value (v1::array::view view) : _value{view} {}
112+
113+ // / @copydoc v1::document::value::get_deleter() const
114+ deleter_type const & get_deleter () const {
115+ return _value.get_deleter ();
116+ }
117+
118+ // / @copydoc v1::document::value::release()
119+ unique_ptr_type release () {
120+ return _value.release ();
121+ }
122+
123+ // / @copydoc v1::document::value::reset(v1::document::value v)
124+ void reset (value v) {
125+ _value = std::move (v._value );
126+ }
127+
128+ // / @copydoc v1::document::value::reset(v1::document::view v)
129+ void reset (v1::array::view v) {
130+ *this = value{v};
131+ }
132+
133+ // /
134+ // / Return a view of the BSON bytes as an array.
135+ // /
136+ v1::array::view view () const {
137+ return v1::array::view{_value.data ()};
138+ }
139+
140+ // /
141+ // / Implicitly convert to `this->view()`.
142+ // /
143+ /* explicit(false) */ operator v1::array::view () const {
144+ return this ->view ();
145+ }
146+
147+ // / @copydoc v1::array::view::cbegin() const
148+ v1::array::view::const_iterator cbegin () const {
149+ return this ->view ().cbegin ();
150+ }
151+
152+ // / @copydoc v1::array::view::cend() const
153+ v1::array::view::const_iterator cend () const {
154+ return this ->view ().cend ();
155+ }
156+
157+ // / @copydoc v1::array::view::begin() const
158+ v1::array::view::const_iterator begin () const {
159+ return this ->view ().begin ();
160+ }
161+
162+ // / @copydoc v1::array::view::end() const
163+ v1::array::view::const_iterator end () const {
164+ return this ->view ().end ();
165+ }
166+
167+ // / @copydoc v1::array::view::find(std::uint32_t i) const
168+ v1::array::view::const_iterator find (std::uint32_t i) const {
169+ return this ->view ().find (i);
170+ }
171+
172+ // / @copydoc v1::array::view::operator[](std::uint32_t i) const
173+ v1::element::view operator [](std::uint32_t i) const {
174+ return this ->view ()[i];
175+ }
176+
177+ // / @copydoc v1::array::view::data() const
178+ std::uint8_t const * data () const {
179+ return this ->view ().data ();
180+ }
181+
182+ // / @copydoc v1::array::view::size() const
183+ std::size_t size () const {
184+ return this ->view ().size ();
185+ }
186+
187+ // / @copydoc v1::array::view::length() const
188+ std::size_t length () const {
189+ return this ->view ().length ();
190+ }
191+
192+ // / @copydoc v1::array::view::empty() const
193+ bool empty () const {
194+ return this ->view ().empty ();
195+ }
196+
197+ // / @copydoc v1::array::view::operator bool() const
198+ explicit operator bool () const {
199+ return this ->view ().operator bool ();
200+ }
201+
202+ // / @copydoc v1::array::view::operator==(v1::array::view lhs, v1::array::view rhs)
203+ friend bool operator ==(value const & lhs, value const & rhs) {
204+ return lhs.view () == rhs.view ();
205+ }
206+
207+ // / @copydoc v1::array::view::operator!=(v1::array::view lhs, v1::array::view rhs)
208+ friend bool operator !=(value const & lhs, value const & rhs) {
209+ return !(lhs == rhs);
210+ }
211+ };
33212
34213} // namespace array
35214} // namespace v1
@@ -41,3 +220,7 @@ class value {};
41220// / @file
42221// / Provides @ref bsoncxx::v1::array::value.
43222// /
223+ // / @par Includes
224+ // / - @ref bsoncxx/v1/array/view.hpp
225+ // / - @ref bsoncxx/v1/document/value.hpp
226+ // /
0 commit comments