Browse Source

add enums for serializer
argument parsing for viewer


Former-commit-id: 46bc287518c2c5f9000771bf4c49cc52650cb82a

schuellc 10 years ago
parent
commit
ab97f308f3

+ 32 - 2
include/igl/serialize.h

@@ -242,7 +242,7 @@ namespace igl
 
     template <typename T>
     struct is_serializable {
-      static const bool value = std::is_fundamental<T>::value || std::is_same<std::string,T>::value || std::is_base_of<SerializableBase,T>::value
+      static const bool value = std::is_fundamental<T>::value || std::is_same<std::string,T>::value || std::is_enum<T>::value || std::is_base_of<SerializableBase,T>::value
         || is_stl_container<T>::value || is_eigen_type<T>::value || std::is_pointer<T>::value || serialization::is_smart_ptr<T>::value;
     };
 
@@ -267,6 +267,14 @@ namespace igl
     inline void serialize(const std::string& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     inline void deserialize(std::string& obj,std::vector<char>::const_iterator& iter);
 
+    // enum types
+    template <typename T>
+    inline typename std::enable_if<std::is_enum<T>::value,size_t>::type getByteSize(const T& obj);
+    template <typename T>
+    inline typename std::enable_if<std::is_enum<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
+    template <typename T>
+    inline typename std::enable_if<std::is_enum<T>::value>::type deserialize(T& obj,std::vector<char>::const_iterator& iter);
+
     // SerializableBase
     template <typename T>
     inline typename std::enable_if<std::is_base_of<SerializableBase,T>::value,size_t>::type getByteSize(const T& obj);
@@ -631,7 +639,6 @@ namespace igl
 
   namespace serialization
   {
-    // not serializable
     template <typename T>
     inline typename std::enable_if<!is_serializable<T>::value,size_t>::type getByteSize(const T& obj)
     {
@@ -723,6 +730,29 @@ namespace igl
       obj = str;
     }
 
+    // enum types
+
+    template <typename T>
+    inline typename std::enable_if<std::is_enum<T>::value,size_t>::type getByteSize(const T& obj)
+    {
+      return sizeof(T);
+    }
+
+    template <typename T>
+    inline typename std::enable_if<std::is_enum<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>
+    inline typename std::enable_if<std::is_enum<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);
+      iter += sizeof(T);
+    }
+
     // SerializableBase
 
     template <typename T>

+ 1 - 1
include/igl/triangle_triangle_adjacency.h

@@ -18,7 +18,7 @@ namespace igl
   //
   // Templates:
   //   Scalar derived type of eigen matrix for V (e.g. derived from
-  //     MatirxXd)
+  //     MatrixXd)
   //   Index  derived type of eigen matrix for F (e.g. derived from
   //     MatrixXi)
   // Inputs:

+ 2 - 2
include/igl/viewer/Viewer.cpp

@@ -412,6 +412,8 @@ namespace igl
       if (callback_init(*this))
         return;
 
+    init_plugins();
+
     // Parse command line arguments
     bool isLoaded = false;
     for(int i=1;i<argc;i++)
@@ -423,8 +425,6 @@ namespace igl
           std::cout << "file not found: " << argv[i+1] << std::endl;
       }
     }
-
-    init_plugins();
   }
 
   IGL_INLINE Viewer::Viewer()