rapidyaml  0.10.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...
 

Detailed Description

Function Documentation

◆ key() [1/3]

◆ key() [2/3]

Definition at line 44 of file node.hpp.

44 { return {w}; }

◆ key() [3/3]

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

Definition at line 45 of file node.hpp.

45 { return {w}; }

◆ write()

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

Definition at line 1632 of file node.hpp.

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

References c4::yml::NodeRef::set_val_serialized().

Referenced by c4::yml::NodeRef::operator<<().

◆ read() [1/3]

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

Definition at line 1638 of file node.hpp.

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

Referenced by c4::yml::detail::RoNodeMethods< Impl, ConstImpl >::operator>>(), and c4::yml::read().

◆ read() [2/3]

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

Definition at line 1644 of file node.hpp.

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

References c4::yml::read().

◆ readkey() [1/3]

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

Definition at line 1650 of file node.hpp.

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

Referenced by c4::yml::detail::RoNodeMethods< Impl, ConstImpl >::operator>>(), and c4::yml::readkey().

◆ readkey() [2/3]

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

Definition at line 1656 of file node.hpp.

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

References c4::yml::readkey().

◆ 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 1363 of file tree.hpp.

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

References sample::from_chars(), and c4::yml::VALNIL.

◆ 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 1374 of file tree.hpp.

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

References sample::from_chars(), and c4::yml::KEYNIL.

◆ 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 1438 of file tree.hpp.

1439 {
1440  static_assert(std::is_floating_point<T>::value, "must be floating point");
1441  C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wfloat-equal");
1442  if(C4_UNLIKELY(std::isnan(val)))
1443  return to_chars(buf, csubstr(".nan"));
1444  else if(C4_UNLIKELY(val == std::numeric_limits<T>::infinity()))
1445  return to_chars(buf, csubstr(".inf"));
1446  else if(C4_UNLIKELY(val == -std::numeric_limits<T>::infinity()))
1447  return to_chars(buf, csubstr("-.inf"));
1448  return to_chars(buf, val);
1449  C4_SUPPRESS_WARNING_GCC_CLANG_POP
1450 }
size_t to_chars(substr buf, ievt::DataType flags)
Convert bit mask of ievt::EventFlags to text.
Definition: ints_utils.cpp:68

References c4::yml::extra::ievt::to_chars().

Referenced by c4::yml::Tree::to_arena().

◆ 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 1456 of file tree.hpp.

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

References sample::from_chars().

Referenced by c4::yml::read(), and c4::yml::readkey().