#include <userver/formats/json/value_builder.hpp>
Builder for JSON.
Class provides methods for building JSON. For read only access to the existing JSON values use formats::json::Value.
Definition at line 41 of file value_builder.hpp.
Classes | |
struct | IterTraits |
Public Types | |
using | iterator = Iterator<IterTraits> |
Public Member Functions | |
ValueBuilder ()=default | |
Constructs a ValueBuilder that holds kNull. | |
ValueBuilder (formats::common::Type type) | |
Constructs a valueBuilder that holds default value for provided type . | |
ValueBuilder (common::TransferTag, ValueBuilder &&) noexcept | |
Transfers the ValueBuilder object. | |
ValueBuilder (const ValueBuilder &other) | |
ValueBuilder (ValueBuilder &&other) | |
ValueBuilder & | operator= (const ValueBuilder &other) |
ValueBuilder & | operator= (ValueBuilder &&other) |
ValueBuilder (const formats::json::Value &other) | |
ValueBuilder (formats::json::Value &&other) | |
template<typename T > | |
ValueBuilder (const T &t) | |
Universal constructor using Serialize. | |
ValueBuilder | operator[] (std::string key) |
Access member by key for modification. | |
ValueBuilder | operator[] (std::size_t index) |
Access array member by index for modification. | |
template<typename Tag , utils::StrongTypedefOps Ops, typename Enable = std::enable_if_t<utils::IsStrongTypedefLoggable(Ops)>> | |
ValueBuilder | operator[] (utils::StrongTypedef< Tag, std::string, Ops > key) |
Access member by key for modification. | |
void | EmplaceNocheck (std::string_view key, ValueBuilder value) |
Emplaces new member w/o a check whether the key already exists. | |
void | Remove (std::string_view key) |
Remove key from object. If key is missing nothing happens. | |
iterator | begin () |
iterator | end () |
bool | IsEmpty () const |
Returns whether the array or object 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 map (Type::kObject). | |
std::size_t | GetSize () const |
Returns array size or object members count. | |
bool | HasMember (std::string_view key) const |
Returns true if value holds a key . | |
std::string | GetPath () const |
Returns full path to this value. | |
void | Resize (std::size_t size) |
Resize the array value or convert null value into an array of requested size. | |
void | PushBack (ValueBuilder &&bld) |
Add element into the last position of array. | |
formats::json::Value | ExtractValue () |
Take out the resulting Value object. After calling this method the object is in unspecified (but valid - possibly null) state. | |
Concrete type constructors | |
ValueBuilder (std::nullptr_t) | |
ValueBuilder (bool t) | |
ValueBuilder (const char *str) | |
ValueBuilder (char *str) | |
ValueBuilder (const std::string &str) | |
ValueBuilder (std::string_view str) | |
ValueBuilder (int t) | |
ValueBuilder (unsigned int t) | |
ValueBuilder (uint64_t t) | |
ValueBuilder (int64_t t) | |
ValueBuilder (float t) | |
ValueBuilder (double t) | |
Definition at line 50 of file value_builder.hpp.
|
noexcept |
Transfers the ValueBuilder
object.
|
inline |
Definition at line 74 of file value_builder.hpp.
Universal constructor using Serialize.
Definition at line 90 of file value_builder.hpp.
void formats::json::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. |
formats::json::Value formats::json::ValueBuilder::ExtractValue | ( | ) |
Take out the resulting Value
object. After calling this method the object is in unspecified (but valid - possibly null) state.
`JsonException` | if called not from the root builder. |
std::size_t formats::json::ValueBuilder::GetSize | ( | ) | const |
Returns array size or object members count.
`TypeMismatchException` | if not an array or an object. |
bool formats::json::ValueBuilder::HasMember | ( | std::string_view | key | ) | const |
Returns true if value holds a key
.
`TypeMismatchException` | if *this is not a map or null. |
bool formats::json::ValueBuilder::IsEmpty | ( | ) | const |
Returns whether the array or object is empty.
`TypeMismatchException` | if not an array or an object. |
ValueBuilder formats::json::ValueBuilder::operator[] | ( | std::size_t | index | ) |
Access array member by index for modification.
`TypeMismatchException` | if not an array value. |
`OutOfBoundsException` | if index is greater than size. |
ValueBuilder formats::json::ValueBuilder::operator[] | ( | std::string | key | ) |
Access member by key for modification.
`TypeMismatchException` | if not object or null value. |
ValueBuilder formats::json::ValueBuilder::operator[] | ( | utils::StrongTypedef< Tag, std::string, Ops > | key | ) |
Access member by key for modification.
`TypeMismatchException` | if not object or null value. |
Definition at line 229 of file value_builder.hpp.
void formats::json::ValueBuilder::PushBack | ( | ValueBuilder && | bld | ) |
Add element into the last position of array.
`TypeMismatchException` | if not an array or null. |
void formats::json::ValueBuilder::Remove | ( | std::string_view | key | ) |
Remove key from object. If key is missing nothing happens.
`TypeMismatchException` | if value is not an object. |
void formats::json::ValueBuilder::Resize | ( | std::size_t | size | ) |
Resize the array value or convert null value into an array of requested size.
`TypeMismatchException` | if not an array or null. |
|
friend |
Definition at line 196 of file value_builder.hpp.
|
friend |
Definition at line 196 of file value_builder.hpp.