Loading...
Searching...
No Matches
key_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/closed_context-fwd.hpp>
#include <bsoncxx/builder/stream/key_context-fwd.hpp> // IWYU pragma: export
#include <bsoncxx/builder/core.hpp>
#include <bsoncxx/builder/stream/value_context.hpp>
#include <bsoncxx/stdx/string_view.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 key_context {
public:
key_context(core* core) : _core(core) {}
template <std::size_t n>
value_context<key_context> operator<<(char const (&v)[n]) {
_core->key_view(stdx::string_view{v, n - 1});
return value_context<key_context>(_core);
}
value_context<key_context> operator<<(std::string str) {
_core->key_owned(std::move(str));
return value_context<key_context>(_core);
}
value_context<key_context> operator<<(stdx::string_view str) {
_core->key_view(std::move(str));
return value_context<key_context>(_core);
}
template <typename T>
detail::requires_t<key_context&, detail::is_invocable<T, key_context>> operator<<(T&& func) {
detail::invoke(std::forward<T>(func), *this);
return *this;
}
template <typename T>
detail::requires_t<v_noabi::document::value, std::is_same<base, closed_context>, detail::is_alike<T, finalize_type>>
operator<<(T&&) {
return _core->extract_document();
}
key_context operator<<(concatenate_doc doc) {
_core->concatenate(doc);
return *this;
}
base operator<<(close_document_type const) {
_core->close_document();
return unwrap();
}
operator key_context<>() {
return key_context<>(_core);
}
private:
base unwrap() {
return base(_core);
}
core* _core;
};
} // namespace stream
} // namespace builder
} // namespace v_noabi
} // namespace bsoncxx
#include <bsoncxx/config/postlude.hpp>
postlude.hpp
The bsoncxx v_noabi macro guard postlude header.
prelude.hpp
The bsoncxx v_noabi macro guard prelude header.
bsoncxx::builder::stream::key_context::key_context
key_context(core *core)
Create a key_context given a core builder.
Definition key_context.hpp:59
bsoncxx::v1::stdx::string_view
A polyfill for std::string_view.
Definition string_view.hpp:412
bsoncxx::v_noabi::builder::core
A low-level interface for constructing BSON documents and arrays.
Definition core.hpp:46
bsoncxx::v_noabi::builder::core::key_owned
core & key_owned(std::string key)
Appends a key passed as an STL string. Transfers ownership of the key to this class.
bsoncxx::v_noabi::builder::core::key_view
core & key_view(stdx::string_view key)
Appends a key passed as a non-owning stdx::string_view.
bsoncxx::v_noabi::builder::stream::key_context<>
bsoncxx::v_noabi::builder::stream::key_context::operator<<
key_context operator<<(concatenate_doc doc)
<< operator for concatenating another document.
Definition key_context.hpp:146
bsoncxx::v_noabi::builder::stream::key_context::operator<<
value_context< key_context > operator<<(char const (&v)[n])
<< operator for accepting a literal key and appending it to the core builder.
Definition key_context.hpp:72
bsoncxx::v_noabi::builder::stream::key_context::operator<<
base operator<<(close_document_type const)
<< operator for closing a subdocument in the core builder.
Definition key_context.hpp:156
bsoncxx::v_noabi::builder::stream::key_context::key_context
key_context(core *core)
Create a key_context given a core builder.
Definition key_context.hpp:59
bsoncxx::v_noabi::builder::stream::value_context
A stream context which expects a value.
Definition value_context.hpp:51
closed_context-fwd.hpp
Declares bsoncxx::v_noabi::builder::stream::closed_context.
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.
bsoncxx::v_noabi::builder::concatenate_doc
Container to concatenate a document.
Definition concatenate.hpp:34
bsoncxx::v_noabi::builder::stream::close_document_type
The type of a stream manipulator to close a subdocument.
Definition helpers.hpp:41
string_view.hpp
Provides std::string_view-related polyfills for library API usage.
type_traits.hpp
For internal use only!
value_context.hpp
Provides bsoncxx::v_noabi::builder::stream::value_context.