项目作者: Tosainu

项目描述 :
YAML deserializer for C++17
高级语言: C++
项目地址: git://github.com/Tosainu/yamlizer.git
创建时间: 2018-01-14T02:57:13Z
项目社区:https://github.com/Tosainu/yamlizer

开源协议:MIT License

下载


" class="reference-link">yamlizer

YAML deserializer for C++17

Requirements

  • GCC 7.3.1+ or Clang 5.0.1+
  • CMake 3.8+
  • Boost 1.61.0+
    • Boost.Convert
    • Boost.Hana
    • Boost.Test
  • libyaml 0.1.7+

Example

scalar

  1. const auto v1 = yamlizer::from_yaml<int>("123");
  2. // => 123
  3. const auto v2 = yamlizer::from_yaml<float>("1.23");
  4. // => 1.23f

string

  1. const auto s1 = yamlizer::from_yaml<std::string>("Hello, World!");
  2. // => std::string{"Hello, World!"}
  3. const auto s2 = yamlizer::from_yaml<std::wstring>("Hello, World!");
  4. // => std::wstring{L"Hello, World!"}

struct

  1. struct book {
  2. std::string name;
  3. int price;
  4. };
  5. BOOST_HANA_ADAPT_STRUCT(book, name, price);
  6. const auto b = yamlizer::from_yaml<book>(R"EOS(
  7. name: Gochumon wa Usagi Desuka ? Vol.1
  8. price: 819
  9. )EOS");
  10. std::cout << b.name << std::endl;
  11. // => Gochumon wa Usagi Desuka ? Vol.1
  12. std::cout << b.price << " yen" << std::endl;
  13. // => 819 yen

containers

  1. const auto v1 = yamlizer::from_yaml<std::vector<int>>("[0, 1, 2, 3, 4, 5]");
  2. // => std::vector<int>{0, 1, 2, 3, 4 ,5}
  3. const auto m1 = yamlizer::from_yaml<std::map<std::string, int>>(R"EOS(
  4. foo: 123
  5. bar: 456
  6. )EOS");
  7. std::cout << m1.at("foo") << ' ' << m1.at("bar") << std::endl;
  8. // => 123 456

tuple

  1. const auto t = yamlizer::from_yaml<std::tuple<int, float, std::string>>(R"EOS(
  2. - 123
  3. - 1.23
  4. - Hello, World!
  5. )EOS");
  6. // => std::tuple<int, float, std::string>{123, 1.23f, std::string{"Hello, World!"}}

License

MIT