Version: SMASH-3.2.2
YAML::convert< T > Struct Template Reference

#include <configuration.h>

template<typename T>
struct YAML::convert< T >

Convert from YAML::Node to SMASH-readable (C++) format and vice versa.

Template Parameters
TType of the values (could be any data type that needs conversion).

Definition at line 42 of file configuration.h.

Static Public Member Functions

static Node encode (const T &x)
 Serialization: Converts x (of any type) to a YAML::Node. More...
 
static bool decode (const Node &node, T &x)
 Deserialization: Converts a YAML::Node to any SMASH-readable data type and returns whether or not this operation was successful. More...
 

Member Function Documentation

◆ encode()

template<typename T >
static Node YAML::convert< T >::encode ( const T &  x)
inlinestatic

Serialization: Converts x (of any type) to a YAML::Node.

To do this, the type of x needs first be cast to a string.

Parameters
[in]xValue that is to be converted to a YAML::Node.
Returns
YAML node

Definition at line 50 of file configuration.h.

50  {
51  if constexpr (std::is_convertible_v<T, std::string>) {
52  return Node{static_cast<std::string>(x)};
53  } else {
54  static_assert(smash::has_to_string_v<T>,
55  "Encoding type T to YAML::Node requires an overload of "
56  "smash::to_string(T) to convert T to an std::string.");
57  return Node{smash::to_string(x)};
58  }
59  }
std::string to_string(ThermodynamicQuantity quantity)
Convert a ThermodynamicQuantity enum value to its corresponding string.
Definition: stringify.cc:25

◆ decode()

template<typename T >
static bool YAML::convert< T >::decode ( const Node &  node,
T &  x 
)
inlinestatic

Deserialization: Converts a YAML::Node to any SMASH-readable data type and returns whether or not this operation was successful.

Parameters
[in]nodeYAML::Node that is to be converted.
[in]xValue that the YAML:Node is cast to.
Returns
True in case conversion was successful.

Definition at line 69 of file configuration.h.

69  {
70  if (!node.IsScalar()) {
71  return false;
72  } else {
73  x = static_cast<T>(node.Scalar());
74  return true;
75  }
76  }

The documentation for this struct was generated from the following file: