2013-06-12 19:19:05 +00:00
|
|
|
#ifndef SERIALIZE_INTERFACE_H_INCLUDED
|
|
|
|
#define SERIALIZE_INTERFACE_H_INCLUDED
|
|
|
|
|
|
|
|
#include "include/Utils/DataTypes/DataTypes.h"
|
|
|
|
#include "include/Utils/ErrorTypes/ErrorTypes.h"
|
|
|
|
#include "boost/property_tree/ptree.hpp"
|
|
|
|
#include "boost/property_tree/xml_parser.hpp"
|
|
|
|
#include "boost/shared_array.hpp"
|
|
|
|
|
|
|
|
#include "boost/foreach.hpp"
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace SE
|
|
|
|
{
|
|
|
|
|
|
|
|
std::shared_ptr<boost::property_tree::ptree> StringToPropertyTree(std::string xmlCode, std::map<std::string, std::string> replaceMap = std::map<std::string, std::string>());
|
|
|
|
|
|
|
|
std::shared_ptr<boost::property_tree::ptree> FileToPropertyTree(boost::shared_array<char> xmlFileArr, cardinal xmlFileSize, std::map<std::string, std::string> replaceMap = std::map<std::string, std::string>());
|
|
|
|
|
|
|
|
std::shared_ptr<boost::property_tree::ptree> FileToPropertyTree(const std::string& fileName, std::map<std::string, std::string> replaceMap = std::map<std::string, std::string>());
|
|
|
|
|
|
|
|
|
|
|
|
class TSerializeInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void Serialize(boost::property_tree::ptree& propertyTree)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2013-11-11 22:12:29 +00:00
|
|
|
|
|
|
|
template <typename TVALUE>
|
|
|
|
TVALUE GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path)
|
|
|
|
{
|
|
|
|
return subTree.second.get<TVALUE>(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
vec2 GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path);
|
|
|
|
|
|
|
|
template <>
|
|
|
|
vec3 GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path);
|
|
|
|
|
|
|
|
template <>
|
|
|
|
vec4 GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path);
|
2013-06-12 19:19:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
template <typename TKEY, typename TVALUE>
|
|
|
|
class TMapParser : public TSerializeInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::map<TKEY, TVALUE> Map;
|
|
|
|
|
|
|
|
virtual void Serialize(boost::property_tree::ptree& propertyTree)
|
|
|
|
{
|
|
|
|
|
|
|
|
BOOST_FOREACH(boost::property_tree::ptree::value_type& subTree, propertyTree)
|
|
|
|
{
|
|
|
|
TKEY key = subTree.second.get<TKEY>("<xmlattr>.key");
|
2013-11-11 22:12:29 +00:00
|
|
|
TVALUE value = GetValueFromSubtree<TVALUE>(subTree, "<xmlattr>.value");
|
2013-06-12 19:19:05 +00:00
|
|
|
|
|
|
|
Map[key] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename TKEY, typename TVALUE>
|
|
|
|
std::map<TKEY, TVALUE> SerializeToMap(boost::property_tree::ptree& propertyTree)
|
|
|
|
{
|
|
|
|
TMapParser<TKEY, TVALUE> mapParser;
|
|
|
|
mapParser.Serialize(propertyTree);
|
|
|
|
return mapParser.Map;
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace SE
|
|
|
|
|
2013-01-19 20:02:34 +00:00
|
|
|
#endif
|