TSDuck v3.40-3963
MPEG Transport Stream Toolkit
|
Implementation of a JSON string. More...
#include <tsjsonString.h>
Public Member Functions | |
String (const UString &value=UString()) | |
Constructor. | |
void | add (const UString &name, const UString &value) |
Add a string field into an object. | |
void | add (const UString &name, const ValuePtr &value) |
Add a field into an object. | |
template<typename T , typename std::enable_if< std::is_integral< T >::value, int >::type = 0> | |
void | add (const UString &name, T value) |
Add an integer number field into an object. | |
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, int >::type = 0> | |
void | add (const UString &name, T value) |
Add a floating-point number field into an object. | |
virtual Value & | at (size_t index) |
Get an element of an array (modifiable version). | |
virtual const Value & | at (size_t index) const |
Get an element of an array (const version). | |
virtual void | clear () override |
Clear the content of the value;. | |
virtual void | erase (size_t index, size_t count=1) |
Erase elements from an array. | |
virtual ValuePtr | extract (const UString &name) |
Extract a field from an object. | |
virtual ValuePtr | extractAt (size_t index) |
Extract an element from an array. | |
virtual void | getNames (UStringList &names) const |
Get all field names in an object. | |
virtual bool | isArray () const |
Check if this instance is a JSON array. | |
virtual bool | isFalse () const |
Check if this instance is a JSON false literal. | |
virtual bool | isInteger () const |
Check if this instance is a JSON number and an integer value (an integral value). | |
virtual bool | isNull () const |
Check if this instance is a JSON null literal. | |
virtual bool | isNumber () const |
Check if this instance is a JSON number. | |
virtual bool | isObject () const |
Check if this instance is a JSON object. | |
virtual bool | isString () const override |
Check if this instance is a JSON string. | |
virtual bool | isTrue () const |
Check if this instance is a JSON true literal. | |
virtual UString | oneLiner (Report &report=(ts::NullReport::Instance())) const |
Format the value as a one-liner JSON text. | |
virtual void | print (TextFormatter &output) const override |
Format the value as JSON text. | |
virtual UString | printed (size_t indent=2, Report &report=(ts::NullReport::Instance())) const |
Format the value as structured JSON text. | |
virtual const Value & | query (const UString &path) const |
Query a JSON value using a composite path. | |
virtual Value & | query (const UString &path, bool create=false, Type type=Type::Object) |
Query a JSON value using a composite path, creating intermediate objects when necessary. | |
virtual void | remove (const UString &name) |
Remove a field from an object. | |
virtual bool | save (const fs::path &fileName, size_t indent=2, bool stdOutputIfEmpty=false, Report &report=(ts::NullReport::Instance())) |
Save the value as a JSON file. | |
size_t | set (const UString &value, size_t index=std::numeric_limits< size_t >::max()) |
Set a string element of an array. | |
size_t | set (const ValuePtr &value, size_t index=std::numeric_limits< size_t >::max()) |
Set an element of an array. | |
template<typename T , typename std::enable_if< std::is_integral< T >::value, int >::type = 0> | |
size_t | set (T value, size_t index=std::numeric_limits< size_t >::max()) |
Set an integer number element of an array. | |
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, int >::type = 0> | |
size_t | set (T value, size_t index=std::numeric_limits< size_t >::max()) |
Set a floating-point number element of an array. | |
virtual size_t | size () const override |
Get the "size" of the value. | |
virtual bool | toBoolean (bool defaultValue=false) const override |
Convert this instance to a boolean. | |
virtual double | toFloat (double defaultValue=0.0) const override |
Convert this instance to a double-precision float. | |
virtual int64_t | toInteger (int64_t defaultValue=0) const override |
Convert this instance to an integer. | |
virtual UString | toString (const UString &defaultValue=UString()) const override |
Convert this instance to a string. | |
virtual Type | type () const override |
Get the JSON value type. | |
virtual const Value & | value (const UString &name) const |
Get the value of an object field (const version). | |
virtual Value & | value (const UString &name, bool create=false, Type type=Type::Object) |
Get the value of an object field (modifiable version). | |
virtual ValuePtr | valuePtr (const UString &name) |
Get the value of an object field (pointer version). | |
Protected Member Functions | |
virtual void | addFloat (const UString &name, double value) |
Add a double-precision floating-point number field into an object. | |
virtual void | addInteger (const UString &name, int64_t value) |
Add a 64-bit signed integer number field into an object. | |
virtual void | addString (const UString &name, const UString &value) |
Add a string field into an object. | |
virtual void | addValue (const UString &name, const ValuePtr &value) |
Add a field into an object. | |
virtual size_t | setFloat (double value, size_t index) |
Set a double-precision floating-point number element of an array. | |
virtual size_t | setInteger (int64_t value, size_t index) |
Set a 64-bit signed integer number element of an array. | |
virtual size_t | setString (const UString &value, size_t index) |
Set a string element of an array. | |
virtual size_t | setValue (const ValuePtr &value, size_t index) |
Set an element of an array. | |
Implementation of a JSON string.
Constructor.
[in] | value | Initial string value. |
Check if this instance is a JSON string.
Reimplemented from ts::json::Value.
|
overridevirtual |
Format the value as JSON text.
[in,out] | output | The output object to format. |
Implements ts::json::Value.
Convert this instance to a boolean.
[in] | defaultValue | Default value to return when no conversion is possible. |
Reimplemented from ts::json::Value.
Convert this instance to an integer.
[in] | defaultValue | Default value to return when no conversion is possible. |
Reimplemented from ts::json::Value.
Convert this instance to a double-precision float.
[in] | defaultValue | Default value to return when no conversion is possible. |
Reimplemented from ts::json::Value.
|
overridevirtual |
Convert this instance to a string.
[in] | defaultValue | Default value to return when no conversion is possible. |
Reimplemented from ts::json::Value.
Get the "size" of the value.
Reimplemented from ts::json::Value.
Clear the content of the value;.
Reimplemented from ts::json::Value.
|
virtualinherited |
Format the value as structured JSON text.
[in] | indent | Indentation width of each level. |
[in,out] | report | Where to report errors. |
|
virtualinherited |
Format the value as a one-liner JSON text.
[in,out] | report | Where to report errors. |
|
virtualinherited |
Save the value as a JSON file.
[in] | fileName | Name of the JSON file to save. |
[in] | indent | Indentation width of each level. |
[in] | stdOutputIfEmpty | If true and if fileName is empty or "-", writes to the standard output. |
[in,out] | report | Where to report errors. |
Check if this instance is a JSON null literal.
Reimplemented in ts::json::Null.
Check if this instance is a JSON true literal.
Reimplemented in ts::json::True.
Check if this instance is a JSON false literal.
Reimplemented in ts::json::False.
Check if this instance is a JSON number.
Reimplemented in ts::json::Number.
Check if this instance is a JSON number and an integer value (an integral value).
Reimplemented in ts::json::Number.
Check if this instance is a JSON object.
Reimplemented in ts::json::Object.
Check if this instance is a JSON array.
Reimplemented in ts::json::Array.
|
virtualinherited |
Get all field names in an object.
[out] | names | Receive the list of field names. |
Reimplemented in ts::json::Object.
Get the value of an object field (const version).
[in] | name | Field name. |
Reimplemented in ts::json::Object.
|
virtualinherited |
Get the value of an object field (modifiable version).
[in] | name | Field name. |
[in] | create | If true and the field does not exist, create it. |
[in] | type | When the field is created, provide the object type. |
Reimplemented in ts::json::Object.
Get the value of an object field (pointer version).
Must be a non-const object since we can potentially modify the field.
[in] | name | Field name. |
Reimplemented in ts::json::Object.
Extract a field from an object.
The field is removed but its previous content is returned.
[in] | name | Field name. |
Reimplemented in ts::json::Object.
Add a field into an object.
[in] | name | Field name. |
[in] | value | Smart pointer to a JSON value. The pointed object is shared. |
Add an integer number field into an object.
T | An integer type. |
[in] | name | Field name. |
[in] | value | Field value. |
Add a floating-point number field into an object.
T | A floating-point type. |
[in] | name | Field name. |
[in] | value | Field value. |
Add a string field into an object.
[in] | name | Field name. |
[in] | value | Field value. |
Get an element of an array (const version).
[in] | index | Index to fetch in the array. |
Reimplemented in ts::json::Array.
Get an element of an array (modifiable version).
[in] | index | Index to fetch in the array. |
Reimplemented in ts::json::Array.
|
inlineinherited |
Set an element of an array.
[in] | value | Smart pointer to a JSON value. The pointed object is shared. |
[in] | index | Index to fetch in the array. If out of bound, the value is added at the end of the array. |
|
inlineinherited |
Set an integer number element of an array.
T | An integer type. |
[in] | value | Value to set. |
[in] | index | Index in the array. If out of bound, the value is added at the end of the array. |
|
inlineinherited |
Set a floating-point number element of an array.
T | A floating-point type. |
[in] | value | Value to set. |
[in] | index | Index in the array. If out of bound, the value is added at the end of the array. |
|
inlineinherited |
Set a string element of an array.
[in] | value | Value to set. |
[in] | index | Index in the array. If out of bound, the value is added at the end of the array. |
Erase elements from an array.
[in] | index | Index to erase in the array. Ignored if out of bound. |
[in] | count | Number of elements to erase. |
Reimplemented in ts::json::Array.
Extract an element from an array.
The element is removed but its previous content is returned.
[in] | index | Index to erase in the array. Ignored if out of bound. |
Reimplemented in ts::json::Array.
Query a JSON value using a composite path.
[in] | path | Full path from this object to final object. May contain object field names and array indexes. Example: "obj1.arr[3].obj2". If this object is an array, the path must start with a index (example: "[3].obj2"). If the path is empty, this object is returned. |
Reimplemented in ts::json::Array, and ts::json::Object.
|
virtualinherited |
Query a JSON value using a composite path, creating intermediate objects when necessary.
[in] | path | Full path from this object to final object. May contain object field names and array indexes. Example: "obj1.arr[3].obj2". If this object is an array, the path must start with a index (example: "[3].obj2"). When an array index is empty and create is true, a new element is created at the end of the array (example: "obj1.arr[].obj2"). If the path is empty, this object is returned. |
[in] | create | If true create all missing intermediate objects. |
[in] | type | When the final field is created, provide the object type. |
Reimplemented in ts::json::Array, and ts::json::Object.
|
protectedvirtualinherited |
Add a field into an object.
[in] | name | Field name. |
[in] | value | Smart pointer to a JSON value. The pointed object is shared. |
Reimplemented in ts::json::Object.
|
protectedvirtualinherited |
Add a 64-bit signed integer number field into an object.
[in] | name | Field name. |
[in] | value | Field value. |
Reimplemented in ts::json::Object.
|
protectedvirtualinherited |
Add a double-precision floating-point number field into an object.
[in] | name | Field name. |
[in] | value | Field value. |
Reimplemented in ts::json::Object.
|
protectedvirtualinherited |
Add a string field into an object.
[in] | name | Field name. |
[in] | value | Field value. |
Reimplemented in ts::json::Object.
|
protectedvirtualinherited |
Set an element of an array.
[in] | value | Smart pointer to a JSON value. The pointed object is shared. |
[in] | index | Index to fetch in the array. If out of bound, the value is added at the end of the array. |
Reimplemented in ts::json::Array.
|
protectedvirtualinherited |
Set a 64-bit signed integer number element of an array.
[in] | value | Value to set. |
[in] | index | Index in the array. If out of bound, the value is added at the end of the array. |
Reimplemented in ts::json::Array.
Set a double-precision floating-point number element of an array.
[in] | value | Value to set. |
[in] | index | Index in the array. If out of bound, the value is added at the end of the array. |
Reimplemented in ts::json::Array.
|
protectedvirtualinherited |
Set a string element of an array.
[in] | value | Value to set. |
[in] | index | Index in the array. If out of bound, the value is added at the end of the array. |
Reimplemented in ts::json::Array.