MongoDB C++ Driver  mongocxx-3.10.2
array.hpp
1 // Copyright 2014 MongoDB Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <bsoncxx/builder/basic/array-fwd.hpp>
18 
19 #include <bsoncxx/array/value.hpp>
20 #include <bsoncxx/array/view.hpp>
21 #include <bsoncxx/builder/basic/impl.hpp>
22 #include <bsoncxx/builder/basic/kvp.hpp>
23 #include <bsoncxx/builder/basic/sub_array.hpp>
24 #include <bsoncxx/builder/core.hpp>
25 
26 #include <bsoncxx/config/prelude.hpp>
27 
28 namespace bsoncxx {
29 namespace v_noabi {
30 namespace builder {
31 namespace basic {
32 
37 class array : public sub_array {
38  public:
42  BSONCXX_INLINE array() : sub_array(&_core), _core(true) {}
43 
47  BSONCXX_INLINE array(array&& arr) noexcept : sub_array(&_core), _core(std::move(arr._core)) {}
48 
52  BSONCXX_INLINE array& operator=(array&& arr) noexcept {
53  _core = std::move(arr._core);
54  return *this;
55  }
56 
60  BSONCXX_INLINE bsoncxx::v_noabi::array::view view() const {
61  return _core.view_array();
62  }
63 
70  BSONCXX_INLINE operator bsoncxx::v_noabi::array::view() const {
71  return view();
72  }
73 
84  return _core.extract_array();
85  }
86 
90  BSONCXX_INLINE void clear() {
91  _core.clear();
92  }
93 
94  private:
95  core _core;
96 };
97 
108 template <typename... Args>
109 bsoncxx::v_noabi::array::value BSONCXX_CALL make_array(Args&&... args) {
110  array array;
111  array.append(std::forward<Args>(args)...);
112  return array.extract();
113 }
114 
115 } // namespace basic
116 } // namespace builder
117 } // namespace v_noabi
118 } // namespace bsoncxx
119 
120 namespace bsoncxx {
121 namespace builder {
122 namespace basic {
123 
124 using ::bsoncxx::v_noabi::builder::basic::make_array;
125 
126 } // namespace basic
127 } // namespace builder
128 } // namespace bsoncxx
129 
130 #include <bsoncxx/config/postlude.hpp>
A read-only BSON array that owns its underlying buffer.
Definition: value.hpp:36
A read-only, non-owning view of a BSON document.
Definition: view.hpp:36
A JSON-like builder for creating arrays.
Definition: list.hpp:180
A traditional builder-style interface for constructing a BSON array.
Definition: array.hpp:37
void clear()
Reset the underlying BSON to an empty array.
Definition: array.hpp:90
array & operator=(array &&arr) noexcept
Move assignment operator.
Definition: array.hpp:52
bsoncxx::v_noabi::array::view view() const
Definition: array.hpp:60
array(array &&arr) noexcept
Move constructor.
Definition: array.hpp:47
array()
Default constructor.
Definition: array.hpp:42
bsoncxx::v_noabi::array::value extract()
Transfer ownership of the underlying array to the caller.
Definition: array.hpp:83
An internal class of builder::basic.
Definition: sub_array.hpp:41
sub_array(core *core)
Default constructor.
Definition: sub_array.hpp:46
A low-level interface for constructing BSON documents and arrays.
Definition: core.hpp:45
void clear()
Deletes the contents of the underlying BSON datum.
bsoncxx::v_noabi::array::view view_array() const
Gets a view over the array.
bsoncxx::v_noabi::array::value extract_array()
Transfers ownership of the underlying document to the caller.
The top-level namespace for bsoncxx library entities.
Definition: element-fwd.hpp:19