Skip to content

nodef/mini-yaml.cxx

 
 

Repository files navigation

mini-yaml

Build Status
Single header YAML 1.0 C++11 serializer/deserializer, by Jimmie Bergmann.

Quickstart

file.txt

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

.cpp

Yaml::Node root;
Yaml::Parse(root, "file.txt");

// Print all scalars.
std::cout << root["key"].As<std::string>() << std::endl;
std::cout << root["list"][0].As<std::string>() << std::endl;
std::cout << root["list"][1]["integer"].As<int>() << std::endl;
std::cout << root["list"][1]["boolean"].As<bool>() << std::endl;

// Iterate second sequence item.
Node & item = root[1];
for(auto it = item.Begin(); it != item.End(); it++)
{
    std::cout << (*it).first << ": " << (*it).second.As<string>() << std::endl;
}

Output

foo bar
hello world
123
1
integer: 123
boolean: true

See Best practice.

Installation

Run:

$ npm i mini-yaml.cxx

And then include Yaml.hpp as follows:

#include "node_modules/mini-yaml.cxx/yaml/Yaml.hpp"

You may also want to include Yaml.cpp as follows:

#ifndef __MINI_YAML_CXX__
#define __MINI_YAML_CXX__
#include "node_modules/mini-yaml.cxx/yaml/Yaml.cpp"
#endif

Usage

See examples/FirstExample.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" node content. "root" is left untouched.

Build status

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

Branch Status
master Build Status
dev 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; Jimmie Bergmann (2018).

Resources

License

Stars

Watchers

Forks

Languages

  • C++ 99.6%
  • Makefile 0.4%