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

Implementation of deserialization from a tree. More...

Functions

template<class T>
ReadResult c4::yml::read (Tree const *tree, id_type id, T *v)
 Deserialize a scalar node's val from a tree object, returning false if the conversion failed.
template<class Wrapper>
ReadResult c4::yml::read (Tree const *tree, id_type id, Wrapper const &w)
 overload to enable use of wrapper tag-types like eg c4::fmt::base64()
template<class T>
ReadResult c4::yml::read_key (Tree const *tree, id_type id, T *v)
 Deserialize a node's key from a tree object, returning false if the conversion failed.
template<class Wrapper>
ReadResult c4::yml::read_key (Tree const *tree, id_type id, Wrapper const &w)
 overload to enable use of wrapper tag-types like eg c4::fmt::base64()

Detailed Description

Implementation of deserialization from a tree.

Function Documentation

◆ read() [1/2]

template<class T>
ReadResult c4::yml::read ( Tree const * tree,
id_type id,
T * v )
inline

Deserialize a scalar node's val from a tree object, returning false if the conversion failed.

Returns
false if the conversion failed
See also
scalar_deserialize()
the counterpart function read_key()

Definition at line 1871 of file tree.hpp.

1872{
1873 // caller only checks that type is one of VAL|MAP|SEQ (because it
1874 // can't be more concrete than that). Here, we expect a VAL so now
1875 // we can check for that:
1876 NodeData const* C4_RESTRICT nd = tree->_p(id);
1877 return ReadResult((nd->m_type & VAL) && scalar_deserialize(nd->m_val.scalar, v), id);
1878}
@ VAL
a scalar: has a scalar (ie string) value, possibly empty. must be a leaf node, and cannot be MAP or S...
Definition node_type.hpp:34
bool scalar_deserialize(csubstr str, T *val)
Deserialize a scalar from its string representation, dispatching to one of from_chars(),...
contains the data for each YAML node.
Definition tree.hpp:288
A lightweight truthy type, used to enable reporting the offending node when a deserializing error hap...
Definition common.hpp:162

◆ read() [2/2]

template<class Wrapper>
ReadResult c4::yml::read ( Tree const * tree,
id_type id,
Wrapper const & w )
inline

overload to enable use of wrapper tag-types like eg c4::fmt::base64()

Definition at line 1882 of file tree.hpp.

1883{
1884 // caller only checks that type is one of VAL|MAP|SEQ (because it
1885 // can't be more concrete than that). Here, we expect a VAL so now
1886 // we can check for that:
1887 NodeData const* C4_RESTRICT nd = tree->_p(id);
1888 return ReadResult((nd->m_type & VAL) && from_chars(nd->m_val.scalar, w), id);
1889}
bool from_chars(csubstr buf, uint8_t *v) noexcept

◆ read_key() [1/2]

template<class T>
ReadResult c4::yml::read_key ( Tree const * tree,
id_type id,
T * v )
inline

Deserialize a node's key from a tree object, returning false if the conversion failed.

Returns
false if the conversion failed
See also
the counterpart function read(Tree const*, id_type, T*)

Definition at line 1898 of file tree.hpp.

1899{
1900 // caller already checks availability of key
1901 return ReadResult(scalar_deserialize(tree->_p(id)->m_key.scalar, v), id);
1902}

◆ read_key() [2/2]

template<class Wrapper>
ReadResult c4::yml::read_key ( Tree const * tree,
id_type id,
Wrapper const & w )
inline

overload to enable use of wrapper tag-types like eg c4::fmt::base64()

Definition at line 1906 of file tree.hpp.

1907{
1908 // caller already checks availability of key
1909 return ReadResult(from_chars(tree->_p(id)->m_key.scalar, w), id);
1910}