A use case is to go through a configuration file written in YAML. I need to check each key and analyze its value accordingly. I like the idea of using random access methods, for example doc["key"] >> value, but I really need to do this to warn the user about unrecognized keys in the configuration file if, for example, they mistakenly wrote the key. I do not know how to do this without repeating the file.
I know I can do this with YAML::Iterator, so
for (YAML::Iterator it=doc.begin(); it<doc.end(); ++it)
{
std::string key;
it.first() >> key;
if (key=="parameter") { }
} else if () {
} else {
std::cerr << "Warning: bad parameter" << std::endl;
}
}
but is there an easier way to do this? My path seems to completely bypass any error checking built into YAML-cpp, and seems to undo all the simplicity of random key access.