Vulcan
Aerospace Engineering Utilities Built on Janus
Loading...
Searching...
No Matches
vulcan::io::YamlNode Class Reference

Wrapper around yaml-cpp node with ergonomic accessors. More...

#include <YamlNode.hpp>

Public Member Functions

 YamlNode (YAML::Node node, std::string path="root")
 Wrap an existing yaml-cpp node.
YamlNode operator[] (const std::string &key) const
 Access child by key (map).
YamlNode operator[] (std::size_t index) const
 Access child by index (sequence).
bool Has (const std::string &key) const
 Check if key exists.
bool IsDefined () const
 Check if node is defined.
bool IsSequence () const
 Check if node is a sequence.
bool IsMap () const
 Check if node is a map.
bool IsScalar () const
 Check if node is a scalar.
bool IsNull () const
 Check if node is null.
std::size_t Size () const
 Get sequence size.
const std::string & Path () const
 Get current path (for error messages).
template<typename T>
Require (const std::string &key) const
 Get required value (throws YamlError if missing or wrong type).
template<typename T>
As () const
 Get required value from current node.
template<typename T>
Get (const std::string &key, const T &default_value) const
 Get optional value with default.
template<typename T>
std::optional< T > GetOptional (const std::string &key) const
 Get optional value (returns nullopt if missing).
template<typename Func>
void ForEach (Func &&func) const
 Iterate over sequence elements.
template<typename Func>
void ForEachEntry (Func &&func) const
 Iterate over map entries: func(key, node).
template<typename T>
std::vector< T > ToVector () const
 Convert sequence to vector.
const YAML::Node & Raw () const
 Get underlying yaml-cpp node.
template<>
double As () const
 Convert node to double.
template<>
float As () const
 Convert node to float.
template<>
int As () const
 Convert node to int.
template<>
int64_t As () const
 Convert node to int64_t.
template<>
bool As () const
 Convert node to bool.

Static Public Member Functions

static YamlNode LoadFile (const std::string &path)
 Load from file.
static YamlNode Parse (const std::string &yaml_content)
 Parse from string.

Detailed Description

Wrapper around yaml-cpp node with ergonomic accessors.

Provides:

  • Type-safe extraction with good error messages
  • Path tracking for debugging
  • Support for Janus math types

Constructor & Destructor Documentation

◆ YamlNode()

vulcan::io::YamlNode::YamlNode ( YAML::Node node,
std::string path = "root" )
inlineexplicit

Wrap an existing yaml-cpp node.

Member Function Documentation

◆ As() [1/6]

template<>
bool vulcan::io::YamlNode::As ( ) const
inline

Convert node to bool.

◆ As() [2/6]

template<>
int64_t vulcan::io::YamlNode::As ( ) const
inline

Convert node to int64_t.

◆ As() [3/6]

template<>
int vulcan::io::YamlNode::As ( ) const
inline

Convert node to int.

◆ As() [4/6]

template<>
float vulcan::io::YamlNode::As ( ) const
inline

Convert node to float.

◆ As() [5/6]

template<>
double vulcan::io::YamlNode::As ( ) const
inline

Convert node to double.

◆ As() [6/6]

template<typename T>
T vulcan::io::YamlNode::As ( ) const
nodiscard

Get required value from current node.

◆ ForEach()

template<typename Func>
void vulcan::io::YamlNode::ForEach ( Func && func) const
inline

Iterate over sequence elements.

◆ ForEachEntry()

template<typename Func>
void vulcan::io::YamlNode::ForEachEntry ( Func && func) const
inline

Iterate over map entries: func(key, node).

◆ Get()

template<typename T>
T vulcan::io::YamlNode::Get ( const std::string & key,
const T & default_value ) const
inlinenodiscard

Get optional value with default.

◆ GetOptional()

template<typename T>
std::optional< T > vulcan::io::YamlNode::GetOptional ( const std::string & key) const
inlinenodiscard

Get optional value (returns nullopt if missing).

◆ Has()

bool vulcan::io::YamlNode::Has ( const std::string & key) const
inlinenodiscard

Check if key exists.

◆ IsDefined()

bool vulcan::io::YamlNode::IsDefined ( ) const
inlinenodiscard

Check if node is defined.

◆ IsMap()

bool vulcan::io::YamlNode::IsMap ( ) const
inlinenodiscard

Check if node is a map.

◆ IsNull()

bool vulcan::io::YamlNode::IsNull ( ) const
inlinenodiscard

Check if node is null.

◆ IsScalar()

bool vulcan::io::YamlNode::IsScalar ( ) const
inlinenodiscard

Check if node is a scalar.

◆ IsSequence()

bool vulcan::io::YamlNode::IsSequence ( ) const
inlinenodiscard

Check if node is a sequence.

◆ LoadFile()

YamlNode vulcan::io::YamlNode::LoadFile ( const std::string & path)
inlinestatic

Load from file.

◆ operator[]() [1/2]

YamlNode vulcan::io::YamlNode::operator[] ( const std::string & key) const
inlinenodiscard

Access child by key (map).

◆ operator[]() [2/2]

YamlNode vulcan::io::YamlNode::operator[] ( std::size_t index) const
inlinenodiscard

Access child by index (sequence).

◆ Parse()

YamlNode vulcan::io::YamlNode::Parse ( const std::string & yaml_content)
inlinestatic

Parse from string.

◆ Path()

const std::string & vulcan::io::YamlNode::Path ( ) const
inlinenodiscard

Get current path (for error messages).

◆ Raw()

const YAML::Node & vulcan::io::YamlNode::Raw ( ) const
inlinenodiscard

Get underlying yaml-cpp node.

◆ Require()

template<typename T>
T vulcan::io::YamlNode::Require ( const std::string & key) const
inlinenodiscard

Get required value (throws YamlError if missing or wrong type).

◆ Size()

std::size_t vulcan::io::YamlNode::Size ( ) const
inlinenodiscard

Get sequence size.

◆ ToVector()

template<typename T>
std::vector< T > vulcan::io::YamlNode::ToVector ( ) const
inlinenodiscard

Convert sequence to vector.


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