MongoDB C++ Driver mongocxx-3.11.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
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<array_context&,
70 detail::is_invocable<T, array_context<>>,
71 detail::is_invocable<T, single_context>,
72 detail::is_alike<T, finalize_type>>
73 operator<<(T&& t) {
74 _core->append(std::forward<T>(t));
75 return *this;
76 }
77
86 template <typename Func>
87 detail::requires_t<array_context&,
88 detail::disjunction<detail::is_invocable<Func, array_context>,
89 detail::is_invocable<Func, single_context>>>
90 operator<<(Func&& func) {
91 detail::invoke(std::forward<Func>(func), *this);
92 return *this;
93 }
94
105 template <typename T>
106 detail::requires_t<bsoncxx::v_noabi::array::value,
107 std::is_same<base, closed_context>,
108 detail::is_alike<T, finalize_type>>
109 // VS2015U1 can't resolve the name.
110 operator<<(T&&) {
111 return _core->extract_array();
112 }
113
119 key_context<array_context> operator<<(const open_document_type) {
120 _core->open_document();
121 return wrap_document();
122 }
123
134 _core->concatenate(array.view());
135 return *this;
136 }
137
144 _core->open_array();
145 return wrap_array();
146 }
147
154 _core->close_array();
155 return unwrap();
156 }
157
162 operator array_context<>() {
163 return array_context<>(_core);
164 }
165
172 operator single_context();
173
174 private:
175 base unwrap() {
176 return base(_core);
177 }
178
179 array_context<array_context> wrap_array() {
180 return array_context<array_context>(_core);
181 }
182
183 key_context<array_context> wrap_document() {
184 return key_context<array_context>(_core);
185 }
186
187 core* _core;
188};
189
190} // namespace stream
191} // namespace builder
192} // namespace v_noabi
193} // namespace bsoncxx
194
196
Provides bsoncxx::v_noabi::array::value.
Declares bsoncxx::v_noabi::builder::stream::array_context.
The bsoncxx macro guard postlude header.
The bsoncxx macro guard prelude header.
A read-only BSON array that owns its underlying buffer. When a array::value goes out of scope,...
Definition value.hpp:36
A low-level interface for constructing BSON documents and arrays.
Definition core.hpp:46
bsoncxx::v_noabi::array::value extract_array()
Transfers ownership of the underlying document to the caller.
core & append(const types::b_double &value)
Appends a BSON double.
core & open_document()
Opens a sub-document within this BSON datum.
core & close_array()
Closes the current sub-array within this BSON datum.
core & concatenate(const bsoncxx::v_noabi::document::view &view)
Appends the keys from a BSON document into 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:133
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:73
base operator<<(const close_array_type)
<< operator for closing a subarray in the core builder.
Definition array_context.hpp:153
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.
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. Use this with the array stream builder in order to pass an array i...
Definition concatenate.hpp:60
The type of a stream manipulator to close a subarray.
Definition helpers.hpp:71
The type of a stream manipulator to open a subarray.
Definition helpers.hpp:56
Provides <type_traits>-related polyfills for internal use.