MongoDB C++ Driver  mongocxx-3.6.2
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
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 
79  core& key_view(stdx::string_view key);
80 
94  core& key_owned(std::string key);
95 
108 
121 
132 
143 
162 
175  core& append(const types::b_double& value);
176 
189  core& append(const types::b_utf8& value);
190 
203  core& append(const types::b_document& value);
204 
217  core& append(const types::b_array& value);
218 
231  core& append(const types::b_binary& value);
232 
246 
259  core& append(const types::b_oid& value);
260 
273  core& append(const types::b_bool& value);
274 
287  core& append(const types::b_date& value);
288 
301  core& append(const types::b_null& value);
302 
315  core& append(const types::b_regex& value);
316 
330 
343  core& append(const types::b_code& value);
344 
357  core& append(const types::b_symbol& value);
358 
372 
385  core& append(const types::b_int32& value);
386 
400 
413  core& append(const types::b_int64& value);
414 
428 
441  core& append(const types::b_minkey& value);
442 
455  core& append(const types::b_maxkey& value);
456 
469 
481  core& append(std::string str);
482 
494  core& append(stdx::string_view str);
495 
509  template <typename T>
510  BSONCXX_INLINE core& append(T* v) {
511  static_assert(std::is_same<typename std::remove_const<T>::type, char>::value,
512  "append is disabled for non-char pointer types");
513  append(types::b_utf8{v});
514 
515  return *this;
516  }
517 
529  core& append(bool value);
530 
542  core& append(double value);
543 
555  core& append(std::int32_t value);
556 
568  core& append(std::int64_t value);
569 
581  core& append(const oid& value);
582 
595 
608 
621 
635 
648 
666 
683 
688  void clear();
689 
690  private:
691  std::unique_ptr<impl> _impl;
692 };
693 
694 } // namespace builder
695 BSONCXX_INLINE_NAMESPACE_END
696 } // namespace bsoncxx
697 
698 #include <bsoncxx/config/postlude.hpp>
bsoncxx::types::b_array
A BSON array value.
Definition: types.hpp:181
bsoncxx::types::b_oid
A BSON ObjectId value.
Definition: types.hpp:246
bsoncxx::builder::core::extract_document
document::value extract_document()
Transfers ownership of the underlying document to the caller.
bsoncxx::builder::core::append
core & append(const types::b_null &value)
Appends a BSON null.
bsoncxx::builder::core::append
core & append(array::view view)
Appends the given array view.
bsoncxx::builder::core::append
core & append(const types::b_int32 &value)
Appends a BSON 32-bit signed integer.
bsoncxx::builder::core::append
core & append(const types::b_bool &value)
Appends a BSON boolean.
bsoncxx::types::b_utf8
A BSON UTF-8 encoded string value.
Definition: types.hpp:113
bsoncxx::builder::core::append
core & append(const types::b_codewscope &value)
Appends a BSON JavaScript code with scope.
bsoncxx::builder::core::clear
void clear()
Deletes the contents of the underlying BSON datum.
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
bsoncxx::builder::core::append
core & append(const types::b_minkey &value)
Appends a BSON min-key.
bsoncxx::types::b_document
A BSON document value.
Definition: types.hpp:149
bsoncxx::types::b_null
A BSON null value.
Definition: types.hpp:348
bsoncxx::builder::core::append
core & append(const types::b_int64 &value)
Appends a BSON 64-bit signed integer.
bsoncxx::types::b_codewscope
A BSON JavaScript code with scope value.
Definition: types.hpp:496
bsoncxx::builder::core::append
core & append(const types::b_timestamp &value)
Appends a BSON replication timestamp.
bsoncxx::builder::core::core
core(bool is_array)
Constructs an empty BSON datum.
bsoncxx::types::b_int64
A BSON 64-bit signed integer value.
Definition: types.hpp:580
bsoncxx::builder::core::key_owned
core & key_owned(std::string key)
Appends a key passed as an STL string.
bsoncxx::types::b_binary
A BSON binary data value.
Definition: types.hpp:206
bsoncxx::array::view
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
bsoncxx::builder::core::append
core & append(decimal128 value)
Appends a decimal128 object as a BSON Decimal128.
bsoncxx::document::value
A read-only BSON document that owns its underlying buffer.
Definition: value.hpp:33
bsoncxx::builder::core::append
core & append(const types::b_array &value)
Appends a BSON array.
bsoncxx::builder::core::view_document
document::view view_document() const
Gets a view over the document.
bsoncxx::builder::core::append
core & append(const types::b_double &value)
Appends a BSON double.
bsoncxx::builder::core::append
core & append(const types::b_regex &value)
Appends a BSON regex.
bsoncxx::builder::core::append
core & append(std::int64_t value)
Appends a native int64_t as a BSON 64-bit signed integer.
bsoncxx::builder::core::append
core & append(const types::b_undefined &value)
Appends a BSON undefined.
bsoncxx::builder::core::key_view
core & key_view(stdx::string_view key)
Appends a key passed as a non-owning stdx::string_view.
bsoncxx::array::value
A read-only BSON array that owns its underlying buffer.
Definition: value.hpp:34
bsoncxx::types::b_symbol
A BSON Symbol value.
Definition: types.hpp:460
bsoncxx::types::b_dbpointer
A BSON DBPointer value.
Definition: types.hpp:402
bsoncxx::oid
Represents a MongoDB ObjectId.
Definition: oid.hpp:38
bsoncxx::builder::core::append
core & append(const types::b_symbol &value)
Appends a BSON symbol.
bsoncxx::builder::core::open_array
core & open_array()
Opens a sub-array within this BSON datum.
bsoncxx::types::b_regex
A BSON regex value.
Definition: types.hpp:364
bsoncxx::types::b_maxkey
A BSON max-key value.
Definition: types.hpp:651
bsoncxx::builder::core::append
core & append(const types::b_decimal128 &value)
Appends a BSON Decimal128.
bsoncxx::builder::core::append
core & append(const types::b_utf8 &value)
Append a BSON UTF-8 string.
bsoncxx::decimal128
Represents an IEEE 754-2008 BSON Decimal128 value in a platform-independent way.
Definition: decimal128.hpp:30
bsoncxx::builder::core::append
core & append(const types::bson_value::view &value)
Appends a BSON variant value.
bsoncxx::types::b_timestamp
A BSON replication timestamp value.
Definition: types.hpp:561
bsoncxx::builder::core::close_array
core & close_array()
Closes the current sub-array within this BSON datum.
bsoncxx::types::b_date
A BSON date value.
Definition: types.hpp:289
bsoncxx::types::b_int32
A BSON signed 32-bit integer value.
Definition: types.hpp:532
bsoncxx::types::b_minkey
A BSON min-key value.
Definition: types.hpp:635
bsoncxx::builder::core
A low-level interface for constructing BSON documents and arrays.
Definition: core.hpp:42
bsoncxx::builder::core::open_document
core & open_document()
Opens a sub-document within this BSON datum.
bsoncxx::builder::core::append
core & append(const types::b_binary &value)
Appends a BSON binary datum.
bsoncxx::builder::core::append
core & append(bool value)
Appends a native boolean as a BSON boolean.
bsoncxx::builder::core::append
core & append(std::int32_t value)
Appends a native int32_t as a BSON 32-bit signed integer.
bsoncxx::builder::core::append
core & append(const types::b_document &value)
Appends a BSON document.
bsoncxx::types::b_code
A BSON JavaScript code value.
Definition: types.hpp:421
bsoncxx::types::b_decimal128
A BSON Decimal128 value.
Definition: types.hpp:605
bsoncxx::builder::core::append
core & append(const types::b_maxkey &value)
Appends a BSON max-key.
bsoncxx::builder::core::append
core & append(const types::b_dbpointer &value)
Appends a BSON DBPointer.
bsoncxx::builder::core::append
core & append(document::view view)
Appends the given document view.
bsoncxx::builder::core::append
core & append(std::string str)
Appends an STL string as a BSON UTF-8 string.
bsoncxx::builder::core::append
core & append(T *v)
Appends a char* or const char*.
Definition: core.hpp:510
bsoncxx::builder::core::extract_array
array::value extract_array()
Transfers ownership of the underlying document to the caller.
bsoncxx::types::b_undefined
A BSON undefined value.
Definition: types.hpp:230
bsoncxx::builder::core::concatenate
core & concatenate(const document::view &view)
Appends the keys from a BSON document into this BSON datum.
bsoncxx::builder::core::close_document
core & close_document()
Closes the current sub-document within this BSON datum.
bsoncxx::builder::core::view_array
array::view view_array() const
Gets a view over the array.
bsoncxx::builder::core::append
core & append(stdx::string_view str)
Appends a string view as a BSON UTF-8 string.
bsoncxx::builder::core::append
core & append(const types::b_code &value)
Appends a BSON JavaScript code.
bsoncxx::types::b_bool
A BSON boolean value.
Definition: types.hpp:264
bsoncxx::builder::core::append
core & append(double value)
Appends a native double as a BSON double.
bsoncxx::builder::core::append
core & append(const types::b_oid &value)
Appends a BSON ObjectId.
bsoncxx::types::b_double
A BSON double value.
Definition: types.hpp:88
bsoncxx::builder::core::append
core & append(const oid &value)
Appends an oid as a BSON ObjectId.
bsoncxx::document::view
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
bsoncxx::builder::core::append
core & append(const types::b_date &value)
Appends a BSON date.
bsoncxx::types::bson_value::view
A view-only variant that can contain any BSON type.
Definition: view.hpp:44