diff --git a/tutorial/601_Serialization/main.cpp b/tutorial/601_Serialization/main.cpp index f923cd7c6..cf827ad33 100755 --- a/tutorial/601_Serialization/main.cpp +++ b/tutorial/601_Serialization/main.cpp @@ -8,38 +8,59 @@ Eigen::MatrixXd V; Eigen::MatrixXi F; -// derive from igl::Serializable to serialize your own type -struct State : public igl::Serializable -{ - Eigen::MatrixXd V; - Eigen::MatrixXi F; - std::vector ids; - - // You have to define this function to - // register the fields you want to serialize - void InitSerialization() - { - this->Add(V , "V"); - this->Add(F , "F"); - this->Add(ids, "ids"); - } -}; - -// alternatively you can do it like the following to have -// a non-intrusive serialization: +//// derive from igl::Serializable to serialize your own type +//struct State : public igl::Serializable +//{ +// Eigen::MatrixXd V; +// Eigen::MatrixXi F; +// std::vector ids; // -// struct State -// { -// Eigen::MatrixXd V; -// Eigen::MatrixXi F; -// std::vector ids; -// }; +// // You have to define this function to +// // register the fields you want to serialize +// void InitSerialization() +// { +// this->Add(V , "V"); +// this->Add(F , "F"); +// this->Add(ids, "ids"); +// } +//}; + +//// alternatively you can do it like the following to have +//// a non-intrusive serialization: +//// +//struct State +//{ +// Eigen::MatrixXd V; +// Eigen::MatrixXi F; +// std::vector ids; +//}; +// +// +//namespace igl +//{ +// namespace serialization +// { +// // the `template <>` is essential +// template <> inline void serialize(const State& obj,std::vector& buffer){ +// ::igl::serialize(obj.V,std::string("V"),buffer); +// ::igl::serialize(obj.F,std::string("F"),buffer); +// ::igl::serialize(obj.ids,std::string("ids"),buffer); +// } +// template <> inline void deserialize(State& obj,const std::vector& buffer){ +// ::igl::deserialize(obj.V,std::string("V"),buffer); +// ::igl::deserialize(obj.F,std::string("F"),buffer); +// ::igl::deserialize(obj.ids,std::string("ids"),buffer); +// } +// } +//} +// +////OR: // -// SERIALIZE_TYPE(State, -// SERIALIZE_MEMBER(V) -// SERIALIZE_MEMBER(F) -// SERIALIZE_MEMBER_NAME(ids,"ids") -// ) +//SERIALIZE_TYPE(State, +// SERIALIZE_MEMBER(V) +// SERIALIZE_MEMBER(F) +// SERIALIZE_MEMBER_NAME(ids,"ids") +//) int main(int argc, char *argv[]) { diff --git a/tutorial/tutorial.md b/tutorial/tutorial.md index d039bd307..e2e0d9675 100644 --- a/tutorial/tutorial.md +++ b/tutorial/tutorial.md @@ -2193,19 +2193,22 @@ void Serializable::PostDeserialization(); Alternatively, if you want a non-intrusive way of serializing your state you can overload the following functions: ```cpp -namespace igl { namespace serialization { - -void serialize(const State& obj,std::vector& buffer){ - ::igl::serialize(obj.V,std::string("V"),buffer); - ::igl::serialize(obj.F,std::string("F"),buffer); - ::igl::serialize(obj.ids,std::string("ids"),buffer); +namespace igl +{ + namespace serialization + { + template <> inline void serialize(const State& obj,std::vector& buffer){ + ::igl::serialize(obj.V,std::string("V"),buffer); + ::igl::serialize(obj.F,std::string("F"),buffer); + ::igl::serialize(obj.ids,std::string("ids"),buffer); + } + template <> inline void deserialize(State& obj,const std::vector& buffer){ + ::igl::deserialize(obj.V,std::string("V"),buffer); + ::igl::deserialize(obj.F,std::string("F"),buffer); + ::igl::deserialize(obj.ids,std::string("ids"),buffer); + } + } } -void deserialize(State& obj,const std::vector& buffer){ - ::igl::deserialize(obj.V,std::string("V"),buffer); - ::igl::deserialize(obj.F,std::string("F"),buffer); - ::igl::deserialize(obj.ids,std::string("ids"),buffer); -} -}} ``` Equivalently, you can use the following macros: