MongoDB C++ Driver mongocxx-3.11.0
Loading...
Searching...
No Matches
key_context.hpp
Go to the documentation of this file.
1
2// Copyright 2009-present MongoDB, Inc.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#pragma once
17
20
25
27
28namespace bsoncxx {
29namespace v_noabi {
30namespace builder {
31namespace stream {
32
50template <class base>
52 public:
59 key_context(core* core) : _core(core) {}
60
71 template <std::size_t n>
72 value_context<key_context> operator<<(const char (&v)[n]) {
73 _core->key_view(stdx::string_view{v, n - 1});
74 return value_context<key_context>(_core);
75 }
76
87 value_context<key_context> operator<<(std::string str) {
88 _core->key_owned(std::move(str));
89 return value_context<key_context>(_core);
90 }
91
102 value_context<key_context> operator<<(stdx::string_view str) {
103 _core->key_view(std::move(str));
104 return value_context<key_context>(_core);
105 }
106
115 template <typename T>
116 detail::requires_t<key_context&, detail::is_invocable<T, key_context>> //
117 operator<<(T&& func) {
118 detail::invoke(std::forward<T>(func), *this);
119 return *this;
120 }
121
132 template <typename T>
133 detail::requires_t<bsoncxx::v_noabi::document::value,
134 std::is_same<base, closed_context>,
135 detail::is_alike<T, finalize_type>>
136 operator<<(T&&) {
137 return _core->extract_document();
138 }
139
150 _core->concatenate(doc);
151 return *this;
152 }
153
160 _core->close_document();
161 return unwrap();
162 }
163
168 operator key_context<>() {
169 return key_context<>(_core);
170 }
171
172 private:
173 base unwrap() {
174 return base(_core);
175 }
176
177 core* _core;
178};
179
180} // namespace stream
181} // namespace builder
182} // namespace v_noabi
183} // namespace bsoncxx
184
186
The bsoncxx macro guard postlude header.
The bsoncxx macro guard prelude header.
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(const bsoncxx::v_noabi::document::view &view)
Appends the keys from a BSON document into this BSON datum.
bsoncxx::v_noabi::document::value extract_document()
Transfers ownership of the underlying document to the caller.
core & close_document()
Closes the current sub-document within this BSON datum.
A stream context which expects a key, which can later be followed by value, then more key/value pairs...
Definition key_context.hpp:51
key_context operator<<(concatenate_doc doc)
<< operator for concatenating another document.
Definition key_context.hpp:149
value_context< key_context > operator<<(const char(&v)[n])
<< operator for accepting a literal key and appending it to the core builder.
Definition key_context.hpp:72
base operator<<(const close_document_type)
<< operator for closing a subdocument in the core builder.
Definition key_context.hpp:159
key_context(core *core)
Create a key_context given a core builder.
Definition key_context.hpp:59
A stream context which expects a value, which can later be followed by more key/value pairs.
Definition value_context.hpp:50
A read-only BSON document that owns its underlying buffer. When a document::value goes out of scope,...
Definition value.hpp:38
A polyfill for std::string_view.
Definition string_view.hpp:503
Declares bsoncxx::v_noabi::builder::stream::closed_context.
Provides bsoncxx::v_noabi::builder::core.
Declares bsoncxx::v_noabi::builder::stream::key_context.
The top-level namespace within which all bsoncxx library entities are declared.
Provides std::string_view-related polyfills for library API usage.
Container to concatenate a document. Use it by constructing an instance with the document to be conca...
Definition concatenate.hpp:32
The type of a stream manipulator to close a subdocument.
Definition helpers.hpp:44
Provides <type_traits>-related polyfills for internal use.
Provides bsoncxx::v_noabi::builder::stream::value_context.