Added overloads for parsing stl maps and vectors
This commit is contained in:
parent
083a97b171
commit
326899815f
36
include/stlnode.h
Normal file
36
include/stlnode.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#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 "parser.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
#include "stlnode.h"
|
||||||
#include "iterator.h"
|
#include "iterator.h"
|
||||||
#include "emitter.h"
|
#include "emitter.h"
|
||||||
#include "stlemitter.h"
|
#include "stlemitter.h"
|
||||||
|
@ -1121,9 +1121,9 @@ namespace Test {
|
|||||||
" 0.278";
|
" 0.278";
|
||||||
|
|
||||||
PARSE(doc, input);
|
PARSE(doc, input);
|
||||||
StringMap key;
|
std::map<std::string, std::string> key;
|
||||||
key._["first"] = "Sammy";
|
key["first"] = "Sammy";
|
||||||
key._["last"] = "Sosa";
|
key["last"] = "Sosa";
|
||||||
YAML_ASSERT(doc.size() == 1);
|
YAML_ASSERT(doc.size() == 1);
|
||||||
YAML_ASSERT(doc[key].size() == 2);
|
YAML_ASSERT(doc[key].size() == 2);
|
||||||
YAML_ASSERT(doc[key]["hr"] == 65);
|
YAML_ASSERT(doc[key]["hr"] == 65);
|
||||||
|
Loading…
Reference in New Issue
Block a user