MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
array_context.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
17#include <bsoncxx/builder/stream/array_context-fwd.hpp> // IWYU pragma: export
20
27
29
30namespace bsoncxx {
31namespace v_noabi {
32namespace builder {
33namespace stream {
34
50template <class base>
52 public:
60
68 template <class T>
69 detail::requires_not_t<
71 detail::is_invocable<T, array_context<>>,
72 detail::is_invocable<T, single_context>,
73 detail::is_alike<T, finalize_type>>
74 operator<<(T&& t) {
75 _core->append(std::forward<T>(t));
76 return *this;
77 }
78
87 template <typename Func>
88 detail::requires_t<
90 detail::disjunction<detail::is_invocable<Func, array_context>, detail::is_invocable<Func, single_context>>>
91 operator<<(Func&& func) {
92 detail::invoke(std::forward<Func>(func), *this);
93 return *this;
94 }
95
106 template <typename T>
107 detail::requires_t<v_noabi::array::value, std::is_same<base, closed_context>, detail::is_alike<T, finalize_type>>
108 // VS2015U1 can't resolve the name.
109 operator<<(T&&) {
110 return _core->extract_array();
111 }
112
118 key_context<array_context> operator<<(open_document_type const) {
119 _core->open_document();
120 return wrap_document();
121 }
122
133 _core->concatenate(array.view());
134 return *this;
135 }
136
143 _core->open_array();
144 return wrap_array();
145 }
146
153 _core->close_array();
154 return unwrap();
155 }
156
161 operator array_context<>() {
162 return array_context<>(_core);
163 }
164
171 operator single_context();
172
173 private:
174 base unwrap() {
175 return base(_core);
176 }
177
178 array_context<array_context> wrap_array() {
179 return array_context<array_context>(_core);
180 }
181
182 key_context<array_context> wrap_document() {
183 return key_context<array_context>(_core);
184 }
185
186 core* _core;
187};
188
189} // namespace stream
190} // namespace builder
191} // namespace v_noabi
192} // namespace bsoncxx
193
195
Declares bsoncxx::v_noabi::builder::stream::array_context.
The bsoncxx v_noabi macro guard postlude header.
The bsoncxx v_noabi macro guard prelude header.
array_context(core *core)
Create an array_context given a core builder.
Definition array_context.hpp:59
A low-level interface for constructing BSON documents and arrays.
Definition core.hpp:46
core & append(types::b_double const &value)
Appends a BSON double.
core & open_document()
Opens a sub-document within this BSON datum.
v_noabi::array::value extract_array()
Transfers ownership of the underlying document to the caller.
core & open_array()
Opens a sub-array within this BSON datum.
A stream context which expects any number of values.
Definition array_context.hpp:51
array_context operator<<(concatenate_array array)
<< operator for concatenating another array.
Definition array_context.hpp:132
detail::requires_not_t< array_context &, detail::is_invocable< T, array_context<> >, detail::is_invocable< T, single_context >, detail::is_alike< T, finalize_type > > operator<<(T &&t)
<< operator for accepting a real value and appending it to the core builder.
Definition array_context.hpp:74
base operator<<(close_array_type const)
<< operator for closing a subarray in the core builder.
Definition array_context.hpp:152
array_context(core *core)
Create an array_context given a core builder.
Definition array_context.hpp:59
A streaming interface for constructing a BSON array.
Definition array.hpp:42
v_noabi::array::view view() const
Definition array.hpp:52
A stream context which appends a single value.
Definition single_context.hpp:38
Provides bsoncxx::v_noabi::builder::stream::closed_context.
Provides concatenators for use with "streaming" BSON builder syntax.
Provides bsoncxx::v_noabi::builder::core.
Declares bsoncxx::v_noabi::builder::stream::key_context.
Declares entities used with "streaming" 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::stream::single_context.
Provides stream manipulators for use with "streaming" BSON builder syntax.
Container to concatenate an array.
Definition concatenate.hpp:64
The type of a stream manipulator to close a subarray.
Definition helpers.hpp:68
The type of a stream manipulator to open a subarray.
Definition helpers.hpp:53
Provides bsoncxx::v_noabi::array::value.
For internal use only!