MongoDB C++ Driver  mongocxx-3.0.2
core.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 <memory>
18 #include <stdexcept>
19 #include <type_traits>
20 
21 #include <bsoncxx/array/value.hpp>
22 #include <bsoncxx/array/view.hpp>
23 #include <bsoncxx/document/value.hpp>
24 #include <bsoncxx/document/view.hpp>
25 #include <bsoncxx/stdx/string_view.hpp>
26 #include <bsoncxx/types.hpp>
27 
28 #include <bsoncxx/config/prelude.hpp>
29 
30 namespace bsoncxx {
31 BSONCXX_INLINE_NAMESPACE_BEGIN
32 namespace builder {
33 
42 class BSONCXX_API core {
43  public:
44  class BSONCXX_PRIVATE impl;
45 
52  explicit core(bool is_array);
53 
54  core(core&& rhs) noexcept;
55  core& operator=(core&& rhs) noexcept;
56 
57  ~core();
58 
72  void key_view(stdx::string_view key);
73 
81  void key_owned(std::string key);
82 
86  void open_document();
87 
91  void open_array();
92 
96  void close_document();
97 
101  void close_array();
102 
110  void concatenate(const document::view& view);
111 
115  void append(const types::b_double& value);
116 
120  void append(const types::b_utf8& value);
121 
125  void append(const types::b_document& value);
126 
130  void append(const types::b_array& value);
131 
135  void append(const types::b_binary& value);
136 
140  void append(const types::b_undefined& value);
141 
145  void append(const types::b_oid& value);
146 
150  void append(const types::b_bool& value);
151 
155  void append(const types::b_date& value);
156 
160  void append(const types::b_null& value);
161 
165  void append(const types::b_regex& value);
166 
170  void append(const types::b_dbpointer& value);
171 
175  void append(const types::b_code& value);
176 
180  void append(const types::b_symbol& value);
181 
185  void append(const types::b_codewscope& value);
186 
190  void append(const types::b_int32& value);
191 
195  void append(const types::b_timestamp& value);
196 
200  void append(const types::b_int64& value);
201 
205  void append(const types::b_minkey& value);
206 
210  void append(const types::b_maxkey& value);
211 
215  void append(const types::value& value);
216 
220  void append(std::string str);
221 
225  void append(stdx::string_view str);
226 
233  template <typename T>
234  BSONCXX_INLINE void append(T* v) {
235  static_assert(std::is_same<typename std::remove_const<T>::type, char>::value,
236  "append is disabled for non-char pointer types");
237  append(types::b_utf8{v});
238  }
239 
243  void append(bool value);
244 
248  void append(double value);
249 
253  void append(std::int32_t value);
254 
258  void append(std::int64_t value);
259 
263  void append(const oid& value);
264 
268  void append(document::view view);
269 
273  void append(array::view view);
274 
280  document::view view_document() const;
281 
291  array::view view_array() const;
292 
302  document::value extract_document();
303 
317  array::value extract_array();
318 
323  void clear();
324 
325  private:
326  std::unique_ptr<impl> _impl;
327 };
328 
329 } // namespace builder
330 BSONCXX_INLINE_NAMESPACE_END
331 } // namespace bsoncxx
332 
333 #include <bsoncxx/config/postlude.hpp>
A low-level interface for constructing BSON documents and arrays.
Definition: core.hpp:42
A BSON signed 32-bit integer value.
Definition: types.hpp:531
A BSON double value.
Definition: types.hpp:84
A BSON Symbol value.
Definition: types.hpp:460
A read-only BSON array that owns its underlying buffer.
Definition: value.hpp:34
Represents a MongoDB ObjectId.
Definition: oid.hpp:38
A read-only BSON document that owns its underlying buffer.
Definition: value.hpp:33
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
A BSON null value.
Definition: types.hpp:348
A BSON regex value.
Definition: types.hpp:364
A BSON binary data value.
Definition: types.hpp:204
A BSON DBPointer value.
Definition: types.hpp:400
A BSON max-key value.
Definition: types.hpp:620
A BSON UTF-8 encoded string value.
Definition: types.hpp:109
A BSON date value.
Definition: types.hpp:287
A BSON min-key value.
Definition: types.hpp:604
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
A BSON JavaScript code value.
Definition: types.hpp:419
A BSON JavaScript code with scope value.
Definition: types.hpp:498
A BSON 64-bit signed integer value.
Definition: types.hpp:579
A BSON replication timestamp value.
Definition: types.hpp:560
A BSON document value.
Definition: types.hpp:147
void append(T *v)
Append a char* or const char*.
Definition: core.hpp:234
A BSON boolean value.
Definition: types.hpp:262
A BSON ObjectId value.
Definition: types.hpp:244
Definition: element.hpp:24
A BSON undefined value.
Definition: types.hpp:228
A BSON array value.
Definition: types.hpp:179
A variant that can contain any BSON type.
Definition: value.hpp:37