MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
value_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
18
24
26
27namespace bsoncxx {
28namespace v_noabi {
29namespace builder {
30namespace stream {
31
50template <class base>
52 public:
60
68 template <class T>
69 detail::requires_not_t<base, detail::is_invocable<T, single_context>> operator<<(T&& t) {
70 _core->append(std::forward<T>(t));
71 return unwrap();
72 }
73
81 template <typename T>
82 detail::requires_t<base, detail::is_invocable<T, single_context>> operator<<(T&& func) {
83 detail::invoke(std::forward<T>(func), *this);
84 return unwrap();
85 }
86
92 key_context<base> operator<<(open_document_type const) {
93 _core->open_document();
94 return wrap_document();
95 }
96
102 array_context<base> operator<<(open_array_type const) {
103 _core->open_array();
104 return wrap_array();
105 }
106
113 operator single_context();
114
115#if !defined(_MSC_VER) && !defined(__INTEL_COMPILER)
116 // TODO(MSVC): Causes an ICE under VS2015U1
117 static_assert(
118 std::is_same<value_context, decltype(std::declval<value_context>() << 1 << "str")>::value,
119 "value_context must be templatized on a key_context");
120#endif
121
122 private:
123 base unwrap() {
124 return base(_core);
125 }
126
127 array_context<base> wrap_array() {
128 return array_context<base>(_core);
129 }
130
131 key_context<base> wrap_document() {
132 return key_context<base>(_core);
133 }
134
135 core* _core;
136};
137
138} // namespace stream
139} // namespace builder
140} // namespace v_noabi
141} // namespace bsoncxx
142
144
Provides bsoncxx::v_noabi::builder::stream::array_context.
The bsoncxx v_noabi macro guard postlude header.
The bsoncxx v_noabi macro guard prelude header.
value_context(core *core)
Create a value_context given a core builder.
Definition value_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.
core & open_array()
Opens a sub-array within this BSON datum.
detail::requires_not_t< base, detail::is_invocable< T, single_context > > operator<<(T &&t)
<< operator for accepting a real value and appending it to the core builder.
Definition value_context.hpp:69
value_context(core *core)
Create a value_context given a core builder.
Definition value_context.hpp:59
Provides bsoncxx::v_noabi::builder::stream::closed_context.
Provides bsoncxx::v_noabi::builder::core.
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.
Provides stream manipulators for use with "streaming" BSON builder syntax.
For internal use only!
Declares bsoncxx::v_noabi::builder::stream::value_context.