#include <userver/formats/bson/value_builder.hpp>
Builder for BSON.
Class provides methods for building BSON. For read only access to the existing BSON values use formats::bson::Value.
Definition at line 39 of file value_builder.hpp.
Public Types | |
| using | iterator = Iterator<ValueBuilder> |
| using | Type = formats::common::Type |
Public Member Functions | |
| ValueBuilder () | |
Constructs a null value (may be used as either document or array) | |
| ValueBuilder (formats::common::Type type) | |
| Constructs a value with the predefined type. | |
| ValueBuilder (const ValueBuilder &other) | |
| ValueBuilder (ValueBuilder &&other) | |
| ValueBuilder & | operator= (const ValueBuilder &other) |
| ValueBuilder & | operator= (ValueBuilder &&other) |
| template<typename T> | |
| ValueBuilder (const T &t) | |
| Universal constructor using Serialize. | |
| ValueBuilder (common::TransferTag, ValueBuilder &&) noexcept | |
Transfers the ValueBuilder object. | |
| ValueBuilder | operator[] (const std::string &name) |
| Retrieves or creates document field by name. | |
| void | EmplaceNocheck (std::string_view key, ValueBuilder value) |
| Emplaces new member w/o a check whether the key already exists. | |
| template<typename Tag, utils::StrongTypedefOps Ops> requires (utils::IsStrongTypedefLoggable(Ops)) | |
| ValueBuilder | operator[] (const utils::StrongTypedef< Tag, std::string, Ops > &name) |
| Access member by key for modification. | |
| ValueBuilder | operator[] (uint32_t index) |
| Retrieves array element by index. | |
| void | Remove (const std::string &key) |
| Remove key from object. If key is missing nothing happens. | |
| iterator | begin () |
| Returns an iterator to the first array element/document field. | |
| iterator | end () |
| Returns an iterator following the last array element/document field. | |
| bool | IsEmpty () const |
| Returns whether the document/array is empty. | |
| bool | IsNull () const noexcept |
| Returns true if *this holds a Null (Type::kNull). | |
| bool | IsBool () const noexcept |
| Returns true if *this is convertible to bool. | |
| bool | IsInt () const noexcept |
| Returns true if *this is convertible to int. | |
| bool | IsInt64 () const noexcept |
| Returns true if *this is convertible to int64_t. | |
| bool | IsUInt64 () const noexcept |
| Returns true if *this is convertible to uint64_t. | |
| bool | IsDouble () const noexcept |
| Returns true if *this is convertible to double. | |
| bool | IsString () const noexcept |
| Returns true if *this is convertible to std::string. | |
| bool | IsArray () const noexcept |
| Returns true if *this is an array (Type::kArray). | |
| bool | IsObject () const noexcept |
| Returns true if *this holds a document (BSON_TYPE_DOCUMENT). | |
| uint32_t | GetSize () const |
| Returns the number of elements in a document/array. | |
| bool | HasMember (const std::string &name) const |
| Checks whether the document has a field. | |
| std::string | GetPath () const |
| Returns full path to this value. | |
| void | Resize (uint32_t size) |
| Creates or resizes the array. | |
| void | PushBack (ValueBuilder &&elem) |
| Appends an element to the array, possibly creating one. | |
| Value | ExtractValue () |
| Retrieves a compiled value from the builder. After calling this method the builder is in unspecified state. | |
| ValueBuilder (const Value &) | |
| ValueBuilder (const Document &) | |
| ValueBuilder (Value &&) | |
| ValueBuilder (Document &&) | |
Concrete type constructors | |
| ValueBuilder (std::nullptr_t) | |
| ValueBuilder (bool) | |
| ValueBuilder (int) | |
| ValueBuilder (unsigned int) | |
| ValueBuilder (long) | |
| ValueBuilder (unsigned long) | |
| ValueBuilder (long long) | |
| ValueBuilder (unsigned long long) | |
| ValueBuilder (double) | |
| ValueBuilder (const char *) | |
| ValueBuilder (char *) | |
| ValueBuilder (std::string) | |
| ValueBuilder (std::string_view) | |
| ValueBuilder (const std::chrono::system_clock::time_point &) | |
| ValueBuilder (const Oid &) | |
| ValueBuilder (Binary) | |
| ValueBuilder (const Decimal128 &) | |
| ValueBuilder (MinKey) | |
| ValueBuilder (MaxKey) | |
| ValueBuilder (const Timestamp &) | |
Definition at line 41 of file value_builder.hpp.
Definition at line 42 of file value_builder.hpp.
| formats::bson::ValueBuilder::ValueBuilder | ( | const Value & | ) |
Efficiently constructs a copy of an existing value
|
inline |
Universal constructor using Serialize.
Definition at line 98 of file value_builder.hpp.
|
noexcept |
Transfers the ValueBuilder object.
| iterator formats::bson::ValueBuilder::begin | ( | ) |
Returns an iterator to the first array element/document field.
| TypeMismatchException | if value is not a document, array or null |
| void formats::bson::ValueBuilder::EmplaceNocheck | ( | std::string_view | key, |
| ValueBuilder | value ) |
Emplaces new member w/o a check whether the key already exists.
| `TypeMismatchException` | if not object or null value. |
| iterator formats::bson::ValueBuilder::end | ( | ) |
Returns an iterator following the last array element/document field.
| TypeMismatchException | if value is not a document, array or null |
| uint32_t formats::bson::ValueBuilder::GetSize | ( | ) | const |
Returns the number of elements in a document/array.
| TypeMismatchException | if value is not a document, array or null |
null. | bool formats::bson::ValueBuilder::HasMember | ( | const std::string & | name | ) | const |
Checks whether the document has a field.
| name | field name |
| TypeMismatchExcepiton | if value is not a document or null |
| bool formats::bson::ValueBuilder::IsEmpty | ( | ) | const |
Returns whether the document/array is empty.
| TypeMismatchException | if value is not a document, array or null |
true for null. | ValueBuilder formats::bson::ValueBuilder::operator[] | ( | const std::string & | name | ) |
Retrieves or creates document field by name.
| TypeMismatchException | if value is not a document or null |
|
inline |
Access member by key for modification.
| `TypeMismatchException` | if not object or null value. |
Definition at line 119 of file value_builder.hpp.
| ValueBuilder formats::bson::ValueBuilder::operator[] | ( | uint32_t | index | ) |
Retrieves array element by index.
| TypeMismatchException | if value is not an array or null |
| OutOfBoundsException | if index is invalid for the array |
| void formats::bson::ValueBuilder::PushBack | ( | ValueBuilder && | elem | ) |
Appends an element to the array, possibly creating one.
| elem | element to append |
| TypeMismatchException | if value is not an array or null |
| void formats::bson::ValueBuilder::Remove | ( | const std::string & | key | ) |
Remove key from object. If key is missing nothing happens.
| `TypeMismatchException` | if value is not an object. |
| void formats::bson::ValueBuilder::Resize | ( | uint32_t | size | ) |
Creates or resizes the array.
| size | new size |
| TypeMismatchException | if value is not an array or null |