37 using initializer_list_t = std::initializer_list<list>;
57 list(T value) : val{value} {}
79 list(initializer_list_t init) :
list(init, true, true) {}
104 friend ::bsoncxx::v_noabi::builder::document;
105 friend ::bsoncxx::v_noabi::builder::array;
107 list(initializer_list_t init,
bool type_deduction,
bool is_array) : val{nullptr} {
108 std::stringstream err_msg{
"cannot construct document"};
109 bool valid_document =
false;
110 if (type_deduction || !is_array) {
111 valid_document = [&] {
112 if (init.size() % 2 != 0) {
113 err_msg <<
" : must be list of key-value pairs";
116 for (
size_t i = 0; i < init.size(); i += 2) {
117 auto t = (begin(init) + i)->val.
view().
type();
119 err_msg <<
" : all keys must be string type. ";
120 err_msg <<
"Found type=" <<
to_string(t);
128 if (valid_document) {
130 for (
size_t i = 0; i < init.size(); i += 2) {
131 _core.key_owned(std::string((begin(init) + i)->val.
view().
get_string().value));
132 _core.append((begin(init) + i + 1)->val);
134 val = types::bson_value::value(_core.extract_document());
135 }
else if (type_deduction || is_array) {
137 for (
auto&& ele : init)
138 _core.append(ele.val);
139 val = types::bson_value::value(_core.extract_array());
151 using initializer_list_t = std::initializer_list<list>;
176 using initializer_list_t = std::initializer_list<list>;
194 array(initializer_list_t init) :
list(init, false, true) {}
Declares bsoncxx::v_noabi::builder::basic::array.
The bsoncxx macro guard postlude header.
The bsoncxx macro guard prelude header.
Provides bsoncxx::v_noabi::error_code.
Provides bsoncxx::v_noabi::exception.
A JSON-like builder for creating arrays.
Definition list.hpp:175
array(initializer_list_t init)
Creates a BSON array.
Definition list.hpp:194
array()
Creates an empty array.
Definition list.hpp:182
A JSON-like builder for creating documents.
Definition list.hpp:150
document(initializer_list_t init)
Creates a BSON document.
Definition list.hpp:169
document()
Creates an empty document.
Definition list.hpp:157
A JSON-like builder for creating documents and arrays.
Definition list.hpp:36
types::bson_value::view view()
Provides a view of the underlying BSON value.
Definition list.hpp:97
list(T value)
Creates a bsoncxx::v_noabi::builder::list from a value of type T. T must be a bsoncxx::v_noabi::types...
Definition list.hpp:57
operator types::bson_value::view()
Provides a view of the underlying BSON value.
Definition list.hpp:87
list()
Creates an empty document.
Definition list.hpp:43
list(initializer_list_t init)
Creates a BSON document, if possible. Otherwise, it will create a BSON array. A document is possible ...
Definition list.hpp:79
Class representing any exceptions emitted from the bsoncxx library or its underlying implementation.
Definition exception.hpp:34
A variant owning type that represents any BSON type. Owns its underlying buffer. When a bson_value::v...
Definition value.hpp:47
bson_value::view view() const noexcept
Get a view over the bson_value owned by this object.
A view-only variant that can contain any BSON type.
Definition view.hpp:54
bsoncxx::v_noabi::type type() const
Returns the type of the underlying BSON value stored in this object.
const b_string & get_string() const
Returns the underlying BSON UTF-8 string value.
Provides bsoncxx::v_noabi::builder::core.
Provides entities for use with "list" BSON builder syntax.
@ k_unmatched_key_in_builder
Attempted to view or extract a document when a key was still awaiting a matching value.
std::string to_string(type rhs)
Returns a stringification of the given type.
The top-level namespace within which all bsoncxx library entities are declared.
Provides bsoncxx::v_noabi::types::bson_value::value.