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 I'd like to be able to tag the Node to say "If you get emitted, do so with the following style". But I don't think there's any support for this.

Can anyone think of a way around having to emit the whole document by hand?

Many thanks.


回答1:


This feature has already been implemented as pointed out in this question.

You can set the node style with the following code

node.SetStyle(YAML::EmitterStyle::Flow);

or

node.SetStyle(YAML::EmitterStyle::Block);



回答2:


That's currently not possible, but I've submitted it as a feature request:

http://code.google.com/p/yaml-cpp/issues/detail?id=184



来源:https://stackoverflow.com/questions/14282645/how-to-set-an-emit-style-for-a-particular-yaml-cpp-node

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!