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;

    // construction

    node_t();

    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;
};

Fields

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)

Construction

node_t(const char* str)

Specialization for literals.

Methods

std::string typeName() const

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

sequence_t& asSequence()

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

Parameters:

std::exception

If called on a non-sequence node.

map_t& asMap()

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

Parameters:

std::exception

If called on a non-map node.

scalar_t& asScalar()

Parameters:

std::exception

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

Parameters:

std::exception

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