Single header YAML 1.0 C++11 serializer/deserializer.
key: foo bar
list:
- hello world
- integer: 123
boolean: true
auto root = yaml::parse_file<yaml::document>("file.txt");
// Get scalar values.
root["key"].as<std::string>(); // "foo bar"
root["list"][0].as<std::string>(); // "hello world"
root["list"][1]["integer"].as<int>(); // 123
root["list"][1]["boolean"].as<bool>(); // true
root["list"][1]["boolean"].as<std::string>(); // "true"
// Iterate second sequence item of "list".
auto & item = root["list"][1];
for(auto it = item.begin(); it != item.end(); it++)
{
(*it).first; // "integer" / "boolean"
(*it).second.as<string>(); // "123" / "true"
}See Best practice.
Put /yaml in your project directory and simply #include "yaml/yaml.hpp". See examples/first_example.cpp for additional examples.
Always use references when accessing node content, if not intended to make a copy. Modifying copied node wont affect the original node content.
See example:
yaml::node root;
yaml::node & ref = root; // The content of "root" is not being copied.
ref["key"] = "value"; // Modifying "root" node content.
yaml::node copy = root; // The content of "root" is copied to "copy".
// Slow operation if "root" contains a lot of content.
copy["key"] = "value"; // Modifying "copy"'s content. "root" is left untouched.Builds are passed if all tests are good and no memory leaks were found.
| Branch | Linux | Windows |
|---|---|---|
| master | ||
| develop |
Parse/serialize tags(!!type).Parse anchors.Parse flow sequences/maps.Parse complex keys.Parse sets.