Toml Value¶
| Spice | |
|---|---|
TomlValue struct¶
Represents a single TOML value.
Composite values (arrays and tables) own their children as heap pointers, so a TomlValue is always reached via TomlValue* once it has been parsed. Destroying a value recursively destroys everything below it, so a whole tree is released with a single deleteTomlValue call on its root. Accessors like getField hand out borrowed pointers that stay owned by their parent, while addArrayItem and addTableField take ownership of what they are given.
Note that the root cannot simply be held in a heap TomlValue* and left to the compiler: the heap qualifier only emits a raw deallocation when the variable goes out of scope and never runs the destructor of the pointee, so the children below the root would be lost. Unlike JSON, TOML distinguishes integers from floats, so both are stored separately. Date-times are kept in their lexical form (e.g. 1979-05-27T07:32:00Z), which the parser validates and the serializer emits verbatim. Table entries preserve insertion order and TOML has no null value.
Parsing lives in "std/text/toml-parser" and serialization in "std/text/toml-serializer", so programs only pull in what they use.
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct an empty TOML table, which is what a TOML document is rooted at
ctor¶
| Spice | |
|---|---|
Construct an empty TOML value of the given kind. Useful for building arrays and tables from scratch.
Parameters
| Name | Type | Description |
|---|---|---|
kind |
TomlValueKind |
Kind of the value |
ctor¶
| Spice | |
|---|---|
Construct a TOML value that carries text, which is either a string or a date-time in its lexical form.
Parameters
| Name | Type | Description |
|---|---|---|
kind |
TomlValueKind |
Kind of the value - TOML_STRING or TOML_DATETIME |
value |
const String& |
Text payload |
ctor¶
| Spice | |
|---|---|
Construct a TOML boolean value
Parameters
| Name | Type | Description |
|---|---|---|
value |
bool |
Boolean value |
ctor¶
| Spice | |
|---|---|
Construct a TOML integer value
Parameters
| Name | Type | Description |
|---|---|---|
value |
long |
Integer value |
ctor¶
| Spice | |
|---|---|
Construct a TOML float value
Parameters
| Name | Type | Description |
|---|---|---|
value |
double |
Float value |
ctor¶
| Spice | |
|---|---|
Construct a TOML string value
Parameters
| Name | Type | Description |
|---|---|---|
value |
const String& |
String value |
dtor¶
| Spice | |
|---|---|
Destruct the TOML value, releasing every array item and table entry it owns. Since the children are destroyed the same way, this tears down the whole subtree below the value.
Methods¶
getKind¶
| Spice | |
|---|---|
Retrieve the kind of the TOML value
Returns: TomlValueKind — Kind of the value
isString¶
| Spice | |
|---|---|
Check whether the TOML value is a string
Returns: bool — true if the value is a string, false otherwise
isInteger¶
| Spice | |
|---|---|
Check whether the TOML value is an integer
Returns: bool — true if the value is an integer, false otherwise
isFloat¶
| Spice | |
|---|---|
Check whether the TOML value is a float
Returns: bool — true if the value is a float, false otherwise
isBool¶
| Spice | |
|---|---|
Check whether the TOML value is a boolean
Returns: bool — true if the value is a boolean, false otherwise
isDateTime¶
| Spice | |
|---|---|
Check whether the TOML value is a date-time
Returns: bool — true if the value is a date-time, false otherwise
isArray¶
| Spice | |
|---|---|
Check whether the TOML value is an array
Returns: bool — true if the value is an array, false otherwise
isTable¶
| Spice | |
|---|---|
Check whether the TOML value is a table
Returns: bool — true if the value is a table, false otherwise
getString¶
| Spice | |
|---|---|
Retrieve the string payload. Panics if the value is not a string.
Returns: const String& — String value
getInteger¶
| Spice | |
|---|---|
Retrieve the integer payload. Panics if the value is not an integer.
Returns: long — Integer value
getFloat¶
| Spice | |
|---|---|
Retrieve the float payload. Panics if the value is not a float.
Returns: double — Float value
getBool¶
| Spice | |
|---|---|
Retrieve the boolean payload. Panics if the value is not a boolean.
Returns: bool — Boolean value
getDateTime¶
| Spice | |
|---|---|
Retrieve the date-time payload in its lexical form. Panics if the value is not a date-time.
Returns: const String& — Date-time value
getArraySize¶
| Spice | |
|---|---|
Retrieve the number of items in the array. Panics if the value is not an array.
Returns: unsigned long — Number of array items
getArrayItem¶
| Spice | |
|---|---|
Retrieve the array item at the given index. Panics if the value is not an array.
Parameters
| Name | Type | Description |
|---|---|---|
idx |
unsigned long |
Index of the item |
Returns: TomlValue* — Pointer to the array item
getArrayItem¶
| Spice | |
|---|---|
Retrieve the array item at the given index. Panics if the value is not an array.
Parameters
| Name | Type | Description |
|---|---|---|
idx |
unsigned int |
Index of the item |
Returns: TomlValue* — Pointer to the array item
addArrayItem¶
| Spice | |
|---|---|
Append an item to the array. Panics if the value is not an array. The array takes ownership of the heap-allocated item.
Parameters
| Name | Type | Description |
|---|---|---|
item |
TomlValue* |
Item to append |
getTableSize¶
| Spice | |
|---|---|
Retrieve the number of entries in the table. Panics if the value is not a table.
Returns: unsigned long — Number of table entries
getTableKey¶
| Spice | |
|---|---|
Retrieve the key of the table entry at the given index, in insertion order. Panics if the value is not a table.
Parameters
| Name | Type | Description |
|---|---|---|
idx |
unsigned long |
Index of the entry |
Returns: const String& — Entry key
getTableValue¶
| Spice | |
|---|---|
Retrieve the value of the table entry at the given index, in insertion order. Panics if the value is not a table.
Parameters
| Name | Type | Description |
|---|---|---|
idx |
unsigned long |
Index of the entry |
Returns: TomlValue* — Pointer to the entry value
hasField¶
| Spice | |
|---|---|
Check whether the table contains an entry with the given key
Parameters
| Name | Type | Description |
|---|---|---|
key |
const String& |
Entry key to look for |
Returns: bool — true if the entry exists, false otherwise
hasField¶
| Spice | |
|---|---|
Check whether the table contains an entry with the given key
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
Entry key to look for |
Returns: bool — true if the entry exists, false otherwise
getFieldOrNil¶
| Spice | |
|---|---|
Retrieve the value of the table entry with the given key, or nil if the value is not a table or the entry does not exist.
Parameters
| Name | Type | Description |
|---|---|---|
key |
const String& |
Entry key to look up |
Returns: TomlValue* — Pointer to the entry value, or nil
getFieldOrNil¶
| Spice | |
|---|---|
Retrieve the value of the table entry with the given key, or nil if the value is not a table or the entry does not exist.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
Entry key to look up |
Returns: TomlValue* — Pointer to the entry value, or nil
getField¶
| Spice | |
|---|---|
Retrieve the value of the table entry with the given key. Panics if the value is not a table or the entry does not exist.
Parameters
| Name | Type | Description |
|---|---|---|
key |
const String& |
Entry key to look up |
Returns: TomlValue* — Pointer to the entry value
getField¶
| Spice | |
|---|---|
Retrieve the value of the table entry with the given key. Panics if the value is not a table or the entry does not exist.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
Entry key to look up |
Returns: TomlValue* — Pointer to the entry value
addTableField¶
| Spice | |
|---|---|
Append an entry to the table. Panics if the value is not a table. The table takes ownership of the heap-allocated entry value.
Parameters
| Name | Type | Description |
|---|---|---|
key |
const String& |
Entry key |
value |
TomlValue* |
Entry value |
Functions¶
deleteTomlValue¶
| Spice | |
|---|---|
Destroys a heap-allocated TOML value together with everything it owns and sets the given handle to nil, so releasing a whole tree only takes one call on its root.
Note that this is what sDelete would normally be used for. It cannot be used here, because a value tree is destroyed recursively and the compiler does not emit an explicit dtor that is only reached through sDestruct.
Parameters
| Name | Type | Description |
|---|---|---|
value |
TomlValue*& |
Handle of the value to destroy |
tomlInfinity¶
| Spice | |
|---|---|
Retrieve positive infinity, which TOML spells inf. Spice has no literal for it, so it is provided here for building and inspecting float values.
Returns: double — Positive infinity
tomlNaN¶
| Spice | |
|---|---|
Retrieve a quiet NaN, which TOML spells nan. Spice has no literal for it, so it is provided here for building float values.
Returns: double — Not a number
tomlIsNaN¶
| Spice | |
|---|---|
Checks whether the given float is a NaN. The usual value != value trick does not work in Spice, since its float comparisons are ordered ones.
Parameters
| Name | Type | Description |
|---|---|---|
value |
double |
Float value to check |
Returns: bool — true if the value is a NaN, false otherwise
TomlValueKind enum¶
Tag for the variant stored inside a TomlValue.
| Item | Value | Description |
|---|---|---|
TOML_STRING |
||
TOML_INTEGER |
||
TOML_FLOAT |
||
TOML_BOOL |
||
TOML_DATETIME |
||
TOML_ARRAY |
||
TOML_TABLE |