A powerful simple lightweight YAML parser library for C++. There are lots of libraries which parse yaml files in C++, yet they are cumbersome and very heavy to include in a performance-matter project, thus increasing the need for a minimal robust parser.
-
Very easy to integrate to your project:
- Copy the
yaml/
directory to your project. - Include the
yaml.hpp
file in your source code. - Add the
yaml.cpp
to the compiler and linker.
- Copy the
-
Robust and Recovery:
- Simple indentation errors are recoverable. The parser will try its best to find the best suit for the yaml layout even if there are unconsistant indentations.
- Abilty to parse list-elements and list-nodes. These happen when a parent node either has a list of nodes or elements attached to it.
-
Simple to Use:
- Retreiving values of nodes or lists are quite simple and intuitive. Note, the syntax is shown below.
The content below represents a yaml file, then a set of examples on how to extract the data:
example.yaml
object:
name: "mohido"
property: "cool as hell"
version: 123
academy: "333"
list:
- item1
- item2
- item3
node_list:
- name : "node1"
value: 1
hell:
- item1: "sang"
- item1: "mang"
- name : "node2"
value: 2
temp: extra
extra:
- extra1
- extra2
- extra3
First of all, create a yaml parser object:
YAML::Yaml coolYamlObject(<yaml_file_path>);
-
value
"mohido"
ofobject.name
can be accessed as follows:coolYamlObject["object"]["name"].getData<std::string>();
-
value
123
ofversion
can be accessed as follows:coolYamlObject["version"].getData<std::string>();
-
value
item1
oflist[0]
can be accessed as follows:coolYamlObject["list"].getData<std::vector<std::string>>()[0];
-
value
"node1"
ofnode_list[0].name
can be accessed as follows:coolYamlObject["node_list"]["0"]["name"].getData<std::string>();
-
value
extra3
ofnode_list[1].extra[2]
can be accessed as follows:coolYamlObject["node_list"]["1"]["extra"].getData<std::vector<std::string>>()[2];
- Contributions are welcome!
- Bugs/Suggestions/Reports can be created as issues on Github with the desired label.