yaml-cpp

how to set yaml-cpp node style?

这一生的挚爱 提交于 2019-12-06 08:54:40
问题 I have a vector3 class. class vector3 { float x, y, z; } node["x"] = vector3.x; node["y"] = vector3.y; node["z"] = vector3.z; The result is x: 0 y: 0 z: 0 I want the result to be: {x: 0, y: 0, z: 0} If use the old API, I can use YAML::Flow to set the style: YAML::Emitter emitter; out << YAML::Flow << YAML::BeginMap << YAML::Key << "x" << YAML::Value << x << YAML::EndMap Using the new API, how can I set the style? I asked this question on a yaml-cpp project issue page: https://code.google.com

How to set an emit style for a particular yaml-cpp node

不想你离开。 提交于 2019-12-05 15:22:02
I'm emitting a YAML document as follows: YAML::Node doc; // ...populate doc... YAML::Emitter out; out << doc; Somewhere in the hierarchy of nodes I have a particular sequence that I would like to emit in the Flow style while everything else should use the default style settings. I can't seem to find any way of doing this other than emitting by hand every node and watching out for the nodes I'm interested in. This seems like a high price to pay for something relatively straightforward. Ideally I'd like to be able to tag the Node to say "If you get emitted, do so with the following style". But I

how to set yaml-cpp node style?

纵然是瞬间 提交于 2019-12-04 15:13:31
I have a vector3 class. class vector3 { float x, y, z; } node["x"] = vector3.x; node["y"] = vector3.y; node["z"] = vector3.z; The result is x: 0 y: 0 z: 0 I want the result to be: {x: 0, y: 0, z: 0} If use the old API, I can use YAML::Flow to set the style: YAML::Emitter emitter; out << YAML::Flow << YAML::BeginMap << YAML::Key << "x" << YAML::Value << x << YAML::EndMap Using the new API, how can I set the style? I asked this question on a yaml-cpp project issue page: https://code.google.com/p/yaml-cpp/issues/detail?id=186 I got the answer: You can still use the emitter and set the flow style:

yaml-cpp Easiest way to iterate through a map with undefined values

感情迁移 提交于 2019-12-03 19:13:05
问题 I'd like to obtain every node in a map without knowing the keys. My YAML looks like this: characterType : type1 : attribute1 : something attribute2 : something type2 : attribute1 : something attribute2 : something I don't know how many "type"s will be declared or what the name of those keys will be. That's why I'm trying to iterate through the map. struct CharacterType{ std::string attribute1; std::string attribute2; }; namespace YAML{ template<> struct convert<CharacterType>{ static bool

undefined reference to YAML::LoadFile

一个人想着一个人 提交于 2019-12-01 04:34:16
问题 I'm trying to use the new version of libyaml-cpp and having linker problems ( undefined reference to 'YAML::LoadFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' ). I build the library as follows: cmake -DBUILD_SHARED_LIBS=ON .. make sudo make install Then I include yaml-cpp/yaml.h and call YAML::LoadFile( some_string ); . My compilation line is: g++ -L/usr/local/lib -I/usr/local/include -lyaml-cpp -std=c++0x -o $@ $^ I've tried putting the exact .so file in

yaml-cpp read sequence in item

岁酱吖の 提交于 2019-12-01 01:11:23
How can I read this YAML file with yaml-cpp: sensors: - id: 5 hardwareId: 28-000005a32133 type: 1 - id: 6 hardwareId: 28-000005a32132 type: 4 I can't understand how can I get sensors item, to use it. As I understand sensors is a YAML::Node . How can I get it? Update 1: YAML::Node config = YAML::LoadFile(config_path); const YAML::Node& node_test1 = confg["sensors"]; for (std::size_t i = 0; i < node_test1.size(); i++) { const YAML::Node& node_test2 = node_test1[i]; std::cout << "Id: " << node_test2["id"].as<std::string>() << std::endl; std::cout << "hardwareId: " << node_test2["hardwareId"].as

yaml-cpp Easiest way to iterate through a map with undefined values

夙愿已清 提交于 2019-11-30 06:51:56
I'd like to obtain every node in a map without knowing the keys. My YAML looks like this: characterType : type1 : attribute1 : something attribute2 : something type2 : attribute1 : something attribute2 : something I don't know how many "type"s will be declared or what the name of those keys will be. That's why I'm trying to iterate through the map. struct CharacterType{ std::string attribute1; std::string attribute2; }; namespace YAML{ template<> struct convert<CharacterType>{ static bool decode(const Node& node, CharacterType& cType){ cType.attribute1 = node["attribute1"].as<std::string>();

yaml-cpp read sequence in item

会有一股神秘感。 提交于 2019-11-28 02:04:27
问题 How can I read this YAML file with yaml-cpp: sensors: - id: 5 hardwareId: 28-000005a32133 type: 1 - id: 6 hardwareId: 28-000005a32132 type: 4 I can't understand how can I get sensors item, to use it. As I understand sensors is a YAML::Node . How can I get it? Update 1: YAML::Node config = YAML::LoadFile(config_path); const YAML::Node& node_test1 = confg["sensors"]; for (std::size_t i = 0; i < node_test1.size(); i++) { const YAML::Node& node_test2 = node_test1[i]; std::cout << "Id: " << node