yaml-cpp

Save a YAML Emitter content to a file with YAML-CPP

試著忘記壹切 提交于 2019-12-23 10:59:41
问题 I just started playing around with yaml-cpp, I managed to build it properly and run some of the examples from the yaml-cpp wiki but I can't find a way to save my emitter to a file. Is this not possible? I mean the PyYAML library has a 'dump' function for this. Is there no such functionality in yaml-cpp? Is there some workaround to converting a yaml emitter to a stl stream and then dumping this to a yaml file? Please let me know Thanks, Adam 回答1: The function Emitter::c_str() returns a NULL

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

北战南征 提交于 2019-12-22 08:43:52
问题 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

Yaml-cpp (new API) - nested map / sequence combinations and iteration

梦想的初衷 提交于 2019-12-19 10:25:17
问题 I'm having quite fundamental problems with this api's handling of maps vs sequences. Say I have the following structure: foo_map["f1"] = "one"; foo_map["f2"] = "two"; bar_map["b1"] = "one"; bar_map["b2"] = "two"; I want this to be converted to the following YAML file: Node: - Foo: f1 : one f2 : two - Bar: b1 : one b2 : two I would do so by doing: node.push_back("Foo"); node["Foo"]["b1"] = "one"; ... node.push_back("Bar"); However at the last line node has now been converted from a sequence to

How to install and use YAML-Cpp

拥有回忆 提交于 2019-12-13 16:30:11
问题 I want to learn YAML (and use it with C++) but i'm stuck trying to setup YAML-Cpp . Let me explain what i've done so far. I downloaded the source code (version 0.5.1) Installed Cmake (for Windows) Installed the Boost libraries (precompiled for Visual Studio 2010) EDIT: Built the solution and the INSTALL project Then i got two folders on my C drive: include and lib Then i moved it to another folder on my D drive (maybe it's relevant) For testing, i created a project in V Express and tried to

How to dump a digit string with leading zeros, as a valid yaml string in yaml-cpp?

荒凉一梦 提交于 2019-12-11 16:54:41
问题 Creating a yaml string with leading zeros is not escaped with quotes in yaml-cpp. So writing the string to a texfile is not a valid yaml-string. leading_zeros: 00005 is 5 according to the specification yaml 1.2 (Try yourself: http://www.yamllint.com/) YAML::Node node; node["leading_zeros"] = "00005"; std::cout << YAML::Dump(node)<<std::endl; // output: leading_zeros: 00005 // instead of:leading_zeros: "00005" How to bring yaml-cpp to escape a string with leading zeros? So that is would not be

Using YAML-cpp, how to identify unknown keys?

孤人 提交于 2019-12-11 11:57:52
问题 The use case is stepping through a configuration file written in YAML. I need to check each key and parse its value accordingly. I like the idea of using random-access methods like doc["key"] >> value , but what I really need to do is warn the user of unrecognized keys in the config file, in case they, for example, misspelled a key. I don't know how to do that without iterating through the file. I know I can do this using YAML::Iterator , like so for (YAML::Iterator it=doc.begin(); it<doc.end

How to split yaml file into several files?

南笙酒味 提交于 2019-12-11 06:08:29
问题 I have a big (~2Gb) yaml file. I use yaml-cpp library and YAML::Loadfile function. But I have an issue of RAM shortage. What is the easiest way to split this file into several small ones in a way that each small file would be a valid yaml file (maybe by capabilities of linux)? 回答1: If you have multiple documents in your file and then you could split upon --- at the beginning of the line. If you don't have multiple documents (or if you have multiple ones, but they are still too big), your

How to merge node in yaml-cpp

岁酱吖の 提交于 2019-12-08 03:59:59
问题 I have two node object, like this: school: grade: class: name: bob school: grade: class: age: 18 I want to merge it, the result like this: school: grade: class: name: bob age: 18 How to merge it? when the node size and depth do not kown. 回答1: Here is my attempt: #include <yaml-cpp/yaml.h> inline const YAML::Node & cnode(const YAML::Node &n) { return n; } YAML::Node merge_nodes(YAML::Node a, YAML::Node b) { if (!b.IsMap()) { // If b is not a map, merge result is b, unless b is null return b

Compiler error with yaml-cpp - undefined reference to `YAML::detail::node_data::convert_to_map`

只谈情不闲聊 提交于 2019-12-07 18:08:21
问题 Here's the complete log: /tmp/ccCvErNZ.o: In function `YAML::detail::node& YAML::detail::node_data::get<std::string>(std::string const&, std::shared_ptr<YAML::detail::memory_holder>)': cricket.cpp:(.text._ZN4YAML6detail9node_data3getISsEERNS0_4nodeERKT_St10shared_ptrINS0_13memory_holderEE[_ZN4YAML6detail9node_data3getISsEERNS0_4nodeERKT_St10shared_ptrINS0_13memory_holderEE]+0x94): undefined reference to `YAML::detail::node_data::convert_to_map(std::shared_ptr<YAML::detail::memory_holder>)'

How to merge node in yaml-cpp

纵饮孤独 提交于 2019-12-06 15:58:26
I have two node object, like this: school: grade: class: name: bob school: grade: class: age: 18 I want to merge it, the result like this: school: grade: class: name: bob age: 18 How to merge it? when the node size and depth do not kown. Here is my attempt: #include <yaml-cpp/yaml.h> inline const YAML::Node & cnode(const YAML::Node &n) { return n; } YAML::Node merge_nodes(YAML::Node a, YAML::Node b) { if (!b.IsMap()) { // If b is not a map, merge result is b, unless b is null return b.IsNull() ? a : b; } if (!a.IsMap()) { // If a is not a map, merge result is b return b; } if (!b.size()) { //