MongoDB C++ Driver mongocxx-3.0.0
Loading...
Searching...
No Matches
single_context.hpp
1// Copyright 2014 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/core.hpp>
18#include <bsoncxx/builder/stream/array_context.hpp>
19#include <bsoncxx/builder/stream/value_context.hpp>
20#include <bsoncxx/builder/stream/key_context.hpp>
21
22#include <bsoncxx/config/prelude.hpp>
23
24namespace bsoncxx {
25BSONCXX_INLINE_NAMESPACE_BEGIN
26namespace builder {
27namespace stream {
28
37 public:
38
45 BSONCXX_INLINE single_context(core* core) : _core(core) {
46 }
47
55 _core->open_document();
56
57 return wrap_document();
58 }
59
66 BSONCXX_INLINE array_context<single_context> operator<<(open_array_type) {
67 _core->open_array();
68
69 return wrap_array();
70 }
71
79 template <class T>
80 BSONCXX_INLINE void operator<<(T&& t) {
81 _core->append(std::forward<T>(t));
82 }
83
84 private:
85 BSONCXX_INLINE array_context<single_context> wrap_array() {
87 }
88
89 BSONCXX_INLINE key_context<single_context> wrap_document() {
90 return key_context<single_context>(_core);
91 }
92
93 core* _core;
94};
95
99template <class T>
101 return single_context(_core);
102}
103
107template <class T>
109 return single_context(_core);
110}
111
112} // namespace stream
113} // namespace builder
114BSONCXX_INLINE_NAMESPACE_END
115} // namespace bsoncxx
116
117#include <bsoncxx/config/postlude.hpp>
A low-level interface for constructing BSON documents and arrays.
Definition core.hpp:42
void open_document()
Opens a sub-document within this BSON datum.
void append(const types::b_double &value)
Append a BSON double.
void open_array()
Opens a sub-array within this BSON datum.
A stream context which expects any number of values.
Definition array_context.hpp:52
A stream context which expects a key, which can later be followed by value, then more key/value pairs...
Definition key_context.hpp:48
A stream context which appends a single value.
Definition single_context.hpp:36
void operator<<(T &&t)
<< operator for accepting a real value and appending it to the core builder.
Definition single_context.hpp:80
key_context< single_context > operator<<(open_document_type)
<< operator for opening a new subdocument in the core builder.
Definition single_context.hpp:54
A stream context which expects a value, which can later be followed by more key/value pairs.
Definition value_context.hpp:48