Loading...
Searching...
No Matches
value_context.hpp
Go to the documentation of this file.
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <bsoncxx/builder/stream/value_context-fwd.hpp> // IWYU pragma: export
#include <bsoncxx/builder/core.hpp>
#include <bsoncxx/builder/stream/array_context.hpp>
#include <bsoncxx/builder/stream/closed_context.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/builder/stream/helpers.hpp>
#include <bsoncxx/stdx/type_traits.hpp>
#include <bsoncxx/config/prelude.hpp>
namespace bsoncxx {
namespace v_noabi {
namespace builder {
namespace stream {
template <class base>
class value_context {
public:
value_context(core* core) : _core(core) {}
template <class T>
detail::requires_not_t<base, detail::is_invocable<T, single_context>> operator<<(T&& t) {
_core->append(std::forward<T>(t));
return unwrap();
}
template <typename T>
detail::requires_t<base, detail::is_invocable<T, single_context>> operator<<(T&& func) {
detail::invoke(std::forward<T>(func), *this);
return unwrap();
}
key_context<base> operator<<(open_document_type const) {
_core->open_document();
return wrap_document();
}
array_context<base> operator<<(open_array_type const) {
_core->open_array();
return wrap_array();
}
operator single_context();
#if !defined(_MSC_VER) && !defined(__INTEL_COMPILER)
// TODO(MSVC): Causes an ICE under VS2015U1
static_assert(
std::is_same<value_context, decltype(std::declval<value_context>() << 1 << "str")>::value,
"value_context must be templatized on a key_context");
#endif
private:
base unwrap() {
return base(_core);
}
array_context<base> wrap_array() {
return array_context<base>(_core);
}
key_context<base> wrap_document() {
return key_context<base>(_core);
}
core* _core;
};
} // namespace stream
} // namespace builder
} // namespace v_noabi
} // namespace bsoncxx
#include <bsoncxx/config/postlude.hpp>
array_context.hpp
Provides bsoncxx::v_noabi::builder::stream::array_context.
postlude.hpp
The bsoncxx v_noabi macro guard postlude header.
prelude.hpp
The bsoncxx v_noabi macro guard prelude header.
bsoncxx::builder::stream::value_context::value_context
value_context(core *core)
Create a value_context given a core builder.
Definition value_context.hpp:59
bsoncxx::v_noabi::builder::core
A low-level interface for constructing BSON documents and arrays.
Definition core.hpp:46
bsoncxx::v_noabi::builder::core::append
core & append(types::b_double const &value)
Appends a BSON double.
bsoncxx::v_noabi::builder::core::open_document
core & open_document()
Opens a sub-document within this BSON datum.
bsoncxx::v_noabi::builder::core::open_array
core & open_array()
Opens a sub-array within this BSON datum.
bsoncxx::v_noabi::builder::stream::value_context::operator<<
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
bsoncxx::v_noabi::builder::stream::value_context::value_context
value_context(core *core)
Create a value_context given a core builder.
Definition value_context.hpp:59
closed_context.hpp
Provides bsoncxx::v_noabi::builder::stream::closed_context.
core.hpp
Provides bsoncxx::v_noabi::builder::core.
bsoncxx::v_noabi::builder::stream
Declares entities used with "streaming" BSON builder syntax.
bsoncxx::v_noabi::builder
Declares entities used to build BSON documents.
bsoncxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
bsoncxx
The top-level namespace within which all bsoncxx library entities are declared.
helpers.hpp
Provides stream manipulators for use with "streaming" BSON builder syntax.
type_traits.hpp
For internal use only!
value_context-fwd.hpp
Declares bsoncxx::v_noabi::builder::stream::value_context.