ソースを参照

gcc fixes for new serializer

Former-commit-id: 4b56eb656cebd71d1d7f9e27c3e488783e1a2f5c
Daniele Panozzo 10 年 前
コミット
ec1576f647

+ 2 - 1
build/Makefile.conf

@@ -106,8 +106,9 @@ endif
 
 ifeq ($(IGL_USERNAME),daniele)
 	IGL_WITH_MATLAB=0
+	IGL_WITH_XML=1
 	AFLAGS=-m64
-	GG=g++-4.8
+	GG=g++-4.8 -Wfatal-errors
 	EIGEN3_INC=-I/usr/local/include/eigen3
 endif
 

+ 14 - 11
build/Makefile_xml

@@ -1,10 +1,10 @@
 include Makefile.conf
 
 .PHONY: all
-all: 
-debug:
-#all: libiglxml
-#debug: libiglxml
+#all:
+#debug:
+all: libiglxml
+debug: libiglxml
 
 include Makefile.conf
 all: CFLAGS += -O3 -DNDEBUG
@@ -13,17 +13,20 @@ debug: CFLAGS += -g -Wall
 .PHONY: libiglxml
 libiglxml: obj ../lib/libiglxml.a
 
-SRC_DIR=../include/igl/xml/
-CPP_FILES=$(wildcard $(SRC_DIR)*.cpp)
+#SRC_DIR=../include/igl/xml/
+#CPP_FILES=$(wildcard $(SRC_DIR)*.cpp)
+CPP_FILES=$(wildcard ../include/igl/xml/*.cpp)
 OBJ_FILES=$(addprefix obj/,$(notdir $(CPP_FILES:.cpp=.o)))
 
 # include igl headers
 INC+=-I../include/
 
-# EXPECTS THAT CFLAGS IS ALREADY SET APPROPRIATELY 
+# EXPECTS THAT CFLAGS IS ALREADY SET APPROPRIATELY
 
 # Eigen dependency
-EIGEN3_INC=-I$(DEFAULT_PREFIX)/include/eigen3 -I$(DEFAULT_PREFIX)/include/eigen3/unsupported
+ifndef EIGEN3_INC
+	EIGEN3_INC=-I$(DEFAULT_PREFIX)/include/eigen3 -I$(DEFAULT_PREFIX)/include/eigen3/unsupported
+endif
 INC+=$(EIGEN3_INC)
 
 #AntTweakbar dependency
@@ -42,15 +45,15 @@ INC+=$(ANTTWEAKBAR_INC)
 
 #CFLAGS+=-std=c++11
 
-obj: 
+obj:
 	mkdir -p obj
 
 ../lib/libiglxml.a: $(OBJ_FILES)
 	rm -f $@
 	ar cqs $@ $(OBJ_FILES)
 
-obj/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/%.h
-	g++ $(AFLAGS) $(CFLAGS) -c -o $@ $< $(INC)
+obj/%.o: ../include/igl/xml/%.cpp ../include/igl/xml/%.h
+	$(GG) $(AFLAGS) $(CFLAGS) -c -o $@ $< $(INC)
 
 clean:
 	rm -f $(OBJ_FILES)

+ 56 - 56
include/igl/serialize.cpp

@@ -1,8 +1,8 @@
-// 
-// Copyright (C) 2014 Christian Schüller <schuellchr@gmail.com>
-// 
-// This Source Code Form is subject to the terms of the Mozilla Public License 
-// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
+//
+// Copyright (C) 2014 Christian Sch�ller <schuellchr@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
 // obtain one at http://mozilla.org/MPL/2.0/.
 
 #include "serialize.h"
@@ -10,10 +10,10 @@
 namespace igl
 {
   template <typename T>
-  void serialize(const T& obj,const std::string& filename)
+  IGL_INLINE void serialize(const T& obj,const std::string& filename)
   {
     std::ofstream fout(filename.c_str(),std::ios::out | std::ios::binary);
-    
+
     if(fout.is_open())
     {
       std::vector<char> buffer;
@@ -25,20 +25,20 @@ namespace igl
     }
     else
     {
-      std::cerr << "Saving binary serialization failed!" << std::endl; 
+      std::cerr << "Saving binary serialization failed!" << std::endl;
     }
   }
 
   template <typename T>
-  void serialize(const T& obj,const std::string& objectName,std::vector<char>& buffer)
+  IGL_INLINE void serialize(const T& obj,const std::string& objectName,std::vector<char>& buffer)
   {
     static_assert(detail::is_serializable<T>::value,"'igl::serialize': type is not serializable");
-    
+
     // serialize object data
     size_t size = detail::getByteSize(obj);
     std::vector<char> tmp(size);
     detail::serialize(obj,tmp,tmp.begin());
-   
+
     std::string objectType(typeid(obj).name());
 
     size_t curSize = buffer.size();
@@ -48,7 +48,7 @@ namespace igl
     buffer.resize(newSize);
 
     std::vector<char>::iterator iter = buffer.begin()+curSize;
-    
+
     // serialize object header (name/type/size)
     detail::serialize(objectName,buffer,iter);
     detail::serialize(objectType,buffer,iter);
@@ -59,7 +59,7 @@ namespace igl
   }
 
   template <typename T>
-  void deserialize(T& obj,const std::string& filename)
+  IGL_INLINE void deserialize(T& obj,const std::string& filename)
   {
     std::ifstream file(filename.c_str(),std::ios::binary);
 
@@ -68,10 +68,10 @@ namespace igl
       file.seekg(0,std::ios::end);
       int size = file.tellg();
       file.seekg(0,std::ios::beg);
-      
+
       std::vector<char> buffer(size);
       file.read(&buffer[0],size);
-      
+
       deserialize(obj,"obj",buffer);
       file.close();
     }
@@ -82,10 +82,10 @@ namespace igl
   }
 
   template <typename T>
-  void deserialize(T& obj,const std::string& objectName,const std::vector<char>& buffer)
+  IGL_INLINE void deserialize(T& obj,const std::string& objectName,const std::vector<char>& buffer)
   {
     static_assert(detail::is_serializable<T>::value,"'igl::deserialize': type is not deserializable");
-    
+
     // find suitable object header
     std::vector<char>::const_iterator iter = buffer.begin();
     while(iter != buffer.end())
@@ -96,7 +96,7 @@ namespace igl
       detail::deserialize(name,iter);
       detail::deserialize(type,iter);
       detail::deserialize(size,iter);
-      
+
       if(name == objectName && type == typeid(obj).name())
         break;
       else
@@ -114,20 +114,20 @@ namespace igl
     // fundamental types
 
     template <typename T>
-    typename std::enable_if_t<std::is_fundamental<T>::value,size_t> getByteSize(const T& obj)
+    IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value,size_t>::type getByteSize(const T& obj)
     {
       return sizeof(T);
     }
 
     template <typename T>
-    std::enable_if_t<std::is_fundamental<T>::value> serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
+    IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
       const uint8_t* ptr = reinterpret_cast<const uint8_t*>(&obj);
       iter = std::copy(ptr,ptr+sizeof(T),iter);
     }
 
     template <typename T>
-    std::enable_if_t<std::is_fundamental<T>::value> deserialize(T& obj,std::vector<char>::const_iterator& iter)
+    IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value>::type deserialize(T& obj,std::vector<char>::const_iterator& iter)
     {
       uint8_t* ptr = reinterpret_cast<uint8_t*>(&obj);
       std::copy(iter,iter+sizeof(T),ptr);
@@ -136,18 +136,18 @@ namespace igl
 
     // std::string
 
-    size_t getByteSize(const std::string& obj)
+    IGL_INLINE size_t getByteSize(const std::string& obj)
     {
       return getByteSize(obj.length())+obj.length()*sizeof(uint8_t);
     }
 
-    void serialize(const std::string& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
+    IGL_INLINE void serialize(const std::string& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
       detail::serialize(obj.length(),buffer,iter);
       for(const auto& cur : obj) { detail::serialize(cur,buffer,iter); }
     }
 
-    void deserialize(std::string& obj,std::vector<char>::const_iterator& iter)
+    IGL_INLINE void deserialize(std::string& obj,std::vector<char>::const_iterator& iter)
     {
       size_t size;
       detail::deserialize(size,iter);
@@ -164,13 +164,13 @@ namespace igl
     // Serializable
 
     template <typename T>
-    typename std::enable_if_t<std::is_base_of<Serializable,T>::value,size_t> getByteSize(const T& obj)
+    IGL_INLINE typename std::enable_if<std::is_base_of<Serializable,T>::value,size_t>::type getByteSize(const T& obj)
     {
       return sizeof(std::vector<char>::size_type);
     }
 
     template <typename T>
-    std::enable_if_t<std::is_base_of<Serializable,T>::value> serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
+    IGL_INLINE typename std::enable_if<std::is_base_of<Serializable,T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
       // data
       std::vector<char> tmp;
@@ -187,7 +187,7 @@ namespace igl
     }
 
     template <typename T>
-    std::enable_if_t<std::is_base_of<Serializable,T>::value> deserialize(T& obj,std::vector<char>::const_iterator& iter)
+    IGL_INLINE typename std::enable_if<std::is_base_of<Serializable,T>::value>::type deserialize(T& obj,std::vector<char>::const_iterator& iter)
     {
       std::vector<char>::size_type size;
       detail::deserialize(size,iter);
@@ -201,24 +201,24 @@ namespace igl
     }
 
     // STL containers
-    
+
     // std::pair
 
     template <typename T1,typename T2>
-    size_t getByteSize(const std::pair<T1,T2>& obj)
+    IGL_INLINE size_t getByteSize(const std::pair<T1,T2>& obj)
     {
       return getByteSize(obj.first)+getByteSize(obj.second);
     }
 
     template <typename T1,typename T2>
-    void serialize(const std::pair<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
+    IGL_INLINE void serialize(const std::pair<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
       detail::serialize(obj.first,buffer,iter);
       detail::serialize(obj.second,buffer,iter);
     }
 
     template <typename T1,typename T2>
-    void deserialize(std::pair<T1,T2>& obj,std::vector<char>::const_iterator& iter)
+    IGL_INLINE void deserialize(std::pair<T1,T2>& obj,std::vector<char>::const_iterator& iter)
     {
       detail::deserialize(obj.first,iter);
       detail::deserialize(obj.second,iter);
@@ -227,13 +227,13 @@ namespace igl
     // std::vector
 
     template <typename T1,typename T2>
-    size_t getByteSize(const std::vector<T1,T2>& obj)
+    IGL_INLINE size_t getByteSize(const std::vector<T1,T2>& obj)
     {
       return std::accumulate(obj.begin(),obj.end(),sizeof(size_t),[](const size_t& acc,const T1& cur) { return acc+getByteSize(cur); });
     }
 
     template <typename T1,typename T2>
-    void serialize(const std::vector<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
+    IGL_INLINE void serialize(const std::vector<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
       size_t size = obj.size();
       detail::serialize(size,buffer,iter);
@@ -244,7 +244,7 @@ namespace igl
     }
 
     template <typename T1,typename T2>
-    void deserialize(std::vector<T1,T2>& obj,std::vector<char>::const_iterator& iter)
+    IGL_INLINE void deserialize(std::vector<T1,T2>& obj,std::vector<char>::const_iterator& iter)
     {
       size_t size;
       detail::deserialize(size,iter);
@@ -259,20 +259,20 @@ namespace igl
     //std::set
 
     template <typename T>
-    size_t getByteSize(const std::set<T>& obj)
+    IGL_INLINE size_t getByteSize(const std::set<T>& obj)
     {
       return std::accumulate(obj.begin(),obj.end(),getByteSize(obj.size()),[](const size_t& acc,const T& cur) { return acc+getByteSize(cur); });
     }
 
     template <typename T>
-    void serialize(const std::set<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
+    IGL_INLINE void serialize(const std::set<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
       detail::serialize(obj.size(),buffer,iter);
       for(const auto& cur : obj) { detail::serialize(cur,buffer,iter); }
     }
 
     template <typename T>
-    void deserialize(std::set<T>& obj,std::vector<char>::const_iterator& iter)
+    IGL_INLINE void deserialize(std::set<T>& obj,std::vector<char>::const_iterator& iter)
     {
       size_t size;
       detail::deserialize(size,iter);
@@ -289,20 +289,20 @@ namespace igl
     // std::map
 
     template <typename T1,typename T2>
-    size_t getByteSize(const std::map<T1,T2>& obj)
+    IGL_INLINE size_t getByteSize(const std::map<T1,T2>& obj)
     {
       return std::accumulate(obj.begin(),obj.end(),sizeof(size_t),[](const size_t& acc,const std::pair<T1,T2>& cur) { return acc+getByteSize(cur); });
     }
 
     template <typename T1,typename T2>
-    void serialize(const std::map<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
+    IGL_INLINE void serialize(const std::map<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
       detail::serialize(obj.size(),buffer,iter);
       for(const auto& cur : obj) { detail::serialize(cur,buffer,iter); }
     }
 
     template <typename T1,typename T2>
-    void deserialize(std::map<T1,T2>& obj,std::vector<char>::const_iterator& iter)
+    IGL_INLINE void deserialize(std::map<T1,T2>& obj,std::vector<char>::const_iterator& iter)
     {
       size_t size;
       detail::deserialize(size,iter);
@@ -318,14 +318,14 @@ namespace igl
 
     // Eigen types
     template<typename T,int R,int C,int P,int MR,int MC>
-    size_t getByteSize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj)
+    IGL_INLINE size_t getByteSize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj)
     {
       // space for numbers of rows,cols and data
       return 2*sizeof(Eigen::Matrix<T,R,C,P,MR,MC>::Index)+sizeof(T)*obj.rows()*obj.cols();
     }
 
     template<typename T,int R,int C,int P,int MR,int MC>
-    void serialize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
+    IGL_INLINE void serialize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
       detail::serialize(obj.rows(),buffer,iter);
       detail::serialize(obj.cols(),buffer,iter);
@@ -335,9 +335,9 @@ namespace igl
     }
 
     template<typename T,int R,int C,int P,int MR,int MC>
-    void deserialize(Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>::const_iterator& iter)
+    IGL_INLINE void deserialize(Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>::const_iterator& iter)
     {
-      Eigen::Matrix<T,R,C,P,MR,MC>::Index rows,cols;
+      typename Eigen::Matrix<T,R,C,P,MR,MC>::Index rows,cols;
       detail::deserialize(rows,iter);
       detail::deserialize(cols,iter);
       size_t size = sizeof(T)*rows*cols;
@@ -348,7 +348,7 @@ namespace igl
     }
 
     template<typename T,int P,typename I>
-    size_t getByteSize(const Eigen::SparseMatrix<T,P,I>& obj)
+    IGL_INLINE size_t getByteSize(const Eigen::SparseMatrix<T,P,I>& obj)
     {
       // space for numbers of rows,cols,nonZeros and tripplets with data (rowIdx,colIdx,value)
       size_t size = sizeof(Eigen::SparseMatrix<T,P,I>::Index);
@@ -356,7 +356,7 @@ namespace igl
     }
 
     template<typename T,int P,typename I>
-    void serialize(const Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
+    IGL_INLINE void serialize(const Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
       detail::serialize(obj.rows(),buffer,iter);
       detail::serialize(obj.cols(),buffer,iter);
@@ -374,9 +374,9 @@ namespace igl
     }
 
     template<typename T,int P,typename I>
-    void deserialize(Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>::const_iterator& iter)
+    IGL_INLINE void deserialize(Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>::const_iterator& iter)
     {
-      Eigen::SparseMatrix<T,P,I>::Index rows,cols,nonZeros;
+      typename Eigen::SparseMatrix<T,P,I>::Index rows,cols,nonZeros;
       detail::deserialize(rows,iter);
       detail::deserialize(cols,iter);
       detail::deserialize(nonZeros,iter);
@@ -387,7 +387,7 @@ namespace igl
       std::vector<Eigen::Triplet<T,I> > triplets;
       for(int i=0;i<nonZeros;i++)
       {
-        Eigen::SparseMatrix<T,P,I>::Index rowId,colId;
+        typename Eigen::SparseMatrix<T,P,I>::Index rowId,colId;
         detail::deserialize(rowId,iter);
         detail::deserialize(colId,iter);
         T value;
@@ -400,7 +400,7 @@ namespace igl
     // pointers
 
     template <typename T>
-    std::enable_if_t<std::is_pointer<T>::value,size_t> getByteSize(const T& obj)
+    IGL_INLINE typename std::enable_if<std::is_pointer<T>::value,size_t>::type getByteSize(const T& obj)
     {
       bool isNullPtr = (obj == NULL);
 
@@ -413,18 +413,18 @@ namespace igl
     }
 
     template <typename T>
-    std::enable_if_t<std::is_pointer<T>::value> serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
+    IGL_INLINE typename std::enable_if<std::is_pointer<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
       bool isNullPtr = (obj == NULL);
 
       detail::serialize(isNullPtr,buffer,iter);
 
-      if(isNullPtr == false) 
+      if(isNullPtr == false)
         detail::serialize(*obj,buffer,iter);
     }
 
     template <typename T>
-    std::enable_if_t<std::is_pointer<T>::value> deserialize(T& obj,std::vector<char>::const_iterator& iter)
+    IGL_INLINE typename std::enable_if<std::is_pointer<T>::value>::type deserialize(T& obj,std::vector<char>::const_iterator& iter)
     {
       bool isNullPtr;
       detail::deserialize(isNullPtr,iter);
@@ -441,11 +441,11 @@ namespace igl
       {
         if(obj != NULL)
           std::cout << "deserialization: possible memory leak for '" << typeid(obj).name() << "'" << std::endl;
-        
-        obj = new std::remove_pointer<T>::type();
+
+        obj = new typename std::remove_pointer<T>::type();
 
         detail::deserialize(*obj,iter);
       }
     }
   }
-}
+}

+ 50 - 47
include/igl/serialize.h

@@ -1,8 +1,8 @@
-// 
-// Copyright (C) 2014 Christian Schüller <schuellchr@gmail.com>
-// 
-// This Source Code Form is subject to the terms of the Mozilla Public License 
-// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
+//
+// Copyright (C) 2014 Christian Sch�ller <schuellchr@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
 // obtain one at http://mozilla.org/MPL/2.0/.
 // -----------------------------------------------------------------------------
 // Functions to save and load a serialization of fundamental c++ data types to
@@ -19,13 +19,14 @@
 
 #ifndef IGL_SERIALIZE_H
 #define IGL_SERIALIZE_H
-
+#include "igl_inline.h"
 #include <type_traits>
 #include <iostream>
 #include <numeric>
 #include <vector>
 #include <set>
 #include <map>
+#include <fstream>
 
 #include <Eigen/Dense>
 #include <Eigen/Sparse>
@@ -43,13 +44,13 @@ namespace igl
   //   obj        object to serialize
   //   objectName unique object name,used for the identification
   //   filename   name of the file containing the serialization
-  // Outputs: 
+  // Outputs:
   //   buffer     binary serialization
   //
   template <typename T>
-  void serialize(const T& obj,const std::string& filename);
+  IGL_INLINE void serialize(const T& obj,const std::string& filename);
   template <typename T>
-  void serialize(const T& obj,const std::string& objectName,std::vector<char>& buffer);
+  IGL_INLINE void serialize(const T& obj,const std::string& objectName,std::vector<char>& buffer);
 
   // deserializes the given data from a file or buffer back to the provided object
   //
@@ -59,13 +60,13 @@ namespace igl
   //   buffer     binary serialization
   //   objectName unique object name, used for the identification
   //   filename   name of the file containing the serialization
-  // Outputs: 
-  //   obj        object to load back serialization to 
+  // Outputs:
+  //   obj        object to load back serialization to
   //
   template <typename T>
-  void deserialize(T& obj,const std::string& filename);
+  IGL_INLINE void deserialize(T& obj,const std::string& filename);
   template <typename T>
-  void deserialize(T& obj,const std::string& objectName,const std::vector<char>& buffer);
+  IGL_INLINE void deserialize(T& obj,const std::string& objectName,const std::vector<char>& buffer);
 
   // interface for user defined types
   struct Serializable
@@ -76,9 +77,9 @@ namespace igl
   // example:
   //
   // class Test : public igl::Serializable {
-  //   
+  //
   //   int var;
-  // 
+  //
   //   void Serialize(std::vector<char>& buffer) {
   //     serialize(var,"var1",buffer);
   //   }
@@ -92,80 +93,80 @@ namespace igl
   {
     // fundamental types
     template <typename T>
-    std::enable_if_t<std::is_fundamental<T>::value,size_t> getByteSize(const T& obj);
+    IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value,size_t>::type getByteSize(const T& obj);
     template <typename T>
-    std::enable_if_t<std::is_fundamental<T>::value> serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
+    IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T>
-    std::enable_if_t<std::is_fundamental<T>::value> deserialize(T& obj,std::vector<char>::const_iterator& iter);
+    IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value>::type deserialize(T& obj,std::vector<char>::const_iterator& iter);
 
     // std::string
-    size_t getByteSize(const std::string& obj);
-    void serialize(const std::string& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
-    void deserialize(std::string& obj,std::vector<char>::iterator& iter);
+    IGL_INLINE size_t getByteSize(const std::string& obj);
+    IGL_INLINE void serialize(const std::string& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
+    IGL_INLINE void deserialize(std::string& obj,std::vector<char>::const_iterator& iter);
 
     // Serializable
     template <typename T>
-    std::enable_if_t<std::is_base_of<Serializable,T>::value,size_t> getByteSize(const T& obj);
+    IGL_INLINE typename std::enable_if<std::is_base_of<Serializable,T>::value,size_t>::type getByteSize(const T& obj);
     template <typename T>
-    std::enable_if_t<std::is_base_of<Serializable,T>::value> serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
+    IGL_INLINE typename std::enable_if<std::is_base_of<Serializable,T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T>
-    std::enable_if_t<std::is_base_of<Serializable,T>::value> deserialize(T& obj,std::vector<char>::const_iterator& iter);
+    IGL_INLINE typename std::enable_if<std::is_base_of<Serializable,T>::value>::type deserialize(T& obj,std::vector<char>::const_iterator& iter);
 
     // stl containers
     // std::pair
     template <typename T1,typename T2>
-    size_t getByteSize(const std::pair<T1,T2>& obj);
+    IGL_INLINE size_t getByteSize(const std::pair<T1,T2>& obj);
     template <typename T1,typename T2>
-    void serialize(const std::pair<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
+    IGL_INLINE void serialize(const std::pair<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T1,typename T2>
-    void deserialize(std::pair<T1,T2>& obj,std::vector<char>::const_iterator& iter);
+    IGL_INLINE void deserialize(std::pair<T1,T2>& obj,std::vector<char>::const_iterator& iter);
 
     // std::vector
     template <typename T1,typename T2>
-    size_t getByteSize(const std::vector<T1,T2>& obj);
+    IGL_INLINE size_t getByteSize(const std::vector<T1,T2>& obj);
     template <typename T1,typename T2>
-    void serialize(const std::vector<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
+    IGL_INLINE void serialize(const std::vector<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T1,typename T2>
-    void deserialize(std::vector<T1,T2>& obj,std::vector<char>::const_iterator& iter);
+    IGL_INLINE void deserialize(std::vector<T1,T2>& obj,std::vector<char>::const_iterator& iter);
 
     // std::set
     template <typename T>
-    size_t getByteSize(const std::set<T>& obj);
+    IGL_INLINE size_t getByteSize(const std::set<T>& obj);
     template <typename T>
-    void serialize(const std::set<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
+    IGL_INLINE void serialize(const std::set<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T>
-    void deserialize(std::set<T>& obj,std::vector<char>::const_iterator& iter);
+    IGL_INLINE void deserialize(std::set<T>& obj,std::vector<char>::const_iterator& iter);
 
     // std::map
     template <typename T1,typename T2>
-    size_t getByteSize(const std::map<T1,T2>& obj);
+    IGL_INLINE size_t getByteSize(const std::map<T1,T2>& obj);
     template <typename T1,typename T2>
-    void serialize(const std::map<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
+    IGL_INLINE void serialize(const std::map<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T1,typename T2>
-    void deserialize(std::map<T1,T2>& obj,std::vector<char>::const_iterator& iter);
+    IGL_INLINE void deserialize(std::map<T1,T2>& obj,std::vector<char>::const_iterator& iter);
 
     // Eigen types
     template<typename T,int R,int C,int P,int MR,int MC>
-    size_t getByteSize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj);
+    IGL_INLINE size_t getByteSize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj);
     template<typename T,int R,int C,int P,int MR,int MC>
-    void serialize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
+    IGL_INLINE void serialize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template<typename T,int R,int C,int P,int MR,int MC>
-    void deserialize(Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>::const_iterator& iter);
+    IGL_INLINE void deserialize(Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>::const_iterator& iter);
 
     template<typename T,int P,typename I>
-    size_t getByteSize(const Eigen::SparseMatrix<T,P,I>& obj);
+    IGL_INLINE size_t getByteSize(const Eigen::SparseMatrix<T,P,I>& obj);
     template<typename T,int P,typename I>
-    void serialize(const Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
+    IGL_INLINE void serialize(const Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template<typename T,int P,typename I>
-    void deserialize(Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>::const_iterator& iter);
+    IGL_INLINE void deserialize(Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>::const_iterator& iter);
 
     // pointers
     template <typename T>
-    std::enable_if_t<std::is_pointer<T>::value,size_t> getByteSize(const T& obj);
+    IGL_INLINE typename std::enable_if<std::is_pointer<T>::value,size_t>::type getByteSize(const T& obj);
     template <typename T>
-    std::enable_if_t<std::is_pointer<T>::value> serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
+    IGL_INLINE typename std::enable_if<std::is_pointer<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T>
-    std::enable_if_t<std::is_pointer<T>::value> deserialize(T& obj,std::vector<char>::const_iterator& iter);
+    IGL_INLINE typename std::enable_if<std::is_pointer<T>::value>::type deserialize(T& obj,std::vector<char>::const_iterator& iter);
 
     // compile time type serializable check
     template <typename T>
@@ -195,6 +196,8 @@ namespace igl
   }
 }
 
-#include "serialize.cpp"
+#ifndef IGL_STATIC_LIBRARY
+  #include "serialize.cpp"
+#endif
 
-#endif
+#endif

+ 52 - 52
include/igl/xml/serialize_xml.cpp

@@ -1,8 +1,8 @@
-// 
-// Copyright (C) 2014 Christian Schüller <schuellchr@gmail.com>
-// 
-// This Source Code Form is subject to the terms of the Mozilla Public License 
-// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
+//
+// Copyright (C) 2014 Christian Sch�ller <schuellchr@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
 // obtain one at http://mozilla.org/MPL/2.0/.
 
 #include "serialize_xml.h"
@@ -10,13 +10,13 @@
 namespace igl
 {
   template <typename T>
-  void serialize_xml(const T& obj,const std::string& filename)
+  IGL_INLINE void serialize_xml(const T& obj,const std::string& filename)
   {
     serialize_xml(obj,"object",filename,0);
   }
 
   template <typename T>
-  void serialize_xml(const T& obj,const std::string& objectName,const std::string& filename,bool binary,bool overwrite)
+  IGL_INLINE void serialize_xml(const T& obj,const std::string& objectName,const std::string& filename,bool binary,bool overwrite)
   {
     tinyxml2::XMLDocument* doc = new tinyxml2::XMLDocument();
 
@@ -50,7 +50,7 @@ namespace igl
   }
 
   template <typename T>
-  void serialize_xml(const T& obj,const std::string& objectName,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,bool binary)
+  IGL_INLINE void serialize_xml(const T& obj,const std::string& objectName,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,bool binary)
   {
     static_assert(detail_xml::is_serializable<T>::value,"'igl::serialize_xml': type is not serializable");
 
@@ -75,13 +75,13 @@ namespace igl
   }
 
   template <typename T>
-  void deserialize_xml(T& obj,const std::string& filename)
+  IGL_INLINE void deserialize_xml(T& obj,const std::string& filename)
   {
     deserialize_xml(obj,"object",filename);
   }
 
   template <typename T>
-  void deserialize_xml(T& obj,const std::string& objectName,const std::string& filename)
+  IGL_INLINE void deserialize_xml(T& obj,const std::string& objectName,const std::string& filename)
   {
     tinyxml2::XMLDocument* doc = new tinyxml2::XMLDocument();
 
@@ -110,7 +110,7 @@ namespace igl
   }
 
   template <typename T>
-  inline void deserialize_xml(T& obj,const std::string& objectName,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element)
+  IGL_INLINE void deserialize_xml(T& obj,const std::string& objectName,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element)
   {
     static_assert(detail::is_serializable<T>::value,"'igl::deserialize_xml': type is not deserializable");
 
@@ -130,7 +130,7 @@ namespace igl
 
         std::vector<char> buffer;
         std::copy(decoded.c_str(),decoded.c_str()+decoded.length(),std::back_inserter(buffer));
-        
+
         deserialize(obj,name,buffer);
       }
       else
@@ -145,14 +145,14 @@ namespace igl
     // fundamental types
 
     template <typename T>
-    std::enable_if_t<std::is_fundamental<T>::value> serialize(const T& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
+    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)
     {
       tinyxml2::XMLElement* child = getElement(doc,element,name.c_str());
       child->SetAttribute("val",obj);
     }
 
     template <typename T>
-    std::enable_if_t<std::is_fundamental<T>::value> deserialize(T& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
+    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)
     {
       const tinyxml2::XMLElement* child = element->FirstChildElement(name.c_str());
       if(child != NULL)
@@ -167,13 +167,13 @@ namespace igl
 
     // std::string
 
-    void serialize(const std::string& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE void serialize(const std::string& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
     {
       tinyxml2::XMLElement* child = getElement(doc,element,name.c_str());
       child->SetAttribute("val",obj.c_str());
     }
 
-    void deserialize(std::string& obj,const tinyxml2::XMLDocument* doc,const 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)
     {
       const tinyxml2::XMLElement* child = element->FirstChildElement(name.c_str());
       if(child != NULL)
@@ -189,7 +189,7 @@ namespace igl
     // Serializable
 
     template <typename T>
-    std::enable_if_t<std::is_base_of<XMLSerializable,T>::value> serialize(const T& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE typename std::enable_if<std::is_base_of<XMLSerializable,T>::value>::type serialize(const T& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
     {
       // Serialize object implementing Serializable interface
       const XMLSerializable& object = dynamic_cast<const XMLSerializable&>(obj);
@@ -199,7 +199,7 @@ namespace igl
     }
 
     template <typename T>
-    std::enable_if_t<std::is_base_of<XMLSerializable,T>::value> deserialize(T& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE typename std::enable_if<std::is_base_of<XMLSerializable,T>::value>::type deserialize(T& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
     {
       const tinyxml2::XMLElement* child = element->FirstChildElement(name.c_str());
 
@@ -216,7 +216,7 @@ namespace igl
     // STL containers
 
     template <typename T1,typename T2>
-    void serialize(const std::pair<T1,T2>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE void serialize(const std::pair<T1,T2>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
     {
       tinyxml2::XMLElement* pair = getElement(doc,element,name.c_str());
       serialize(obj.first,doc,pair,"first");
@@ -224,7 +224,7 @@ namespace igl
     }
 
     template <typename T1,typename T2>
-    void deserialize(std::pair<T1,T2>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE void deserialize(std::pair<T1,T2>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
     {
       const tinyxml2::XMLElement* child = element->FirstChildElement(name.c_str());
       if(child != NULL)
@@ -240,7 +240,7 @@ namespace igl
     }
 
     template <typename T1,typename T2>
-    void serialize(const std::vector<T1,T2>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE void serialize(const std::vector<T1,T2>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
     {
       tinyxml2::XMLElement* vector = getElement(doc,element,name.c_str());
       vector->SetAttribute("size",(unsigned int)obj.size());
@@ -255,7 +255,7 @@ namespace igl
     }
 
     template <typename T1,typename T2>
-    void deserialize(std::vector<T1,T2>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE void deserialize(std::vector<T1,T2>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
     {
       obj.clear();
 
@@ -281,7 +281,7 @@ namespace igl
     }
 
     template <typename T>
-    void serialize(const std::set<T>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE void serialize(const std::set<T>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
     {
       tinyxml2::XMLElement* set = getElement(doc,element,name.c_str());
       set->SetAttribute("size",(unsigned int)obj.size());
@@ -297,7 +297,7 @@ namespace igl
     }
 
     template <typename T>
-    void deserialize(std::set<T>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE void deserialize(std::set<T>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
     {
       obj.clear();
 
@@ -325,7 +325,7 @@ namespace igl
     }
 
     template <typename T1,typename T2>
-    void serialize(const std::map<T1,T2>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE void serialize(const std::map<T1,T2>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
     {
       tinyxml2::XMLElement* map = getElement(doc,element,name.c_str());
       map->SetAttribute("size",(unsigned int)obj.size());
@@ -341,7 +341,7 @@ namespace igl
     }
 
     template <typename T1,typename T2>
-    void deserialize(std::map<T1,T2>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE void deserialize(std::map<T1,T2>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
     {
       obj.clear();
 
@@ -370,7 +370,7 @@ namespace igl
 
     // Eigen types
     template<typename T,int R,int C,int P,int MR,int MC>
-    void serialize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE void serialize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
     {
       tinyxml2::XMLElement* matrix = getElement(doc,element,name.c_str());
 
@@ -401,7 +401,7 @@ namespace igl
     }
 
     template<typename T,int R,int C,int P,int MR,int MC>
-    void deserialize(Eigen::Matrix<T,R,C,P,MR,MC>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE void deserialize(Eigen::Matrix<T,R,C,P,MR,MC>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
     {
       const tinyxml2::XMLElement* child = element->FirstChildElement(name.c_str());
       bool initialized = false;
@@ -460,7 +460,7 @@ namespace igl
     }
 
     template<typename T,int P,typename I>
-    void serialize(const Eigen::SparseMatrix<T,P,I>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE void serialize(const Eigen::SparseMatrix<T,P,I>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
     {
       tinyxml2::XMLElement* matrix = getElement(doc,element,name.c_str());
 
@@ -490,7 +490,7 @@ namespace igl
     }
 
     template<typename T,int P,typename I>
-    void deserialize(Eigen::SparseMatrix<T,P,I>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE void deserialize(Eigen::SparseMatrix<T,P,I>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
     {
       const tinyxml2::XMLElement* child = element->FirstChildElement(name.c_str());
       bool initialized = false;
@@ -556,7 +556,7 @@ namespace igl
     // pointers
 
     template <typename T>
-    std::enable_if_t<std::is_pointer<T>::value> serialize(const T& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
+    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)
     {
       tinyxml2::XMLElement* pointer = getElement(doc,element,name.c_str());
 
@@ -569,7 +569,7 @@ namespace igl
     }
 
     template <typename T>
-    std::enable_if_t<std::is_pointer<T>::value> deserialize(T& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name)
+    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)
     {
       const tinyxml2::XMLElement* child = element->FirstChildElement(name.c_str());
       if(child != NULL)
@@ -588,8 +588,8 @@ namespace igl
         {
           if(obj != NULL)
             std::cout << "deserialization: possible memory leak for '" << typeid(obj).name() << "'" << std::endl;
-          
-          obj = new std::remove_pointer<T>::type();
+
+          obj = new typename std::remove_pointer<T>::type();
 
           detail_xml::deserialize(*obj,doc,element,name);
         }
@@ -598,7 +598,7 @@ namespace igl
 
     // helper functions
 
-    tinyxml2::XMLElement* getElement(tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
+    IGL_INLINE tinyxml2::XMLElement* getElement(tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name)
     {
       tinyxml2::XMLElement* child = element->FirstChildElement(name.c_str());
       if(child == NULL)
@@ -609,41 +609,41 @@ namespace igl
       return child;
     }
 
-    void getAttribute(const char* src,bool& dest)
+    IGL_INLINE void getAttribute(const char* src,bool& dest)
     {
       tinyxml2::XMLUtil::ToBool(src,&dest);
     }
 
-    void getAttribute(const char* src,char& dest)
+    IGL_INLINE void getAttribute(const char* src,char& dest)
     {
       dest = (char)atoi(src);
     }
 
-    void getAttribute(const char* src,std::string& dest)
+    IGL_INLINE void getAttribute(const char* src,std::string& dest)
     {
       dest = src;
     }
 
-    void getAttribute(const char* src,float& dest)
+    IGL_INLINE void getAttribute(const char* src,float& dest)
     {
       tinyxml2::XMLUtil::ToFloat(src,&dest);
     }
 
-    void getAttribute(const char* src,double& dest)
+    IGL_INLINE void getAttribute(const char* src,double& dest)
     {
       tinyxml2::XMLUtil::ToDouble(src,&dest);
     }
 
-    template<typename T>
-    std::enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value> getAttribute(const char* src,T& dest)
+    IGL_INLINE template<typename T>
+    typename std::enable_if<std::is_integral<T>::value && std::is_unsigned<T>::value>::type getAttribute(const char* src,T& dest)
     {
       unsigned int val;
       tinyxml2::XMLUtil::ToUnsigned(src,&val);
       dest = (T)val;
     }
 
-    template<typename T>
-    std::enable_if_t<std::is_integral<T>::value && !std::is_unsigned<T>::value> getAttribute(const char* src,T& dest)
+    IGL_INLINE template<typename T>
+    typename std::enable_if<std::is_integral<T>::value && !std::is_unsigned<T>::value>::type getAttribute(const char* src,T& dest)
     {
       int val;
       tinyxml2::XMLUtil::ToInt(src,&val);
@@ -654,7 +654,7 @@ namespace igl
     static const int numForbiddenChars = 8;
     static const char forbiddenChars[] ={' ','/','~','#','&','>','<','='};
 
-    void replaceSubString(std::string& str,const std::string& search,const std::string& replace)
+    IGL_INLINE void replaceSubString(std::string& str,const std::string& search,const std::string& replace)
     {
       size_t pos = 0;
       while((pos = str.find(search,pos)) != std::string::npos)
@@ -664,7 +664,7 @@ namespace igl
       }
     }
 
-    void encodeXMLElementName(std::string& name)
+    IGL_INLINE void encodeXMLElementName(std::string& name)
     {
       // must not start with a digit
       if(isdigit(*name.begin()))
@@ -685,7 +685,7 @@ namespace igl
       }
     }
 
-    void decodeXMLElementName(std::string& name)
+    IGL_INLINE void decodeXMLElementName(std::string& name)
     {
       if(name.find("::",0) == 0)
         name.replace(0,3,"");
@@ -702,7 +702,7 @@ namespace igl
       }
     }
 
-   /* Copyright(C) 2004-2008 René Nyffenegger
+   /* Copyright(C) 2004-2008 Ren� Nyffenegger
 
       This source code is provided 'as-is',without any express or implied
       warranty.In no event will the author be held liable for any damages
@@ -722,7 +722,7 @@ namespace igl
 
       3. This notice may not be removed or altered from any source distribution.
 
-      René Nyffenegger rene.nyffenegger@adp-gmbh.ch
+      Ren� Nyffenegger rene.nyffenegger@adp-gmbh.ch
       */
 
     static const std::string base64_chars =
@@ -787,9 +787,9 @@ namespace igl
       std::string ret;
 
       // construct fast lookup table
-      // added by Christian Schüller (schuellc@inf.ethz.ch)
+      // added by Christian Sch�ller (schuellc@inf.ethz.ch)
       int charLookup[200];
-      for(int i=0;i<base64_chars.length();i++)
+      for(int i=0;i<(int)(base64_chars.length());i++)
         charLookup[(int)base64_chars[i]] = i;
 
       while(in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
@@ -828,4 +828,4 @@ namespace igl
       return ret;
     }
   }
-}
+}

+ 54 - 50
include/igl/xml/serialize_xml.h

@@ -1,8 +1,8 @@
-// 
-// Copyright (C) 2014 Christian Schüller <schuellchr@gmail.com>
-// 
-// This Source Code Form is subject to the terms of the Mozilla Public License 
-// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
+//
+// Copyright (C) 2014 Christian Sch�ller <schuellchr@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
 // obtain one at http://mozilla.org/MPL/2.0/.
 // -----------------------------------------------------------------------------
 // Functions to save and load a serialization of fundamental c++ data types to
@@ -16,6 +16,8 @@
 #ifndef IGL_SERIALIZABLE_XML_H
 #define IGL_SERIALIZABLE_XML_H
 
+#include "../igl_inline.h"
+
 #include <type_traits>
 #include <iostream>
 #include <vector>
@@ -45,15 +47,15 @@ namespace igl
   //   binary     set to true to serialize the object in binary format (faster for big data)
   //   overwrite  set to true to update the serialization in an existing xml file
   //   element    tinyxml2 virtual representation of the current xml node
-  // Outputs: 
+  // Outputs:
   //   doc        contains current tinyxml2 virtual representation of the xml data
   //
   template <typename T>
-  void serialize_xml(const T& obj,const std::string& filename);
+  IGL_INLINE void serialize_xml(const T& obj,const std::string& filename);
   template <typename T>
-  void serialize_xml(const T& obj,const std::string& objectName,const std::string& filename, bool binary = false,bool overwrite = false);
+  IGL_INLINE void serialize_xml(const T& obj,const std::string& objectName,const std::string& filename, bool binary = false,bool overwrite = false);
   template <typename T>
-  void serialize_xml(const T& obj,const std::string& objectName,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,bool binary = false);
+  IGL_INLINE void serialize_xml(const T& obj,const std::string& objectName,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
   //
@@ -67,15 +69,15 @@ namespace igl
   //   overwrite  set to true to update the serialization in an existing xml file
   //   doc        contains current tinyxml2 virtual representation of the xml data
   //   element    tinyxml2 virtual representation of the current xml node
-  // Outputs: 
-  //   obj        object to load back serialization to 
+  // Outputs:
+  //   obj        object to load back serialization to
   //
   template <typename T>
-  void deserialize_xml(T& obj,const std::string& filename);
+  IGL_INLINE void deserialize_xml(T& obj,const std::string& filename);
   template <typename T>
-  void deserialize_xml(T& obj,const std::string& objectName,const std::string& filename);
+  IGL_INLINE void deserialize_xml(T& obj,const std::string& objectName,const std::string& filename);
   template <typename T>
-  void deserialize_xml(T& obj,const std::string& objectName,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element);
+  IGL_INLINE void deserialize_xml(T& obj,const std::string& objectName,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element);
 
   // interface for user defined types
   struct XMLSerializable : public Serializable
@@ -88,9 +90,9 @@ namespace igl
   // example:
   //
   // class Test : public igl::Serializable {
-  //   
+  //
   //   int var;
-  // 
+  //
   //   void Serialize(std::vector<char>& buffer) {
   //     serialize(var,"var1",buffer);
   //   }
@@ -110,74 +112,74 @@ namespace igl
   {
     // fundamental types
     template <typename T>
-    std::enable_if_t<std::is_fundamental<T>::value> serialize(const T& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
+    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>
-    std::enable_if_t<std::is_fundamental<T>::value> deserialize(T& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
+    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
-    void serialize(const std::string& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
-    void deserialize(std::string& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
+    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);
 
     // Serializable
     template <typename T>
-    std::enable_if_t<std::is_base_of<XMLSerializable,T>::value> serialize(const T& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
+    IGL_INLINE typename std::enable_if<std::is_base_of<XMLSerializable,T>::value>::type serialize(const T& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
     template <typename T>
-    std::enable_if_t<std::is_base_of<XMLSerializable,T>::value> deserialize(T& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
+    IGL_INLINE typename std::enable_if<std::is_base_of<XMLSerializable,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>
-    void serialize(const std::pair<T1,T2>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
+    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>
-    void deserialize(std::pair<T1,T2>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
+    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>
-    void serialize(const std::vector<T1,T2>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
+    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>
-    void deserialize(std::vector<T1,T2>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
+    IGL_INLINE void deserialize(std::vector<T1,T2>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
 
     template <typename T>
-    void serialize(const std::set<T>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
+    IGL_INLINE void serialize(const std::set<T>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
     template <typename T>
-    void deserialize(std::set<T>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
+    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>
-    void serialize(const std::map<T1,T2>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
+    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>
-    void deserialize(std::map<T1,T2>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
+    IGL_INLINE void deserialize(std::map<T1,T2>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
 
     // Eigen types
     template<typename T,int R,int C,int P,int MR,int MC>
-    void serialize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
+    IGL_INLINE void serialize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
     template<typename T,int R,int C,int P,int MR,int MC>
-    void deserialize(Eigen::Matrix<T,R,C,P,MR,MC>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
+    IGL_INLINE void deserialize(Eigen::Matrix<T,R,C,P,MR,MC>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
 
     template<typename T,int P,typename I>
-    void serialize(const Eigen::SparseMatrix<T,P,I>& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
+    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>
-    void deserialize(Eigen::SparseMatrix<T,P,I>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
+    IGL_INLINE void deserialize(Eigen::SparseMatrix<T,P,I>& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
 
     // pointers
     template <typename T>
-    std::enable_if_t<std::is_pointer<T>::value> serialize(const T& obj,tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element,const std::string& name);
+    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>
-    std::enable_if_t<std::is_pointer<T>::value> deserialize(T& obj,const tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element,const std::string& name);
+    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);
-    void getAttribute(const char* src,bool& dest);
-    void getAttribute(const char* scr,char& dest);
-    void getAttribute(const char* src,std::string& dest);
-    void getAttribute(const char* src,float& dest);
-    void getAttribute(const char* src,double& dest);
+    IGL_INLINE void getAttribute(const char* src,bool& dest);
+    IGL_INLINE void getAttribute(const char* scr,char& dest);
+    IGL_INLINE void getAttribute(const char* src,std::string& dest);
+    IGL_INLINE void getAttribute(const char* src,float& dest);
+    IGL_INLINE void getAttribute(const char* src,double& dest);
     template<typename T>
-    std::enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value> getAttribute(const char* src,T& dest);
+    IGL_INLINE typename std::enable_if<std::is_integral<T>::value && std::is_unsigned<T>::value>::type getAttribute(const char* src,T& dest);
     template<typename T>
-    std::enable_if_t<std::is_integral<T>::value && !std::is_unsigned<T>::value> getAttribute(const char* src,T& dest);
-    void replaceSubString(std::string& str,const std::string& search,const std::string& replace);
-    void encodeXMLElementName(std::string& name);
-    void decodeXMLElementName(std::string& name);
-    std::string base64_encode(unsigned char const* bytes_to_encode,unsigned int in_len);
-    std::string base64_decode(std::string const& encoded_string);
+    IGL_INLINE typename std::enable_if<std::is_integral<T>::value && !std::is_unsigned<T>::value>::type getAttribute(const char* src,T& dest);
+    IGL_INLINE void replaceSubString(std::string& str,const std::string& search,const std::string& replace);
+    IGL_INLINE void encodeXMLElementName(std::string& name);
+    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>
@@ -207,6 +209,8 @@ namespace igl
   }
 }
 
-#include "serialize_xml.cpp";
+#ifndef IGL_STATIC_LIBRARY
+  #include "serialize_xml.cpp";
+#endif
 
-#endif
+#endif

+ 2 - 0
tutorial/CMakeLists.shared

@@ -67,6 +67,8 @@ link_directories(
 add_definitions(-DIGL_OPENGL_4)
 add_definitions(-DNDEBUG)
 add_definitions(-O3)
+add_definitions(-DENABLE_XML_SERIALIZATION)
+
 
 
 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")

+ 1 - 1
tutorial/CMakeLists.txt

@@ -63,7 +63,7 @@ endif(LIBCOMISO_FOUND)
 add_subdirectory("509_Planarization")
 
 # Chapter 6
-add_subdirectory("601_Serialization")
+#add_subdirectory("601_Serialization")
 if(MATLAB_FOUND)
 add_subdirectory("602_Matlab")
 endif(MATLAB_FOUND)