Struct yaml::node_t

Nested Relationships

This struct is a nested type of Class yaml.

Struct Documentation

struct node_t

Data

std::variant<std::monostate, sequence_t, map_t, scalar_t> d

Node data

comments_t comments

Optional comment block

bool printInShortFormat = false

Optional flag to print collections in short form (e.g. [A,B] for sequences)

Note

(New in MRPT 2.1.8)

mark_t marks

Positioning information about the placement of the element in the original input file/stream, i.e. line and column number

Note

(New in MRPT 2.5.0)

Public Functions

template<typename T, typename = std::enable_if_t<!std::is_constructible_v<std::initializer_list<map_t::value_type>, T>>, typename = std::enable_if_t<!std::is_constructible_v<std::initializer_list<sequence_t::value_type>, T>>>
inline node_t(const T &scalar)
inline node_t(const char *str)

Specialization for literals

node_t() = default
inline node_t(std::initializer_list<map_t::value_type> init)
inline node_t(std::initializer_list<sequence_t::value_type> init)
bool isNullNode() const
bool isScalar() const
bool isSequence() const
bool isMap() const
std::string typeName() const

Returns: “null”, “sequence”, “map”, “scalar(<TYPE>)”

sequence_t &asSequence()

Use: for (auto &kv: n.asSequence()) {...}

Throws:

std::exception – If called on a non-sequence node.

const sequence_t &asSequence() const
map_t &asMap()

Use: for (auto &kv: n.asMap()) {...}

Throws:

std::exception – If called on a non-map node.

const map_t &asMap() const
scalar_t &asScalar()
Throws:

std::exception – If called on a non-scalar node.

const scalar_t &asScalar() const
size_t size() const

Returns 1 for null or scalar nodes, the number of children for sequence or map nodes.

template<typename T>
inline T as() const

Returns a copy of the existing value of the given type, or tries to convert it between easily-compatible types (e.g. double<->int, string<->int).

Throws:

std::exception – If the contained type does not match and there is no obvious conversion.

inline std::string_view internalAsStr() const
inline bool hasComment() const
inline bool hasComment(CommentPosition pos) const
inline const std::string &comment() const
inline const std::string &comment(CommentPosition pos) const