Skip to content
 
 

Repository files navigation

mini-yaml

version Build Status Build status codecov License: MIT
Single header YAML 1.0 C++11 serializer/deserializer.

Quickstart

file.txt

key: foo bar
list:
  - hello world
  - integer: 123
    boolean: true

.cpp

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.

Usage

Put /yaml in your project directory and simply #include "yaml/yaml.hpp". See examples/first_example.cpp for additional examples.

Best practice

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.

Build status

Builds are passed if all tests are good and no memory leaks were found.

Branch Linux Windows
master Build Status Build status
develop Build Status Build status

Todo

  • Parse/serialize tags(!!type).
  • Parse anchors.
  • Parse flow sequences/maps.
  • Parse complex keys.
  • Parse sets.

About

Single header YAML 1.0 C++11 serializer/deserializer.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages