new FValue(valueopt, parseopt, sort_namesopt)
- Description:
Implements a minimal C/C++ JSON dynamic data structure.
Extends: Value. This class extends Value, with all public methods available.
- Such a FValue has the capability to define computed attributes.
- Value functions, beyond Value functions
- Element access:
value.at(name)
allows to access a static or computed value.
- Modifiers:
value.set(name, Value& (*getter)(const Value&))
allows to define a value calculation via a function.
- Element access:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value |
string | bool | int | uint | double | float | JSON |
<optional> |
The initial value. |
|
parse |
bool |
<optional> |
false
|
For a string value, if true parses the string, else only copy it. |
sort_names |
bool |
<optional> |
false
|
For a parsed string value, if true sorts the names in alphabetic order, as performed by Value::sortNames(). |
Methods
set(name, getter, cacheopt) → {Value}
- Description:
Sets the calculation of a given field of this structure.
- Setting a value:
// Defines calculations for a given field class DynamicFields { public: static wjson::Value sqrt_x(const wjson::Value& value) { return (int) sqrt(value.get("x", 0)); } }; // Sets sqrt_x as a dynamic calculated field fvalue.set("sqrt_x", DynamicFields::sqrt_x); // Gets the calculation result double sqrt_x = fvalue.get("sqrt_x", 0);
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
string | The field name |
||
getter |
function | A static method of type |
||
cache |
bool |
<optional> |
true
|
If true, memorizes the last calculated value in the static |
Returns:
This value allowing to chain set methods.
- Type
- Value