rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches

Implementation of serialization to a tree. More...

Topics

 Arena utils
 Implementation utils for serializing scalars in a tree's arena.

Functions

template<class T>
type_bits c4::yml::scalar_flags_val (T const &) noexcept
 Return extra style flags to use when setting a scalar as val.
template<class T>
type_bits c4::yml::scalar_flags_key (T const &) noexcept
 Return extra style flags to use when setting a scalar as key.
template<class T>
void c4::yml::write (Tree *tree, id_type id, T const &v)
 Serialize a variable to the tree's arena, and set it as the node's val.
template<class T>
void c4::yml::write_key (Tree *tree, id_type id, T const &v)
 Serialize a variable to the tree's arena, and set it as the node's key.

Detailed Description

Implementation of serialization to a tree.

Function Documentation

◆ scalar_flags_val()

template<class T>
type_bits c4::yml::scalar_flags_val ( T const & )
inlinenoexcept

Return extra style flags to use when setting a scalar as val.

Defaults to VAL_PLAIN for arithmetic types, or NOTYPE otherwise

Definition at line 1785 of file tree.hpp.

1786{
1787 if constexpr (std::is_arithmetic_v<T>)
1788 return VAL_PLAIN;
1789 else
1790 return NOTYPE;
1791}
@ NOTYPE
no node type or style is set
Definition node_type.hpp:32
@ VAL_PLAIN
mark val scalar as plain scalar (unquoted, even when multiline)

Referenced by scalar_flags_val(), and write().

◆ scalar_flags_key()

template<class T>
type_bits c4::yml::scalar_flags_key ( T const & )
inlinenoexcept

Return extra style flags to use when setting a scalar as key.

Defaults to KEY_PLAIN for arithmetic types, or NOTYPE otherwise

Definition at line 1795 of file tree.hpp.

1796{
1797 if constexpr (std::is_arithmetic_v<T>)
1798 return KEY_PLAIN;
1799 else
1800 return NOTYPE;
1801}
@ KEY_PLAIN
mark key scalar as plain scalar (unquoted, even when multiline)

Referenced by scalar_flags_key(), and write_key().

◆ write()

template<class T>
void c4::yml::write ( Tree * tree,
id_type id,
T const & v )
inline

Serialize a variable to the tree's arena, and set it as the node's val.

Definition at line 1838 of file tree.hpp.

1839{
1840 tree->set_val(id, serialize_to_arena(tree, v), scalar_flags_val(v));
1841}
void set_val(id_type node, csubstr val) RYML_NOEXCEPT
Definition tree.hpp:688
csubstr serialize_to_arena(Tree *tree, T const &scalar)
Serialize a scalar to a tree's arena, dispatching to either serialize_to_arena_scalar() or serialize_...
Definition tree.hpp:109
type_bits scalar_flags_val(T const &) noexcept
Return extra style flags to use when setting a scalar as val.
Definition tree.hpp:1785

◆ write_key()

template<class T>
void c4::yml::write_key ( Tree * tree,
id_type id,
T const & v )
inline

Serialize a variable to the tree's arena, and set it as the node's key.

Warning
The key MUST be a scalar value. The tree cannot handle container keys.

Definition at line 1848 of file tree.hpp.

1849{
1850 tree->set_key(id, serialize_to_arena(tree, v), scalar_flags_key(v));
1851}
void set_key(id_type node, csubstr key) RYML_NOEXCEPT
Definition tree.hpp:705
type_bits scalar_flags_key(T const &) noexcept
Return extra style flags to use when setting a scalar as key.
Definition tree.hpp:1795