Skip to content
Snippets Groups Projects
Commit 32689981 authored by Jesse Beder's avatar Jesse Beder
Browse files

Added overloads for parsing stl maps and vectors

parent 083a97b1
No related branches found
Tags release-0.2.5
No related merge requests found
#pragma once
#ifndef STLNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define STLNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#include <vector>
#include <map>
namespace YAML
{
template <typename T>
void operator >> (const Node& node, std::vector<T>& v)
{
v.clear();
v.resize(node.size());
for(unsigned i=0;i<node.size();++i)
node[i] >> v[i];
}
template <typename K, typename V>
void operator >> (const Node& node, std::map<K, V>& m)
{
m.clear();
for(Iterator it=node.begin();it!=node.end();++it) {
K k;
V v;
it.first() >> k;
it.second() >> v;
m[k] = v;
}
}
}
#endif // STLNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
......@@ -6,6 +6,7 @@
#include "parser.h"
#include "node.h"
#include "stlnode.h"
#include "iterator.h"
#include "emitter.h"
#include "stlemitter.h"
......
......@@ -1121,9 +1121,9 @@ namespace Test {
" 0.278";
PARSE(doc, input);
StringMap key;
key._["first"] = "Sammy";
key._["last"] = "Sosa";
std::map<std::string, std::string> key;
key["first"] = "Sammy";
key["last"] = "Sosa";
YAML_ASSERT(doc.size() == 1);
YAML_ASSERT(doc[key].size() == 2);
YAML_ASSERT(doc[key]["hr"] == 65);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment