LocalGuidance
A library that generates velocity references to follow a path.
yaml_tools::YamlNode Class Reference

#include <YamlNode.hpp>

Inheritance diagram for yaml_tools::YamlNode:
Inheritance graph

Public Types

using Impl = YAML::Node
 The underlying node. More...
 
using Type = YAML::NodeType::value
 The underlying node type. More...
 

Public Member Functions

 YamlNode ()=default
 Default constructor. More...
 
 YamlNode (const YamlNode &other)=default
 Default copy constructor (shallow!). More...
 
virtual ~YamlNode ()=default
 Destructor. More...
 
ImplgetImpl ()
 Get the underlying type as reference. More...
 
const ImplgetImpl () const
 Get the underlying type as const reference. More...
 
const std::string & getNestedKey () const
 Get the nested key of the YAML node. More...
 
std::string toString () const
 
void toFile (const std::string &path) const
 
bool isDefined () const
 Check if the YAML node is defined. More...
 
bool isNull () const
 Check if the YAML node is null. More...
 
bool isScalar () const
 Check if the YAML node is of type scalar. More...
 
bool isSequence () const
 Check if the YAML node is of type sequence. More...
 
bool isMap () const
 Check if the YAML node is of type map. More...
 
Type getType () const
 Get the YAML node type. More...
 
YamlNodeoperator= (const YamlNode &rhs)=default
 Assignment operator for YAML nodes (shallow!). More...
 
template<typename Scalar >
YamlNodeoperator= (const Scalar &rhs)
 
bool operator== (const YamlNode &rhs) const
 
bool hasKey (const std::string &key) const
 
bool hasKey (const size_t i) const
 
std::vector< std::string > getKeys () const
 
YamlNode operator[] (const std::string &key)
 
YamlNode operator[] (const std::string &key) const
 
YamlNode operator[] (const size_t i)
 
YamlNode operator[] (const size_t i) const
 
size_t size () const
 
template<typename T >
void pushBack (const T &t)
 
Iterator begin ()
 
ConstIterator begin () const
 
Iterator end ()
 
ConstIterator end () const
 
template<typename Scalar >
Scalar as () const
 
template<>
void pushBack (const YamlNode &t)
 Specialization of pushBack(..) for YAML nodes. More...
 

Static Public Member Functions

static YamlNode fromString (const std::string &string)
 
static YamlNode fromFile (const std::string &path)
 

Protected Member Functions

 YamlNode (const Impl &impl, std::string nestedKey)
 

Protected Attributes

Impl impl_
 Implementation. More...
 
std::string nestedKey_
 

Detailed Description

YAML node wrapping class. YAML nodes can contain trees of the following data structures:

  • scalars (of type bool, int, float, double, string)
  • sequences
  • maps

Member Typedef Documentation

◆ Impl

using yaml_tools::YamlNode::Impl = YAML::Node

The underlying node.

◆ Type

using yaml_tools::YamlNode::Type = YAML::NodeType::value

The underlying node type.

Constructor & Destructor Documentation

◆ YamlNode() [1/3]

yaml_tools::YamlNode::YamlNode ( const Impl impl,
std::string  nestedKey 
)
protected

Constructor from an underlying YAML node. Protected, for internal use only.

Parameters
implUnderlying YAML node.
nestedKeyNested key.

◆ YamlNode() [2/3]

yaml_tools::YamlNode::YamlNode ( )
default

Default constructor.

◆ YamlNode() [3/3]

yaml_tools::YamlNode::YamlNode ( const YamlNode other)
default

Default copy constructor (shallow!).

◆ ~YamlNode()

virtual yaml_tools::YamlNode::~YamlNode ( )
virtualdefault

Destructor.

Member Function Documentation

◆ as()

template<typename Scalar >
Scalar yaml_tools::YamlNode::as ( ) const
inline

Cast a YAML node to a scalar. Applicable YAML node types: Scalar. Throws a yaml_tools::Exception if unsuccessful.

Template Parameters
ScalarScalar type to cast into.
Returns
Scalar.

◆ begin() [1/2]

Iterator yaml_tools::YamlNode::begin ( )

Get an iterator pointing to the first element of the YAML node. Applicable YAML node types: Sequence, Map. Throws a yaml_tools::Exception if unsuccessful.

Returns
Iterator.

◆ begin() [2/2]

ConstIterator yaml_tools::YamlNode::begin ( ) const

Get a constant iterator pointing to the first element of the YAML node. Applicable YAML node types: Sequence, Map. Throws a yaml_tools::Exception if unsuccessful.

Returns
Constant iterator.

◆ end() [1/2]

Iterator yaml_tools::YamlNode::end ( )

Get an iterator pointing to one past the last element of the YAML node. Applicable YAML node types: Sequence, Map. Throws a yaml_tools::Exception if unsuccessful.

Returns
Iterator.

◆ end() [2/2]

ConstIterator yaml_tools::YamlNode::end ( ) const

Get a constant iterator pointing to one past the last element of the YAML node. Applicable YAML node types: Sequence, Map. Throws a yaml_tools::Exception if unsuccessful.

Returns
Constant iterator.

◆ fromFile()

static YamlNode yaml_tools::YamlNode::fromFile ( const std::string &  path)
static

Create a new YAML node by parsing a file. Throws a yaml_tools::Exception if unsuccessful.

Parameters
pathAbsolute path of the file.
Returns
New YAML node.

◆ fromString()

static YamlNode yaml_tools::YamlNode::fromString ( const std::string &  string)
static

Create a new YAML node by parsing a string. Throws a yaml_tools::Exception if unsuccessful.

Parameters
stringString to parse.
Returns
New YAML node.

◆ getImpl() [1/2]

Impl& yaml_tools::YamlNode::getImpl ( )

Get the underlying type as reference.

◆ getImpl() [2/2]

const Impl& yaml_tools::YamlNode::getImpl ( ) const

Get the underlying type as const reference.

◆ getKeys()

std::vector<std::string> yaml_tools::YamlNode::getKeys ( ) const

Get the map keys of this YAML node. Applicable YAML node types: Map. Throws a yaml_tools::Exception if unsuccessful.

Returns
Map keys of the YAML node.

◆ getNestedKey()

const std::string& yaml_tools::YamlNode::getNestedKey ( ) const
inline

Get the nested key of the YAML node.

◆ getType()

Type yaml_tools::YamlNode::getType ( ) const
inline

Get the YAML node type.

◆ hasKey() [1/2]

bool yaml_tools::YamlNode::hasKey ( const std::string &  key) const

Check if YAML node has a given key. Throws a yaml_tools::Exception if unsuccessful.

Parameters
keyKey to check for.
Returns
True if contains given key.

◆ hasKey() [2/2]

bool yaml_tools::YamlNode::hasKey ( const size_t  i) const

Check if YAML node has a given index. Throws a yaml_tools::Exception if unsuccessful.

Parameters
iIndex to check for.
Returns
True if contains given index.

◆ isDefined()

bool yaml_tools::YamlNode::isDefined ( ) const
inline

Check if the YAML node is defined.

◆ isMap()

bool yaml_tools::YamlNode::isMap ( ) const
inline

Check if the YAML node is of type map.

◆ isNull()

bool yaml_tools::YamlNode::isNull ( ) const
inline

Check if the YAML node is null.

◆ isScalar()

bool yaml_tools::YamlNode::isScalar ( ) const
inline

Check if the YAML node is of type scalar.

◆ isSequence()

bool yaml_tools::YamlNode::isSequence ( ) const
inline

Check if the YAML node is of type sequence.

◆ operator=() [1/2]

YamlNode& yaml_tools::YamlNode::operator= ( const YamlNode rhs)
default

Assignment operator for YAML nodes (shallow!).

◆ operator=() [2/2]

template<typename Scalar >
YamlNode& yaml_tools::YamlNode::operator= ( const Scalar &  rhs)
inline

Assignment operator for scalars.

Template Parameters
ScalarType of the scalar.
Parameters
rhsScalar to assign this YAML node to.
Returns
Reference to this YAML node.

◆ operator==()

bool yaml_tools::YamlNode::operator== ( const YamlNode rhs) const

Comparison operator. Compares the content of the node, ignoring the nested keys.

Parameters
rhsOther YAML node.
Returns
True if the YAML nodes are equal.

◆ operator[]() [1/4]

YamlNode yaml_tools::YamlNode::operator[] ( const std::string &  key)

Access a child YAML node by key. Creates a new child YAML node if it is not existing yet. Throws a yaml_tools::Exception if unsuccessful.

Parameters
keyKey.
Returns
YAML node.

◆ operator[]() [2/4]

YamlNode yaml_tools::YamlNode::operator[] ( const std::string &  key) const

Access a child YAML node by key. Does not create a new child YAML node if it is not existing yet. Throws a yaml_tools::Exception if unsuccessful.

Parameters
keyKey.
Returns
YAML node.

◆ operator[]() [3/4]

YamlNode yaml_tools::YamlNode::operator[] ( const size_t  i)

Access a child YAML node by index. Does not create a new child YAML node if it is not existing yet. Throws a yaml_tools::Exception if unsuccessful. Note: This method does the same thing as its 'const' counterpart. It has been introduced to solve the nonConstYamlNode[0] ambiguity issue, which origins from the fact that '0' can be converted to size_t, but also to 'const char*' and therefore 'string'.

Parameters
iIndex.
Returns
YAML node.

◆ operator[]() [4/4]

YamlNode yaml_tools::YamlNode::operator[] ( const size_t  i) const

Access a child YAML node by index. Does not create a new child YAML node if it is not existing yet. Throws a yaml_tools::Exception if unsuccessful.

Parameters
iIndex.
Returns
YAML node.

◆ pushBack() [1/2]

template<typename T >
void yaml_tools::YamlNode::pushBack ( const T &  t)
inline

Add an element to the YAML node. Applicable YAML node types: Sequence. Throws a yaml_tools::Exception if unsuccessful.

Template Parameters
TType of the element. Can be a scalar or a YAML node itself.
Parameters
tElement to add.

◆ pushBack() [2/2]

template<>
void yaml_tools::YamlNode::pushBack ( const YamlNode t)

Specialization of pushBack(..) for YAML nodes.

◆ size()

size_t yaml_tools::YamlNode::size ( ) const

Get the number of elements contained in this YAML node. Returns 0 for YAML nodes of type Scalar. Applicable YAML node types: Scalar, Sequence, Map. Throws a yaml_tools::Exception if unsuccessful.

Returns
Size of the YAML node.

◆ toFile()

void yaml_tools::YamlNode::toFile ( const std::string &  path) const

Write the YAML node into a file. Throws a yaml_tools::Exception if unsuccessful.

Parameters
pathAbsolute path of the file.

◆ toString()

std::string yaml_tools::YamlNode::toString ( ) const

Convert the YAML node into a string. Throws a yaml_tools::Exception if unsuccessful.

Returns
YAML node in string format.

Member Data Documentation

◆ impl_

Impl yaml_tools::YamlNode::impl_
protected

Implementation.

◆ nestedKey_

std::string yaml_tools::YamlNode::nestedKey_
protected

Nested key for printing warnings and errors. Contains information about file paths, sequence indices and map keys.


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