mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Added reading/writing std::list
This commit is contained in:
@@ -8,8 +8,10 @@
|
||||
|
||||
#include "yaml-cpp/node/node.h"
|
||||
#include "yaml-cpp/node/iterator.h"
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
@@ -83,8 +85,8 @@ namespace YAML
|
||||
struct convert<std::vector<T> > {
|
||||
static Node encode(const std::vector<T>& rhs) {
|
||||
Node node(NodeType::Sequence);
|
||||
for(std::size_t i=0;i<rhs.size();i++)
|
||||
node.append(rhs[i]);
|
||||
for(typename std::vector<T>::const_iterator it=rhs.begin();it!=rhs.end();++it)
|
||||
node.append(*it);
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -98,6 +100,26 @@ namespace YAML
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct convert<std::list<T> > {
|
||||
static Node encode(const std::list<T>& rhs) {
|
||||
Node node(NodeType::Sequence);
|
||||
for(typename std::list<T>::const_iterator it=rhs.begin();it!=rhs.end();++it)
|
||||
node.append(*it);
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, std::list<T>& rhs) {
|
||||
if(node.Type() != NodeType::Sequence)
|
||||
return false;
|
||||
|
||||
rhs.clear();
|
||||
for(const_iterator it=node.begin();it!=node.end();++it)
|
||||
rhs.push_back(it->as<T>());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
Reference in New Issue
Block a user