【发布时间】:2018-02-07 09:58:25
【问题描述】:
我一直在尝试使用 YAML::Emitter 输出 yaml 文件。例如,我需要这样的东西作为我的 yaml 文件。
annotations:
- run:
type: range based
attributes:
start_frame:
frame_number: 25
end_frame:
frame_number: 39
到目前为止,使用我的代码
for (auto element : obj)
{
basenode = YAML::LoadFile(filePath); //loading a file throws exception when it is not a valid yaml file
//Check if metadata is already there
if (!basenode["file_reference"])
{
writeMetaData(element.getGttStream(), element.getTotalFrames(), element.getFileHash());
}
annotationNode["annotations"].push_back(element.getGestureName());
annotationNode["type"] = "range based";
output << annotationNode;
attributesNode["attributes"]["start_frame"]["frame_number"] = element.getStartFrame();
attributesNode["attributes"]["end_frame"]["frame_number"] = element.getEndFrame();
output << typeNode;
output << attributesNode;
ofs.open(filePath, std::ios_base::app);
ofs << std::endl << output.c_str();
}
我得到这样的输出
annotations:
- run
type: range based
---
attributes:
start_frame:
frame_number: 26
end_frame:
frame_number: 57
我希望将最近推送的序列项下的“类型”和“属性”放入“注释”中,随后对所有以下节点都相同。
我什至尝试过使用类似的东西
annotationNode[0][type] = "基于范围"
输出是这样的
0:类型:“基于范围”
如何获取序列“注释”中最近推送的项目?
【问题讨论】:
-
写完整的例子更有帮助;您的代码相当全面,但没有显示您的变量是什么类型(例如,
annotationNode何时定义?)