|
1 | 1 | # wsjcpp-yaml |
| 2 | + |
| 3 | +[](https://travis-ci.org/wsjcpp/wsjcpp-yaml) [](https://github.com/wsjcpp/wsjcpp-yaml) [](https://github.com/wsjcpp/wsjcpp-yaml) [](https://github.com/wsjcpp/wsjcpp-yaml/network/members) |
| 4 | + |
2 | 5 | C++ Write/Reader yaml files |
| 6 | + |
| 7 | + |
| 8 | +## Integrate to your c++ project |
| 9 | + |
| 10 | +include files: |
| 11 | + |
| 12 | +- src.wsjcpp/wsjcpp-core/wsjcpp_core.h |
| 13 | +- src.wsjcpp/wsjcpp-core/wsjcpp_core.cpp |
| 14 | +- src/wsjcpp_yaml.cpp |
| 15 | +- src/wsjcpp_yaml.h |
| 16 | + |
| 17 | +In you main file configure logger: |
| 18 | + |
| 19 | +```cpp |
| 20 | + |
| 21 | +#include <string.h> |
| 22 | +#include <iostream> |
| 23 | +#include "wsjcpp_yaml.h" |
| 24 | +#include "wsjcpp_core.h" |
| 25 | + |
| 26 | + |
| 27 | +int main(int argc, char* argv[]) { |
| 28 | + std::string TAG = "MAIN"; |
| 29 | + std::string appLogPath = ".logs"; |
| 30 | + WSJCppLog::setLogDirectory(appLogPath); |
| 31 | + if (!WSJCppCore::dirExists(appLogPath)) { |
| 32 | + WSJCppCore::makeDir(appLogPath); |
| 33 | + } |
| 34 | + WSJCppLog::info(TAG, "Hello!"); |
| 35 | + |
| 36 | + // now you can use WSJCppYAML |
| 37 | + WSJCppYAML yaml; |
| 38 | + if (yaml.loadFromString( |
| 39 | + "# yaml content\n" |
| 40 | + "yaml: nice format\n" |
| 41 | + "some-map: value1\n" |
| 42 | + "some-map2: value2\n" |
| 43 | + "some-array:\n" |
| 44 | + " - test1 \n" |
| 45 | + " - test2 \n" |
| 46 | + )) { |
| 47 | + WSJCppLog::throw_err(TAG, "Error parsing"); |
| 48 | + return -1; |
| 49 | + } |
| 50 | + |
| 51 | + std::cout << "yaml is " << yaml.getRoot()->getElement("yaml")->getValue() << std::endl; |
| 52 | + std::cout << "some-map is " << yaml.getRoot()->getElement("some-map")->getValue() << std::endl; |
| 53 | + std::cout << "some-map2 is " << yaml.getRoot()->getElement("some-map2")->getValue() << std::endl; |
| 54 | + std::cout << "some-array has " << std::to_string(yaml.getRoot()->getElement("some-array")->getLength()) << std::endl; |
| 55 | + std::cout << "some-array element 1 is " << yaml.getRoot()->getElement("some-array")->->getElement(0)->getValue() << std::endl; |
| 56 | + std::cout << "some-array element 2 is " << yaml.getRoot()->getElement("some-array")->->getElement(1)->getValue() << std::endl; |
| 57 | + return 0; |
| 58 | +} |
| 59 | + |
| 60 | +``` |
0 commit comments