rapidyaml  0.13.0
parse and emit YAML, and do it fast
Serialization helpers

Classes

struct  c4::yml::Key< K >
 
struct  c4::yml::Key< fmt::const_base64_wrapper >
 
struct  c4::yml::Key< fmt::base64_wrapper >
 

Functions

template<class K >
Key< K > c4::yml::key (K &k)
 
Key< fmt::const_base64_wrapperc4::yml::key (fmt::const_base64_wrapper w)
 
Key< fmt::base64_wrapperc4::yml::key (fmt::base64_wrapper w)
 
template<class T >
void c4::yml::write (NodeRef *n, T const &v)
 
template<class T >
bool c4::yml::read (ConstNodeRef const &n, T *v)
 
template<class T >
bool c4::yml::read (NodeRef const &n, T *v)
 
template<class T >
bool c4::yml::readkey (ConstNodeRef const &n, T *v)
 
template<class T >
bool c4::yml::readkey (NodeRef const &n, T *v)
 
template<class T >
auto c4::yml::read (Tree const *tree, id_type id, T *v) -> typename std::enable_if<!std::is_arithmetic< T >::value, bool >::type
 convert the val of a scalar node to a particular non-arithmetic non-float type, by forwarding its val to from_chars<T>(). More...
 
template<class T >
auto c4::yml::readkey (Tree const *tree, id_type id, T *v) -> typename std::enable_if<!std::is_arithmetic< T >::value, bool >::type
 convert the key of a node to a particular non-arithmetic non-float type, by forwarding its key to from_chars<T>(). More...
 
template<class T >
size_t c4::yml::to_chars_float (substr buf, T val)
 encode a floating point value to a string. More...
 
template<class T >
bool c4::yml::from_chars_float (csubstr buf, T *val)
 decode a floating point from string. More...
 
template<class T >
csubstr c4::yml::serialize_to_arena (Tree *tree, T const &a)
 

Detailed Description

Function Documentation

◆ key() [1/3]

template<class K >
Key<K> c4::yml::key ( K &  k)
inline

Definition at line 46 of file node.hpp.

46 { return Key<K>{k}; }

◆ key() [2/3]

Definition at line 47 of file node.hpp.

47 { return {w}; }

◆ key() [3/3]

Key<fmt::base64_wrapper> c4::yml::key ( fmt::base64_wrapper  w)
inline

Definition at line 48 of file node.hpp.

48 { return {w}; }

◆ write()

template<class T >
void c4::yml::write ( NodeRef n,
T const &  v 
)
inline

Definition at line 1633 of file node.hpp.

1634 {
1635  n->set_val_serialized(v);
1636 }

◆ read() [1/3]

template<class T >
bool c4::yml::read ( ConstNodeRef const &  n,
T *  v 
)
inline

Definition at line 1639 of file node.hpp.

1640 {
1641  return read(n.m_tree, n.m_id, v);
1642 }
bool read(NodeRef const &n, T *v)
Definition: node.hpp:1645

◆ read() [2/3]

template<class T >
bool c4::yml::read ( NodeRef const &  n,
T *  v 
)
inline

Definition at line 1645 of file node.hpp.

1646 {
1647  return read(n.tree(), n.id(), v);
1648 }

◆ readkey() [1/3]

template<class T >
bool c4::yml::readkey ( ConstNodeRef const &  n,
T *  v 
)
inline

Definition at line 1651 of file node.hpp.

1652 {
1653  return readkey(n.m_tree, n.m_id, v);
1654 }
bool readkey(NodeRef const &n, T *v)
Definition: node.hpp:1657

◆ readkey() [2/3]

template<class T >
bool c4::yml::readkey ( NodeRef const &  n,
T *  v 
)
inline

Definition at line 1657 of file node.hpp.

1658 {
1659  return readkey(n.tree(), n.id(), v);
1660 }

◆ read() [3/3]

template<class T >
auto c4::yml::read ( Tree const *  tree,
id_type  id,
T *  v 
) -> typename std::enable_if<!std::is_arithmetic<T>::value, bool>::type
inline

convert the val of a scalar node to a particular non-arithmetic non-float type, by forwarding its val to from_chars<T>().

convert the val of a scalar node to a particular arithmetic integral non-float type, by forwarding its val to from_chars<T>().

The full string is used.

Returns
false if the conversion failed, or if the key was empty and unquoted

The full string is used.

Returns
false if the conversion failed

Definition at line 1367 of file tree.hpp.

1369 {
1370  return C4_LIKELY(!(tree->type(id) & VALNIL)) ? from_chars(tree->val(id), v) : false;
1371 }
@ VALNIL
the val is null (eg {a : } results in a null val)
Definition: node_type.hpp:50
bool from_chars(ryml::csubstr buf, vec2< T > *v)

◆ readkey() [3/3]

template<class T >
auto c4::yml::readkey ( Tree const *  tree,
id_type  id,
T *  v 
) -> typename std::enable_if<!std::is_arithmetic<T>::value, bool>::type
inline

convert the key of a node to a particular non-arithmetic non-float type, by forwarding its key to from_chars<T>().

convert the key of a node to a particular arithmetic integral non-float type, by forwarding its val to from_chars<T>().

The full string is used.

Returns
false if the conversion failed, or if the key was empty and unquoted

The full string is used.

Returns
false if the conversion failed

Definition at line 1378 of file tree.hpp.

1380 {
1381  return C4_LIKELY(!(tree->type(id) & KEYNIL)) ? from_chars(tree->key(id), v) : false;
1382 }
@ KEYNIL
the key is null (eg { : b} results in a null key)
Definition: node_type.hpp:49

◆ to_chars_float()

template<class T >
size_t c4::yml::to_chars_float ( substr  buf,
val 
)

encode a floating point value to a string.

Definition at line 1442 of file tree.hpp.

1443 {
1444  static_assert(std::is_floating_point<T>::value, "must be floating point");
1445  C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wfloat-equal");
1446  if(C4_UNLIKELY(std::isnan(val)))
1447  return to_chars(buf, csubstr(".nan"));
1448  else if(C4_UNLIKELY(val == std::numeric_limits<T>::infinity()))
1449  return to_chars(buf, csubstr(".inf"));
1450  else if(C4_UNLIKELY(val == -std::numeric_limits<T>::infinity()))
1451  return to_chars(buf, csubstr("-.inf"));
1452  return to_chars(buf, val);
1453  C4_SUPPRESS_WARNING_GCC_CLANG_POP
1454 }
size_t to_chars(substr buf, escaped_scalar e)
formatting implementation to escape a scalar with escape_scalar()

◆ from_chars_float()

template<class T >
bool c4::yml::from_chars_float ( csubstr  buf,
T *  val 
)

decode a floating point from string.

Accepts special values: .nan, .inf, -.inf

Definition at line 1460 of file tree.hpp.

1461 {
1462  static_assert(std::is_floating_point<T>::value, "must be floating point");
1463  if(buf.begins_with('+'))
1464  {
1465  buf = buf.sub(1);
1466  }
1467  if(C4_LIKELY(from_chars(buf, val)))
1468  {
1469  return true;
1470  }
1471  else if(C4_UNLIKELY(buf == ".nan" || buf == ".NaN" || buf == ".NAN"))
1472  {
1473  *val = std::numeric_limits<T>::quiet_NaN();
1474  return true;
1475  }
1476  else if(C4_UNLIKELY(buf == ".inf" || buf == ".Inf" || buf == ".INF"))
1477  {
1478  *val = std::numeric_limits<T>::infinity();
1479  return true;
1480  }
1481  else if(C4_UNLIKELY(buf == "-.inf" || buf == "-.Inf" || buf == "-.INF"))
1482  {
1483  *val = -std::numeric_limits<T>::infinity();
1484  return true;
1485  }
1486  else
1487  {
1488  return false;
1489  }
1490 }

◆ serialize_to_arena()

template<class T >
csubstr c4::yml::serialize_to_arena ( Tree tree,
T const &  a 
)

Definition at line 1556 of file tree.hpp.

1557 {
1558  substr rem(tree->m_arena.sub(tree->m_arena_pos));
1559  size_t num = serialize_scalar(rem, a);
1560  if(num > rem.len)
1561  {
1562  rem = tree->_grow_arena(num);
1563  num = serialize_scalar(rem, a);
1564  _RYML_ASSERT_VISIT_(tree->m_callbacks, num <= rem.len, tree, NONE);
1565  }
1566  rem = tree->_request_span(num);
1567  return rem;
1568 }
auto serialize_scalar(substr buf, T const &a) -> typename std::enable_if< std::is_floating_point< T >::value, size_t >::type
Definition: tree.hpp:64
@ NONE
an index to none
Definition: common.hpp:251