In yaml-cpp, the function YAML::Node::Tag() seems to only return anything other than "?" when an application-defined tag is used in the YAML source. Surely it should return (for example) "!!map", "!!int" or other built in tags. Is this desired behaviour, and how can I determine, for example, the particular type tag of a scalar node, e.g. null, boolean, integer, float, string etc.? The only approach I can see is to try YAML::Node::as<T>() with each type until an exception is not thrown.

有帮助吗?

解决方案

To get the type of a node, call YAML::Node::Type(). The return value is one of:

YAML::NodeType::Undefined
YAML::NodeType::Null
YAML::NodeType::Scalar
YAML::NodeType::Sequence
YAML::NodeType::Map

yaml-cpp does not do more specific automatic tag detection, e.g., it will not validate !!int vs. !!float.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top