struct mrpt::containers::yaml::node_t


#include <mrpt/containers/yaml.h>

struct node_t
    // fields

    std::variant<std::monostate, sequence_t, map_t, scalar_t> d;
    comments_t comments;
    bool printInShortFormat = false;
    mark_t marks;

    // construction


    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>>
    node_t(const T& scalar);

    node_t(const char* str);
    node_t(std::initializer_list<map_t::value_type> init);
    node_t(std::initializer_list<sequence_t::value_type> init);

    // methods

    bool isNullNode() const;
    bool isScalar() const;
    bool isSequence() const;
    bool isMap() const;
    std::string typeName() const;
    sequence_t& asSequence();
    const sequence_t& asSequence() const;
    map_t& asMap();
    const map_t& asMap() const;
    scalar_t& asScalar();
    const scalar_t& asScalar() const;
    size_t size() const;

    template <typename T>
    T as() const;

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


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) (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 (New in MRPT 2.5.0)


node_t(const char* str)

Specialization for literals.


std::string typeName() const

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

sequence_t& asSequence()

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



If called on a non-sequence node.

map_t& asMap()

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



If called on a non-map node.

scalar_t& asScalar()



If called on a non-scalar node.

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).



If the contained type does not match and there is no obvious conversion.