struct mrpt::containers::yaml::node_t
Overview
#include <mrpt/containers/yaml.h> struct node_t { // fields std::variant<std::monostate, sequence_t, map_t, scalar_t> d; std::unique_ptr<NodeMeta> meta; mark_t marks; bool printInShortFormat = false; // construction node_t(); node_t(node_t&&); node_t(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>> > 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 node_t& operator = (node_t&&); node_t& operator = (const node_t& o); 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; 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::optional<std::string>& commentSlot(CommentPosition pos); };
Fields
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. (New in MRPT 2.5.0)
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 string 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. |
std::optional<std::string>& commentSlot(CommentPosition pos)
Ensure meta is allocated and return a mutable reference to the comment slot.