Browse Source

Enable igl::xml module.

Former-commit-id: 188f4e7438ea10d69243f51a6bbb30e7eeab79f2
Jérémie Dumas 7 years ago
parent
commit
8ae768c77d

+ 40 - 40
include/igl/xml/XMLSerializable.h

@@ -11,7 +11,7 @@
 // Interface for xml-serializable class see serialize_xml.h
 
 // Pretty sure all of these IGL_INLINE should be inline
- 
+
 namespace igl
 {
   namespace xml
@@ -29,83 +29,83 @@ namespace igl
     class XMLSerializable: public XMLSerializableBase
     {
     private:
-  
+
       template <typename T>
       struct XMLSerializationObject: public XMLSerializableBase
       {
         bool Binary;
         std::string Name;
         T* Object;
-  
+
         void Serialize(std::vector<char>& buffer) const {
           serialize(*Object,Name,buffer);
         }
-  
+
         void Deserialize(const std::vector<char>& buffer) {
           deserialize(*Object,Name,buffer);
         }
-  
+
         void Serialize(tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element) const {
           serialize_xml(*Object,Name,doc,element,Binary);
         }
-  
+
         void Deserialize(const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element) {
           deserialize_xml(*Object,Name,doc,element);
         }
       };
-  
+
       mutable bool initialized;
       mutable std::vector<XMLSerializableBase*> objects;
-  
+
     public:
-  
+
       // Override this function to add your member variables which should be serialized
       IGL_INLINE virtual void InitSerialization() = 0;
-  
+
       // Following functions can be overridden to handle the specific events.
       // Return false to prevent the de-/serialization of an object.
       IGL_INLINE virtual bool PreSerialization() const;
       IGL_INLINE virtual void PostSerialization() const;
       IGL_INLINE virtual bool PreDeserialization();
       IGL_INLINE virtual void PostDeserialization();
-  
+
       // Default implementation of XMLSerializableBase interface
       IGL_INLINE void Serialize(std::vector<char>& buffer) const;
       IGL_INLINE void Deserialize(const std::vector<char>& buffer);
       IGL_INLINE void Serialize(tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element) const;
       IGL_INLINE void Deserialize(const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element);
-  
+
       // Default constructor, destructor, assignment and copy constructor
       IGL_INLINE XMLSerializable();
       IGL_INLINE XMLSerializable(const XMLSerializable& obj);
       IGL_INLINE ~XMLSerializable();
       IGL_INLINE XMLSerializable& operator=(const XMLSerializable& obj);
-  
+
       // Use this function to add your variables which should be serialized
       template <typename T>
       IGL_INLINE void Add(T& obj,std::string name,bool binary = false);
     };
- 
+
     // IMPLEMENTATION
 
     IGL_INLINE bool XMLSerializable::PreSerialization() const
-    { 
+    {
       return true;
     }
-    
+
     IGL_INLINE void XMLSerializable::PostSerialization() const
     {
     }
-    
+
     IGL_INLINE bool XMLSerializable::PreDeserialization()
-    { 
+    {
       return true;
     }
-  
-    IGL_INLINE void XMLSerializable::PostDeserialization() 
+
+    IGL_INLINE void XMLSerializable::PostDeserialization()
     {
     }
-  
+
     IGL_INLINE void XMLSerializable::Serialize(std::vector<char>& buffer) const
     {
       if(this->PreSerialization())
@@ -116,14 +116,14 @@ namespace igl
           (const_cast<XMLSerializable*>(this))->InitSerialization();
           initialized = true;
         }
-  
+
         for(unsigned int i=0;i<objects.size();i++)
           objects[i]->Serialize(buffer);
-  
+
         this->PostSerialization();
       }
     }
-  
+
     IGL_INLINE void XMLSerializable::Deserialize(const std::vector<char>& buffer)
     {
       if(this->PreDeserialization())
@@ -134,14 +134,14 @@ namespace igl
           (const_cast<XMLSerializable*>(this))->InitSerialization();
           initialized = true;
         }
-  
+
         for(unsigned int i=0;i<objects.size();i++)
           objects[i]->Deserialize(buffer);
-  
+
         this->PostDeserialization();
       }
     }
-  
+
     IGL_INLINE void XMLSerializable::Serialize(tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element) const
     {
       if(this->PreSerialization())
@@ -152,14 +152,14 @@ namespace igl
           (const_cast<XMLSerializable*>(this))->InitSerialization();
           initialized = true;
         }
-  
+
         for(unsigned int i=0;i<objects.size();i++)
           objects[i]->Serialize(doc,element);
-  
+
         this->PostSerialization();
       }
     }
-  
+
     IGL_INLINE void XMLSerializable::Deserialize(const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element)
     {
       if(this->PreDeserialization())
@@ -170,32 +170,32 @@ namespace igl
           (const_cast<XMLSerializable*>(this))->InitSerialization();
           initialized = true;
         }
-  
+
         for(unsigned int i=0;i<objects.size();i++)
           objects[i]->Deserialize(doc,element);
-  
+
         this->PostDeserialization();
       }
     }
-  
+
     IGL_INLINE XMLSerializable::XMLSerializable()
     {
       initialized = false;
     }
-  
+
     IGL_INLINE XMLSerializable::XMLSerializable(const XMLSerializable& obj)
     {
       initialized = false;
       objects.clear();
     }
-  
+
     IGL_INLINE XMLSerializable::~XMLSerializable()
     {
       initialized = false;
       objects.clear();
     }
-  
-  
+
+
     IGL_INLINE XMLSerializable& XMLSerializable::operator=(const XMLSerializable& obj)
     {
       if(this != &obj)
@@ -208,7 +208,7 @@ namespace igl
       }
       return *this;
     }
-  
+
     template <typename T>
     IGL_INLINE void XMLSerializable::Add(T& obj,std::string name,bool binary)
     {
@@ -216,10 +216,10 @@ namespace igl
       object->Binary = binary;
       object->Name = name;
       object->Object = &obj;
-  
+
       objects.push_back(object);
     }
-    
+
   }
 }
 #endif

+ 18 - 18
include/igl/xml/serialize_xml.h

@@ -58,7 +58,7 @@ namespace igl
     IGL_INLINE void serialize_xml(
       const T& obj,
       const std::string& objectName,
-      const std::string& filename, 
+      const std::string& filename,
       bool binary = false,
       bool overwrite = false);
     template <typename T>
@@ -68,7 +68,7 @@ namespace igl
       tinyxml2::XMLDocument* doc,
       tinyxml2::XMLElement* element,
       bool binary = false);
-  
+
     // deserializes the given data from a xml file or doc data back to the provided object
     //
     // Templates:
@@ -90,7 +90,7 @@ namespace igl
     IGL_INLINE void deserialize_xml(T& obj,const std::string& objectName,const std::string& filename);
     template <typename T>
     IGL_INLINE void deserialize_xml(T& obj,const std::string& objectName,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element);
-  
+
     // internal functions
     namespace serialization_xml
     {
@@ -99,38 +99,38 @@ namespace igl
       IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value>::type serialize(const T& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
       template <typename T>
       IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value>::type deserialize(T& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
-  
+
       // std::string
       IGL_INLINE void serialize(const std::string& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
       IGL_INLINE void deserialize(std::string& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
-  
+
       // XMLSerializableBase
       template <typename T>
       IGL_INLINE typename std::enable_if<std::is_base_of<XMLSerializableBase,T>::value>::type serialize(const T& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
       template <typename T>
       IGL_INLINE typename std::enable_if<std::is_base_of<XMLSerializableBase,T>::value>::type deserialize(T& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
-  
+
       // STL containers
       template <typename T1, typename T2>
       IGL_INLINE void serialize(const std::pair<T1,T2>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
       template <typename T1,typename T2>
       IGL_INLINE void deserialize(std::pair<T1,T2>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
-  
+
       template <typename T1,typename T2>
       IGL_INLINE void serialize(const std::vector<T1,T2>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
       template <typename T1,typename T2>
       IGL_INLINE void deserialize(std::vector<T1,T2>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
-  
+
       template <typename T>
       IGL_INLINE void serialize(const std::set<T>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
       template <typename T>
       IGL_INLINE void deserialize(std::set<T>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
-  
+
       template <typename T1,typename T2>
       IGL_INLINE void serialize(const std::map<T1,T2>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
       template <typename T1,typename T2>
       IGL_INLINE void deserialize(std::map<T1,T2>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
-  
+
       // Eigen types
 
       // Serialize a Dense Eigen Matrix to xml (in the matrix= attribute,
@@ -143,7 +143,7 @@ namespace igl
       // Outputs:
       //   doc  pointer to xml document
       //   element  pointer to xml element
-      //   
+      //
       template<typename T,int R,int C,int P,int MR,int MC>
       IGL_INLINE void serialize(
         const Eigen::Matrix<T,R,C,P,MR,MC>& obj,
@@ -168,7 +168,7 @@ namespace igl
         const std::string& name,
         const std::function<void(const std::string &,T &)> & from_string,
         Eigen::Matrix<T,R,C,P,MR,MC>& obj);
-  
+
       // Legacy APIs
       template<typename T,int R,int C,int P,int MR,int MC>
       IGL_INLINE void serialize(
@@ -182,18 +182,18 @@ namespace igl
         const tinyxml2::XMLDocument* doc,
         const tinyxml2::XMLElement* element,
         const std::string& name);
-  
+
       template<typename T,int P,typename I>
       IGL_INLINE void serialize(const Eigen::SparseMatrix<T,P,I>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
       template<typename T,int P,typename I>
       IGL_INLINE void deserialize(Eigen::SparseMatrix<T,P,I>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
-  
+
       // raw pointers
       template <typename T>
       IGL_INLINE typename std::enable_if<std::is_pointer<T>::value>::type serialize(const T& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
       template <typename T>
       IGL_INLINE typename std::enable_if<std::is_pointer<T>::value>::type deserialize(T& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
-  
+
       // helper functions
       tinyxml2::XMLElement* getElement(tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
       IGL_INLINE void getAttribute(const char* src,bool& dest);
@@ -210,7 +210,7 @@ namespace igl
       IGL_INLINE void decodeXMLElementName(std::string& name);
       IGL_INLINE std::string base64_encode(unsigned char const* bytes_to_encode,unsigned int in_len);
       IGL_INLINE std::string base64_decode(std::string const& encoded_string);
-  
+
       // compile time type serializable check
       template <typename T>
       struct is_stl_container { static const bool value = false; };
@@ -222,14 +222,14 @@ namespace igl
       struct is_stl_container<std::set<T> > { static const bool value = true; };
       template <typename T1,typename T2>
       struct is_stl_container<std::map<T1,T2> > { static const bool value = true; };
-  
+
       template <typename T>
       struct is_eigen_type { static const bool value = false; };
       template <typename T,int R,int C,int P,int MR,int MC>
       struct is_eigen_type<Eigen::Matrix<T,R,C,P,MR,MC> > { static const bool value = true; };
       template <typename T,int P,typename I>
       struct is_eigen_type<Eigen::SparseMatrix<T,P,I> > { static const bool value = true; };
-  
+
       template <typename T>
       struct is_serializable {
         using T0 = typename  std::remove_pointer<T>::type;

+ 3 - 3
include/igl/xml/writeDAE.cpp

@@ -25,12 +25,12 @@ IGL_INLINE bool igl::xml::writeDAE(
 
   const auto & ele = [&doc](
     const std::string tag,
-    // Can't just use `{}` as the default arguement because of a clang-bug 
+    // Can't just use `{}` as the default arguement because of a clang-bug
     // http://stackoverflow.com/questions/17264067/
-    const std::map<std::string,std::string> attribs = 
+    const std::map<std::string,std::string> attribs =
       std::map<std::string,std::string>(),
     const std::string text="",
-    const std::list<XMLElement *> children = 
+    const std::list<XMLElement *> children =
        std::list<XMLElement *>()
     )->XMLElement *
   {

+ 11 - 15
shared/cmake/libigl.cmake

@@ -403,21 +403,17 @@ endif()
 
 ################################################################################
 ### Compile the xml part ###
-# if(LIBIGL_WITH_XML)
-#   set(TINYXML2_DIR "${LIBIGL_EXTERNAL}/tinyxml2")
-#   add_library(tinyxml2 STATIC ${TINYXML2_DIR}/tinyxml2.cpp ${TINYXML2_DIR}/tinyxml2.h)
-#   set_target_properties(tinyxml2 PROPERTIES
-#           COMPILE_DEFINITIONS "TINYXML2_EXPORT"
-#           VERSION "3.0.0"
-#           SOVERSION "3")
-#   list(APPEND LIBIGL_INCLUDE_DIRS ${TINYXML2_DIR})
-#   list(APPEND LIBIGL_XML_EXTRA_LIBRARIES "tinyxml2")
-#   list(APPEND LIBIGL_EXTRA_LIBRARIES ${LIBIGL_XML_EXTRA_LIBRARIES})
-#   if(LIBIGL_USE_STATIC_LIBRARY)
-#     compile_igl_module("xml" "")
-#     target_include_directories(igl_xml PRIVATE ${TINYXML2_DIR})
-#   endif()
-# endif()
+if(LIBIGL_WITH_XML)
+  set(TINYXML2_DIR "${LIBIGL_EXTERNAL}/tinyxml2")
+  add_library(tinyxml2 STATIC ${TINYXML2_DIR}/tinyxml2.cpp ${TINYXML2_DIR}/tinyxml2.h)
+  target_include_directories(tinyxml2 PUBLIC ${TINYXML2_DIR})
+  set_target_properties(tinyxml2 PROPERTIES
+          COMPILE_DEFINITIONS "TINYXML2_EXPORT"
+          VERSION "3.0.0"
+          SOVERSION "3")
+  compile_igl_module("xml" "")
+  target_link_libraries(igl_xml ${IGL_SCOPE} tinyxml2)
+endif()
 
 # Function to print list nicely
 # function(print_list title list)

+ 1 - 3
tutorial/601_Serialization/CMakeLists.txt

@@ -2,6 +2,4 @@ cmake_minimum_required(VERSION 2.8.12)
 project(601_Serialization)
 
 add_executable(${PROJECT_NAME}_bin main.cpp)
-target_include_directories(${PROJECT_NAME}_bin PRIVATE ${LIBIGL_INCLUDE_DIRS})
-target_compile_definitions(${PROJECT_NAME}_bin PRIVATE ${LIBIGL_DEFINITIONS})
-target_link_libraries(${PROJECT_NAME}_bin ${LIBIGL_LIBRARIES} ${LIBIGL_VIEWER_EXTRA_LIBRARIES} ${LIBIGL_OPENGL_EXTRA_LIBRARIES} ${LIBIGL_OPENGL_GLFW_EXTRA_LIBRARIES} ${LIBIGL_XML_EXTRA_LIBRARIES})
+target_link_libraries(${PROJECT_NAME}_bin igl::core igl::viewer igl::xml tutorials)

+ 3 - 3
tutorial/CMakeLists.txt

@@ -115,9 +115,9 @@ endif()
 
 # Chapter 6
 if(TUTORIALS_CHAPTER6)
-  # if(LIBIGL_WITH_XML)
-  #   add_subdirectory("601_Serialization")
-  # endif()
+  if(LIBIGL_WITH_XML)
+    add_subdirectory("601_Serialization")
+  endif()
   # if(LIBIGL_WITH_MATLAB)
   #   add_subdirectory("602_Matlab")
   # endif()