Is there a way to get the name of a node? For example:
Fruits:
- apple
- orange
- pear
and in C++:
YAML::Node fruit = parser["Fruits"];
cout << fruit.name() << endl; // should print "Fruits"
is there something like YAML::Node::name()? I don't see anything in Node.h that fits the bill.
If there isn't, any suggestions on a simple way to modify the code to record this information?
Thanks!
What you're really looking for is the key associated with a value in a map. You're right, there's no link back from a value to its key, but you can store one, when you're navigating the node in the first place.
If all of your keys are string keys, then whenever you pass a value to some function, just pass along the string key as well:
// Instead of:
doSomething(node[key]);
// Call:
doSomething(key, node[key]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With