#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 #include namespace SE { std::shared_ptr StringToPropertyTree(std::string xmlCode, std::map replaceMap = std::map()); std::shared_ptr FileToPropertyTree(boost::shared_array xmlFileArr, cardinal xmlFileSize, std::map replaceMap = std::map()); std::shared_ptr FileToPropertyTree(const std::string& fileName, std::map replaceMap = std::map()); class TSerializeInterface { public: virtual void Serialize(boost::property_tree::ptree& propertyTree) { } }; template TVALUE GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path) { return subTree.second.get(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); template class TMapParser : public TSerializeInterface { public: std::map Map; virtual void Serialize(boost::property_tree::ptree& propertyTree) { BOOST_FOREACH(boost::property_tree::ptree::value_type& subTree, propertyTree) { TKEY key = subTree.second.get(".key"); TVALUE value = GetValueFromSubtree(subTree, ".value"); Map[key] = value; } } }; template std::map SerializeToMap(boost::property_tree::ptree& propertyTree) { TMapParser mapParser; mapParser.Serialize(propertyTree); return mapParser.Map; } } //namespace SE #endif