add yaml example

This commit is contained in:
Lars Melchior
2019-05-17 17:32:52 +02:00
parent f9ba3f2457
commit 8253393c75
3 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
# ---- Dependencies ----
include(../../cmake/CPM.cmake)
CPMAddPackage(
NAME yaml-cpp
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
# 0.6.2 uses old CMake syntax
VERSION 0.6.3
# 0.6.3 not released yet
GIT_TAG 012269756149ae99745b6dafefd415843d7420bb
OPTIONS
"YAML_CPP_BUILD_TESTS Off"
"YAML_CPP_BUILD_CONTRIB On"
"YAML_CPP_BUILD_TOOLS On"
)
# ---- Executable ----
add_executable(CPMYamlExample "main.cpp")
set_target_properties(CPMYamlExample PROPERTIES CXX_STANDARD 17)
target_link_libraries(CPMYamlExample yaml-cpp)

14
examples/yaml/main.cpp Normal file
View File

@@ -0,0 +1,14 @@
#include <yaml-cpp/yaml.h>
#include <iostream>
int main(int argc, char ** argv){
if (argc != 2) {
std::cout << "usage: " << argv[0] << " <path to yaml file>" << std::endl;
return 1;
}
YAML::Node config = YAML::LoadFile(argv[1]);
std::cout << "Parsed YAML:\n" << config << std::endl;
return 0;
}

View File

@@ -0,0 +1,21 @@
- name: Ogre
position: [0, 5, 0]
powers:
- name: Club
damage: 10
- name: Fist
damage: 8
- name: Dragon
position: [1, 0, 10]
powers:
- name: Fire Breath
damage: 25
- name: Claws
damage: 15
- name: Wizard
position: [5, -3, 0]
powers:
- name: Acid Rain
damage: 50
- name: Staff
damage: 3