Drake
Drake C++ Documentation
drake::yaml Namespace Reference

Classes

struct  LoadYamlOptions
 Configuration for LoadYamlFile() and LoadYamlString() to govern when certain conditions are errors or not. More...
 

Functions

template<typename Serializable >
static Serializable LoadYamlFile (const std::string &filename, const std::optional< std::string > &child_name=std::nullopt, const std::optional< Serializable > &defaults=std::nullopt, const std::optional< LoadYamlOptions > &options=std::nullopt)
 Loads data from a YAML-formatted file. More...
 
template<typename Serializable >
static Serializable LoadYamlString (const std::string &data, const std::optional< std::string > &child_name=std::nullopt, const std::optional< Serializable > &defaults=std::nullopt, const std::optional< LoadYamlOptions > &options=std::nullopt)
 Loads data from a YAML-formatted string. More...
 
template<typename Serializable >
void SaveYamlFile (const std::string &filename, const Serializable &data, const std::optional< std::string > &child_name=std::nullopt, const std::optional< Serializable > &defaults=std::nullopt)
 Saves data as a YAML-formatted file. More...
 
template<typename Serializable >
std::string SaveYamlString (const Serializable &data, const std::optional< std::string > &child_name=std::nullopt, const std::optional< Serializable > &defaults=std::nullopt)
 Saves data as a YAML-formatted string. More...
 
template<typename Serializable >
void SaveJsonFile (const std::string &filename, const Serializable &data)
 Saves data as a JSON-formatted file. More...
 
template<typename Serializable >
std::string SaveJsonString (const Serializable &data)
 Saves data as a JSON-formatted string. More...
 

Function Documentation

◆ LoadYamlFile()

static Serializable LoadYamlFile ( const std::string &  filename,
const std::optional< std::string > &  child_name = std::nullopt,
const std::optional< Serializable > &  defaults = std::nullopt,
const std::optional< LoadYamlOptions > &  options = std::nullopt 
)
static

Loads data from a YAML-formatted file.

Refer to YAML Serialization for background and examples.

Parameters
filenameFilename to be read from.
child_name(optional) If provided, loads data from given-named child of the document's root instead of the root itself.
defaults(optional) If provided, then the structure being read into will be initialized using this value instead of the default constructor, and also (unless the options argument is provided and specifies otherwise) any member fields that are not mentioned in the YAML will retain their default values.
options(optional, advanced) If provided, overrides the nominal parsing options. Most users should not specify this; the default is usually correct.
Returns
the loaded user data.
Template Parameters
Serializablemust implement a Serialize function and be default constructible.

◆ LoadYamlString()

static Serializable LoadYamlString ( const std::string &  data,
const std::optional< std::string > &  child_name = std::nullopt,
const std::optional< Serializable > &  defaults = std::nullopt,
const std::optional< LoadYamlOptions > &  options = std::nullopt 
)
static

Loads data from a YAML-formatted string.

Refer to YAML Serialization for background and examples.

Parameters
datathe YAML document as a string.
child_name(optional) If provided, loads data from given-named child of the document's root instead of the root itself.
defaults(optional) If provided, then the structure being read into will be initialized using this value instead of the default constructor, and also (unless the options argument is provided and specifies otherwise) any member fields that are not mentioned in the YAML will retain their default values.
options(optional, advanced) If provided, overrides the nominal parsing options. Most users should not specify this; the default is usually correct.
Returns
the loaded user data.
Template Parameters
Serializablemust implement a Serialize function and be default constructible.

◆ SaveJsonFile()

void SaveJsonFile ( const std::string &  filename,
const Serializable &  data 
)

Saves data as a JSON-formatted file.

Refer to YAML Serialization for background.

Note that there is no matching LoadJsonFile function, because we haven't found any specific need for it yet in C++.

Parameters
dataUser data to be serialized.
Returns
the JSON data as a string.
Template Parameters
Serializablemust implement a Serialize function.

◆ SaveJsonString()

std::string SaveJsonString ( const Serializable &  data)

Saves data as a JSON-formatted string.

Refer to YAML Serialization for background.

Note that there is no matching LoadJsonString function, because we haven't found any specific need for it yet in C++.

Parameters
dataUser data to be serialized.
Returns
the JSON data as a string.
Template Parameters
Serializablemust implement a Serialize function.

◆ SaveYamlFile()

void SaveYamlFile ( const std::string &  filename,
const Serializable &  data,
const std::optional< std::string > &  child_name = std::nullopt,
const std::optional< Serializable > &  defaults = std::nullopt 
)

Saves data as a YAML-formatted file.

Refer to YAML Serialization for background.

The YAML will consist of a single document with a mapping node at the root. If a child_name is not provided (the default), then the serialized data will appear directly within that top-level mapping node. If a child_name is provided, then the top-level mapping node will contain only one entry, whose key is child_name and value is the serialized data.

Parameters
filenameFilename to be written to.
dataUser data to be serialized.
child_name(optional) If provided, the YAML document will be {child_name: { data }} rather than just { data }.
defaults(optional) If provided, then only data that differs from the given defaults will be serialized.
Template Parameters
Serializablemust implement a Serialize function.

◆ SaveYamlString()

std::string SaveYamlString ( const Serializable &  data,
const std::optional< std::string > &  child_name = std::nullopt,
const std::optional< Serializable > &  defaults = std::nullopt 
)

Saves data as a YAML-formatted string.

Refer to YAML Serialization for background.

The YAML will consist of a single document with a mapping node at the root. If a child_name is not provided (the default), then the serialized data will appear directly within that top-level mapping node. If a child_name is provided, then the top-level mapping node will contain only one entry, whose key is child_name and value is the serialized data.

Parameters
dataUser data to be serialized.
child_name(optional) If provided, the YAML document will be {child_name: { data }} rather than just { data }.
defaults(optional) If provided, then only data that differs from the given defaults will be serialized.
Returns
the YAML document as a string.
Template Parameters
Serializablemust implement a Serialize function.