MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sub_document.hpp
Go to the documentation of this file.
1// Copyright 2009-present 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
18
24
26
27namespace bsoncxx {
28namespace v_noabi {
29namespace builder {
30namespace basic {
31
32namespace impl {
33
34template <typename T>
35void value_append(core* core, T&& t);
36
37} // namespace impl
38
46class sub_document {
47 public:
48 sub_document(core* core) : _core(core) {}
49
53 template <typename Arg, typename... Args>
54 void append(Arg&& a, Args&&... args) {
55 append_(std::forward<Arg>(a));
56 append(std::forward<Args>(args)...);
57 }
58
62 void append() {}
63
64 private:
65 //
66 // Appends a basic::kvp where the key is a non-owning string view.
67 //
68 template <typename K, typename V>
69 detail::requires_t<void, detail::is_alike<K, stdx::string_view>> append_(std::tuple<K, V>&& t) {
70 _core->key_view(std::forward<K>(std::get<0>(t)));
71 impl::value_append(_core, std::forward<V>(std::get<1>(t)));
72 }
73
74 //
75 // Appends a basic::kvp where the key is an owning STL string.
76 //
77 template <typename K, typename V>
78 detail::requires_t<void, detail::is_alike<K, std::string>> append_(std::tuple<K, V>&& t) {
79 _core->key_owned(std::forward<K>(std::get<0>(t)));
80 impl::value_append(_core, std::forward<V>(std::get<1>(t)));
81 }
82
83 //
84 // Appends a basic::kvp where the key is a string literal
85 //
86 template <std::size_t n, typename V>
87 void append_(std::tuple<char const (&)[n], V>&& t) {
88 _core->key_view(stdx::string_view{std::get<0>(t), n - 1});
89 impl::value_append(_core, std::forward<V>(std::get<1>(t)));
90 }
91
92 //
93 // Concatenates another bson document directly.
94 //
95 void append_(concatenate_doc doc) {
96 _core->concatenate(doc);
97 }
98
99 core* _core;
100};
101
102} // namespace basic
103} // namespace builder
104} // namespace v_noabi
105} // namespace bsoncxx
106
108
Redeclares bsoncxx::v_noabi::builder::concatenate in the bsoncxx::v_noabi::builder::basic namespace.
The bsoncxx v_noabi macro guard postlude header.
The bsoncxx v_noabi macro guard prelude header.
A polyfill for std::string_view.
Definition string_view.hpp:411
void append(Arg &&a, Args &&... args)
Appends multiple basic::kvp key-value pairs.
Definition sub_document.hpp:54
void append()
Inductive base-case for the variadic append(...)
Definition sub_document.hpp:62
A low-level interface for constructing BSON documents and arrays.
Definition core.hpp:46
core & key_owned(std::string key)
Appends a key passed as an STL string. Transfers ownership of the key to this class.
core & key_view(stdx::string_view key)
Appends a key passed as a non-owning stdx::string_view.
core & concatenate(bsoncxx::v_noabi::document::view const &view)
Appends the keys from a BSON document into this BSON datum.
Provides concatenators for use with "streaming" BSON builder syntax.
Provides bsoncxx::v_noabi::builder::core.
Declares entities used with "basic" BSON builder syntax.
Declares entities used to build BSON documents.
Declares entities whose ABI stability is NOT guaranteed.
The top-level namespace within which all bsoncxx library entities are declared.
Declares bsoncxx::v_noabi::builder::basic::sub_document.
Provides std::string_view-related polyfills for library API usage.
For internal use only!