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

std::unique_ptr<NodeMeta> meta

Optional comment block. Null when no comments are attached (common case), saving ~96 bytes per comment-free node.

mark_t marks

Positioning information about the placement of the element in the original input file/stream, i.e. line and column number. Kept inline (not in NodeMeta) so parse-error messages are always available.

Note

(New in MRPT 2.5.0)

bool printInShortFormat = false

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

Note

(New in MRPT 2.1.8)

Public Functions

node_t() = default
node_t(node_t&&) = default
node_t &operator=(node_t&&) = default
inline node_t(const node_t &o)
inline node_t &operator=(const node_t &o)
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 string literals

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>
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
inline std::optional<std::string> &commentSlot(CommentPosition pos)

Ensure meta is allocated and return a mutable reference to the comment slot.