|
@@ -19,7 +19,7 @@ You can find examples how to use it in the test case class XMLSerializerTest.
|
|
|
#define XML_SERIALIZER_H
|
|
|
|
|
|
#include <iostream>
|
|
|
-#include <array>
|
|
|
+//#include <array>
|
|
|
#include <vector>
|
|
|
#include <map>
|
|
|
|
|
@@ -31,8 +31,8 @@ You can find examples how to use it in the test case class XMLSerializerTest.
|
|
|
namespace igl
|
|
|
{
|
|
|
|
|
|
- void EncodeXMLElementName(std::string& name);
|
|
|
- //void DecodeXMLElementName(std::string& name);
|
|
|
+ void EncodeXMLElementName(std::string& name);
|
|
|
+ //void DecodeXMLElementName(std::string& name);
|
|
|
void ReplaceSubString(std::string& str, const std::string& search, const std::string& replace);
|
|
|
|
|
|
// Forward declaration
|
|
@@ -99,65 +99,65 @@ namespace igl
|
|
|
* class XMLSerializableObject
|
|
|
* internal usage
|
|
|
*/
|
|
|
- class XMLSerializableObject : public XMLSerializable
|
|
|
- {
|
|
|
- public:
|
|
|
-
|
|
|
- XMLSerializableObject(const std::string& name, const std::string& group);
|
|
|
- virtual ~XMLSerializableObject();
|
|
|
-
|
|
|
- // set attribute conversion functions
|
|
|
- void SetAttribute(tinyxml2::XMLElement* element, const char* name, char& dest);
|
|
|
- void SetAttribute(tinyxml2::XMLElement* element, const char* name, char*& dest);
|
|
|
- void SetAttribute(tinyxml2::XMLElement* element, const char* name, std::string& dest);
|
|
|
- void SetAttribute(tinyxml2::XMLElement* element, const char* name, bool& dest);
|
|
|
- void SetAttribute(tinyxml2::XMLElement* element, const char* name, unsigned int& dest);
|
|
|
- void SetAttribute(tinyxml2::XMLElement* element, const char* name, int& dest);
|
|
|
- void SetAttribute(tinyxml2::XMLElement* element, const char* name, float& dest);
|
|
|
- void SetAttribute(tinyxml2::XMLElement* element, const char* name, double& dest);
|
|
|
-
|
|
|
- // get attribute conversion functions
|
|
|
- void GetAttribute(const char* src, char& dest);
|
|
|
- void GetAttribute(const char* src, char*& dest);
|
|
|
- void GetAttribute(const char* src, std::string& dest);
|
|
|
- void GetAttribute(const char* src, bool& dest);
|
|
|
- void GetAttribute(const char* src, unsigned int& dest);
|
|
|
- void GetAttribute(const char* src, int& dest);
|
|
|
- void GetAttribute(const char* src, float& dest);
|
|
|
- void GetAttribute(const char* src, double& dest);
|
|
|
-
|
|
|
- // Initialization
|
|
|
-
|
|
|
- // Basic data types
|
|
|
+ class XMLSerializableObject : public XMLSerializable
|
|
|
+ {
|
|
|
+ public:
|
|
|
+
|
|
|
+ XMLSerializableObject(const std::string& name, const std::string& group);
|
|
|
+ virtual ~XMLSerializableObject();
|
|
|
+
|
|
|
+ // set attribute conversion functions
|
|
|
+ void SetAttribute(tinyxml2::XMLElement* element, const char* name, char& dest);
|
|
|
+ void SetAttribute(tinyxml2::XMLElement* element, const char* name, char*& dest);
|
|
|
+ void SetAttribute(tinyxml2::XMLElement* element, const char* name, std::string& dest);
|
|
|
+ void SetAttribute(tinyxml2::XMLElement* element, const char* name, bool& dest);
|
|
|
+ void SetAttribute(tinyxml2::XMLElement* element, const char* name, unsigned int& dest);
|
|
|
+ void SetAttribute(tinyxml2::XMLElement* element, const char* name, int& dest);
|
|
|
+ void SetAttribute(tinyxml2::XMLElement* element, const char* name, float& dest);
|
|
|
+ void SetAttribute(tinyxml2::XMLElement* element, const char* name, double& dest);
|
|
|
+
|
|
|
+ // get attribute conversion functions
|
|
|
+ void GetAttribute(const char* src, char& dest);
|
|
|
+ void GetAttribute(const char* src, char*& dest);
|
|
|
+ void GetAttribute(const char* src, std::string& dest);
|
|
|
+ void GetAttribute(const char* src, bool& dest);
|
|
|
+ void GetAttribute(const char* src, unsigned int& dest);
|
|
|
+ void GetAttribute(const char* src, int& dest);
|
|
|
+ void GetAttribute(const char* src, float& dest);
|
|
|
+ void GetAttribute(const char* src, double& dest);
|
|
|
+
|
|
|
+ // Initialization
|
|
|
+
|
|
|
+ // Basic data types
|
|
|
void Init(char& val);
|
|
|
void Init(char*& val);
|
|
|
- void Init(std::string& val);
|
|
|
+ void Init(std::string& val);
|
|
|
void Init(bool& val);
|
|
|
void Init(unsigned int& val);
|
|
|
void Init(int& val);
|
|
|
void Init(float& val);
|
|
|
void Init(double& val);
|
|
|
-
|
|
|
- // XMLSerializable*
|
|
|
- template<typename T>
|
|
|
- void Init(T& obj);
|
|
|
- template<typename T>
|
|
|
- void Init(T*& obj);
|
|
|
-
|
|
|
- // STL containers
|
|
|
- template<typename T, int S>
|
|
|
- void Init(std::array<T,S>& obj);
|
|
|
- template<typename T0, typename T1>
|
|
|
- void Init(std::pair<T0,T1>& obj);
|
|
|
- template<typename T>
|
|
|
- void Init(std::vector<T>& obj);
|
|
|
-
|
|
|
- // Eigen types
|
|
|
- template<typename T, int R, int C>
|
|
|
- void Init(Eigen::Matrix<T,R,C>& obj);
|
|
|
- template<typename T>
|
|
|
- void Init(Eigen::SparseMatrix<T>& obj);
|
|
|
-
|
|
|
+
|
|
|
+ // XMLSerializable*
|
|
|
+ template<typename T>
|
|
|
+ void Init(T& obj);
|
|
|
+ template<typename T>
|
|
|
+ void Init(T*& obj);
|
|
|
+
|
|
|
+ // STL containers
|
|
|
+ /*template<typename T, int S>
|
|
|
+ void Init(std::array<T,S>& obj);*/
|
|
|
+ template<typename T0, typename T1>
|
|
|
+ void Init(std::pair<T0,T1>& obj);
|
|
|
+ template<typename T>
|
|
|
+ void Init(std::vector<T>& obj);
|
|
|
+
|
|
|
+ // Eigen types
|
|
|
+ template<typename T, int R, int C>
|
|
|
+ void Init(Eigen::Matrix<T,R,C>& obj);
|
|
|
+ template<typename T>
|
|
|
+ void Init(Eigen::SparseMatrix<T>& obj);
|
|
|
+
|
|
|
// Serialization
|
|
|
|
|
|
// Basic data types
|
|
@@ -174,44 +174,44 @@ namespace igl
|
|
|
bool Serialize(float& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
bool Serialize(float*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
bool Serialize(double& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
- bool Serialize(double*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
-
|
|
|
- // XMLSerializable*
|
|
|
- template<typename T>
|
|
|
- bool Serialize(T& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
- template<typename T>
|
|
|
- bool Serialize(T*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
-
|
|
|
- // STL containers
|
|
|
- template<typename T, size_t S>
|
|
|
- bool Serialize(std::array<T,S>& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
- template<typename T, size_t S>
|
|
|
- bool Serialize(std::array<T,S>*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
-
|
|
|
- template<typename T0, typename T1>
|
|
|
- bool Serialize(std::pair<T0,T1>& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
- template<typename T0, typename T1>
|
|
|
- bool Serialize(std::pair<T0,T1>*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
-
|
|
|
- template<typename T>
|
|
|
- bool Serialize(std::vector<T>& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
- template<typename T>
|
|
|
- bool Serialize(std::vector<T>*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
-
|
|
|
- // Eigen types
|
|
|
- template<typename T, int R, int C>
|
|
|
- bool Serialize(Eigen::Matrix<T,R,C>& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
- template<typename T, int R, int C>
|
|
|
- bool Serialize(Eigen::Matrix<T,R,C>*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
-
|
|
|
- template<typename T>
|
|
|
- bool Serialize(Eigen::SparseMatrix<T>& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
- template<typename T>
|
|
|
- bool Serialize(Eigen::SparseMatrix<T>*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
-
|
|
|
- // Serialization
|
|
|
-
|
|
|
- // Basic data types
|
|
|
+ bool Serialize(double*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+
|
|
|
+ // XMLSerializable*
|
|
|
+ template<typename T>
|
|
|
+ bool Serialize(T& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+ template<typename T>
|
|
|
+ bool Serialize(T*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+
|
|
|
+ // STL containers
|
|
|
+ /*template<typename T, size_t S>
|
|
|
+ bool Serialize(std::array<T,S>& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+ template<typename T, size_t S>
|
|
|
+ bool Serialize(std::array<T,S>*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);*/
|
|
|
+
|
|
|
+ template<typename T0, typename T1>
|
|
|
+ bool Serialize(std::pair<T0,T1>& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+ template<typename T0, typename T1>
|
|
|
+ bool Serialize(std::pair<T0,T1>*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+
|
|
|
+ template<typename T>
|
|
|
+ bool Serialize(std::vector<T>& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+ template<typename T>
|
|
|
+ bool Serialize(std::vector<T>*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+
|
|
|
+ // Eigen types
|
|
|
+ template<typename T, int R, int C>
|
|
|
+ bool Serialize(Eigen::Matrix<T,R,C>& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+ template<typename T, int R, int C>
|
|
|
+ bool Serialize(Eigen::Matrix<T,R,C>*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+
|
|
|
+ template<typename T>
|
|
|
+ bool Serialize(Eigen::SparseMatrix<T>& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+ template<typename T>
|
|
|
+ bool Serialize(Eigen::SparseMatrix<T>*& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+
|
|
|
+ // Serialization
|
|
|
+
|
|
|
+ // Basic data types
|
|
|
bool Deserialize(char& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
bool Deserialize(char*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
bool Deserialize(std::string& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
@@ -226,46 +226,46 @@ namespace igl
|
|
|
bool Deserialize(float*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
bool Deserialize(double& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
bool Deserialize(double*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
-
|
|
|
- // XMLSerializable*
|
|
|
- template<typename T>
|
|
|
- bool Deserialize(T& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
- template<typename T>
|
|
|
- bool Deserialize(T*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
-
|
|
|
- // STL containers
|
|
|
- template<typename T, size_t S>
|
|
|
- bool Deserialize(std::array<T,S>& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
- template<typename T, size_t S>
|
|
|
- bool Deserialize(std::array<T,S>*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
-
|
|
|
- template<typename T0, typename T1>
|
|
|
- bool Deserialize(std::pair<T0,T1>& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
- template<typename T0, typename T1>
|
|
|
- bool Deserialize(std::pair<T0,T1>*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
-
|
|
|
- template<typename T>
|
|
|
- bool Deserialize(std::vector<T>& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
- template<typename T>
|
|
|
- bool Deserialize(std::vector<T>*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
-
|
|
|
- // Eigen types
|
|
|
- template<typename T, int R, int C>
|
|
|
- bool Deserialize(Eigen::Matrix<T,R,C>& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
- template<typename T, int R, int C>
|
|
|
- bool Deserialize(Eigen::Matrix<T,R,C>*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
-
|
|
|
- template<typename T>
|
|
|
- bool Deserialize(Eigen::SparseMatrix<T>& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
- template<typename T>
|
|
|
- bool Deserialize(Eigen::SparseMatrix<T>*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
-
|
|
|
- private:
|
|
|
-
|
|
|
- template<typename T>
|
|
|
- bool setElementAttribute(T& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
- template<typename T>
|
|
|
- bool getElementAttribute(T& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+
|
|
|
+ // XMLSerializable*
|
|
|
+ template<typename T>
|
|
|
+ bool Deserialize(T& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+ template<typename T>
|
|
|
+ bool Deserialize(T*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+
|
|
|
+ // STL containers
|
|
|
+ /*template<typename T, size_t S>
|
|
|
+ bool Deserialize(std::array<T,S>& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+ template<typename T, size_t S>
|
|
|
+ bool Deserialize(std::array<T,S>*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);*/
|
|
|
+
|
|
|
+ template<typename T0, typename T1>
|
|
|
+ bool Deserialize(std::pair<T0,T1>& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+ template<typename T0, typename T1>
|
|
|
+ bool Deserialize(std::pair<T0,T1>*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+
|
|
|
+ template<typename T>
|
|
|
+ bool Deserialize(std::vector<T>& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+ template<typename T>
|
|
|
+ bool Deserialize(std::vector<T>*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+
|
|
|
+ // Eigen types
|
|
|
+ template<typename T, int R, int C>
|
|
|
+ bool Deserialize(Eigen::Matrix<T,R,C>& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+ template<typename T, int R, int C>
|
|
|
+ bool Deserialize(Eigen::Matrix<T,R,C>*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+
|
|
|
+ template<typename T>
|
|
|
+ bool Deserialize(Eigen::SparseMatrix<T>& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+ template<typename T>
|
|
|
+ bool Deserialize(Eigen::SparseMatrix<T>*& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+
|
|
|
+ private:
|
|
|
+
|
|
|
+ template<typename T>
|
|
|
+ bool setElementAttribute(T& obj, tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element, const std::string& name);
|
|
|
+ template<typename T>
|
|
|
+ bool getElementAttribute(T& obj, tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element, const std::string& name);
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -281,7 +281,7 @@ namespace igl
|
|
|
T DefaultValue;
|
|
|
|
|
|
XMLSerializableInstance(T& obj, const std::string& name, const std::string group);
|
|
|
- XMLSerializableInstance(T& obj, const std::string& name, const std::string group, T defaultValue);
|
|
|
+ XMLSerializableInstance(T& obj, const std::string& name, const std::string group, T defaultValue);
|
|
|
~XMLSerializableInstance();
|
|
|
|
|
|
// XMLSerializable interface implementation
|
|
@@ -409,8 +409,8 @@ namespace igl
|
|
|
bool Add(T& object, const std::string& name, T defaultValue);
|
|
|
|
|
|
// STL containers
|
|
|
- template<typename T, size_t S>
|
|
|
- bool Add(std::array<T,S>& obj, const std::string& name);
|
|
|
+ /*template<typename T, size_t S>
|
|
|
+ bool Add(std::array<T,S>& obj, const std::string& name);*/
|
|
|
template<typename T0, typename T1>
|
|
|
bool Add(std::pair<T0,T1>& obj, const std::string& name);
|
|
|
template<typename T>
|
|
@@ -455,8 +455,8 @@ namespace igl
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-#ifdef IGL_HEADER_ONLY
|
|
|
-#include "XMLSerializer.cpp"
|
|
|
+#ifdef IGL_HEADER_ONLY
|
|
|
+#include "XMLSerializer.cpp"
|
|
|
#endif
|
|
|
|
|
|
#endif
|