Loading...
Searching...
No Matches
array_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/array_context-fwd.hpp> // IWYU pragma: export
#include <bsoncxx/builder/stream/key_context-fwd.hpp>
#include <bsoncxx/builder/stream/single_context-fwd.hpp>
#include <bsoncxx/array/value.hpp>
#include <bsoncxx/builder/concatenate.hpp>
#include <bsoncxx/builder/core.hpp>
#include <bsoncxx/builder/stream/closed_context.hpp>
#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 array_context {
public:
array_context(core* core) : _core(core) {}
template <class T>
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) {
_core->append(std::forward<T>(t));
return *this;
}
template <typename Func>
detail::requires_t<
array_context&,
detail::disjunction<detail::is_invocable<Func, array_context>, detail::is_invocable<Func, single_context>>>
operator<<(Func&& func) {
detail::invoke(std::forward<Func>(func), *this);
return *this;
}
template <typename T>
detail::requires_t<v_noabi::array::value, std::is_same<base, closed_context>, detail::is_alike<T, finalize_type>>
// VS2015U1 can't resolve the name.
operator<<(T&&) {
return _core->extract_array();
}
key_context<array_context> operator<<(open_document_type const) {
_core->open_document();
return wrap_document();
}
array_context operator<<(concatenate_array array) {
_core->concatenate(array.view());
return *this;
}
array_context<array_context> operator<<(open_array_type const) {
_core->open_array();
return wrap_array();
}
base operator<<(close_array_type const) {
_core->close_array();
return unwrap();
}
operator array_context<>() {
return array_context<>(_core);
}
operator single_context();
private:
base unwrap() {
return base(_core);
}
array_context<array_context> wrap_array() {
return array_context<array_context>(_core);
}
key_context<array_context> wrap_document() {
return key_context<array_context>(_core);
}
core* _core;
};
} // namespace stream
} // namespace builder
} // namespace v_noabi
} // namespace bsoncxx
#include <bsoncxx/config/postlude.hpp>
array_context-fwd.hpp
Declares 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::array_context::array_context
array_context(core *core)
Create an array_context given a core builder.
Definition array_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::extract_array
v_noabi::array::value extract_array()
Transfers ownership of the underlying document to the caller.
bsoncxx::v_noabi::builder::core::open_array
core & open_array()
Opens a sub-array within this BSON datum.
bsoncxx::v_noabi::builder::stream::array_context
A stream context which expects any number of values.
Definition array_context.hpp:51
bsoncxx::v_noabi::builder::stream::array_context::operator<<
array_context operator<<(concatenate_array array)
<< operator for concatenating another array.
Definition array_context.hpp:132
bsoncxx::v_noabi::builder::stream::array_context::operator<<
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
bsoncxx::v_noabi::builder::stream::array_context::operator<<
base operator<<(close_array_type const)
<< operator for closing a subarray in the core builder.
Definition array_context.hpp:152
bsoncxx::v_noabi::builder::stream::array_context::array_context
array_context(core *core)
Create an array_context given a core builder.
Definition array_context.hpp:59
bsoncxx::v_noabi::builder::stream::array
A streaming interface for constructing a BSON array.
Definition array.hpp:42
bsoncxx::v_noabi::builder::stream::array::view
v_noabi::array::view view() const
Definition array.hpp:52
bsoncxx::v_noabi::builder::stream::single_context
A stream context which appends a single value.
Definition single_context.hpp:38
closed_context.hpp
Provides bsoncxx::v_noabi::builder::stream::closed_context.
concatenate.hpp
Provides concatenators for use with "streaming" BSON builder syntax.
core.hpp
Provides bsoncxx::v_noabi::builder::core.
key_context-fwd.hpp
Declares bsoncxx::v_noabi::builder::stream::key_context.
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.
single_context-fwd.hpp
Declares bsoncxx::v_noabi::builder::stream::single_context.
helpers.hpp
Provides stream manipulators for use with "streaming" BSON builder syntax.
bsoncxx::v_noabi::builder::concatenate_array
Container to concatenate an array.
Definition concatenate.hpp:64
bsoncxx::v_noabi::builder::stream::close_array_type
The type of a stream manipulator to close a subarray.
Definition helpers.hpp:68
bsoncxx::v_noabi::builder::stream::open_array_type
The type of a stream manipulator to open a subarray.
Definition helpers.hpp:53
value.hpp
Provides bsoncxx::v_noabi::array::value.
type_traits.hpp
For internal use only!