MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
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<
109 std::is_same<base, closed_context>,
110 detail::is_alike<T, finalize_type>>
111 // VS2015U1 can't resolve the name.
112 operator<<(T&&) {
113 return _core->extract_array();
114 }
115
121 key_context<array_context> operator<<(open_document_type const) {
122 _core->open_document();
123 return wrap_document();
124 }
125
136 _core->concatenate(array.view());
137 return *this;
138 }
139
146 _core->open_array();
147 return wrap_array();
148 }
149
156 _core->close_array();
157 return unwrap();
158 }
159
164 operator array_context<>() {
165 return array_context<>(_core);
166 }
167
174 operator single_context();
175
176 private:
177 base unwrap() {
178 return base(_core);
179 }
180
181 array_context<array_context> wrap_array() {
182 return array_context<array_context>(_core);
183 }
184
185 key_context<array_context> wrap_document() {
186 return key_context<array_context>(_core);
187 }
188
189 core* _core;
190};
191
192} // namespace stream
193} // namespace builder
194} // namespace v_noabi
195} // namespace bsoncxx
196
198
Provides bsoncxx::v_noabi::array::value.
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 read-only BSON array that owns its underlying buffer.
Definition value.hpp:37
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.
bsoncxx::v_noabi::array::value extract_array()
Transfers ownership of the underlying document to the caller.
core & open_document()
Opens a sub-document within this BSON datum.
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:135
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:155
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
bsoncxx::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
For internal use only!