diff --git a/wrap/Class.cpp b/wrap/Class.cpp index 8bc6ac38d..c384a5377 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -530,4 +530,10 @@ void Class::deserialization_fragments(FileWriter& proxyFile, FileWriter& wrapper proxyFile.oss << " end\n"; proxyFile.oss << " end\n\n"; } + +/* ************************************************************************* */ +std::string Class::getSerializationExport() const { + //BOOST_CLASS_EXPORT_GUID(gtsam::SharedDiagonal, "gtsamSharedDiagonal"); + return "BOOST_CLASS_EXPORT_GUID(" + qualifiedName("::") + ", \"" + qualifiedName() + "\");"; +} /* ************************************************************************* */ diff --git a/wrap/Class.h b/wrap/Class.h index d33124e50..efbcce26c 100644 --- a/wrap/Class.h +++ b/wrap/Class.h @@ -66,6 +66,9 @@ struct Class { // The typedef line for this class, if this class is a typedef, otherwise returns an empty string. std::string getTypedef() const; + // Returns the string for an export flag + std::string getSerializationExport() const; + // Creates a member function that performs serialization void serialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, const std::string& wrapperName, std::vector& functionNames) const; diff --git a/wrap/Module.cpp b/wrap/Module.cpp index ec346a7a0..3f16fbf1b 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -492,11 +492,14 @@ void Module::matlab_code(const string& toolboxPath, const string& headerPath) co wrapperFile.oss << "#include \n"; wrapperFile.oss << "\n"; - // Generate includes while avoiding redundant includes + // Include boost.serialization archive headers before other class headers if (hasSerialiable) { + wrapperFile.oss << "#include \n"; wrapperFile.oss << "#include \n"; wrapperFile.oss << "#include \n\n"; } + + // Generate includes while avoiding redundant includes generateIncludes(wrapperFile); // create typedef classes - we put this at the top of the wrap file so that collectors and method arguments can use these typedefs @@ -506,6 +509,15 @@ void Module::matlab_code(const string& toolboxPath, const string& headerPath) co } wrapperFile.oss << "\n"; + // Generate boost.serialization export flags (needs typedefs from above) + if (hasSerialiable) { + BOOST_FOREACH(const Class& cls, expandedClasses) { + if(cls.isSerializable) + wrapperFile.oss << cls.getSerializationExport() << "\n"; + } + wrapperFile.oss << "\n"; + } + // Generate collectors and cleanup function to be called from mexAtExit WriteCollectorsAndCleanupFcn(wrapperFile, name, expandedClasses); diff --git a/wrap/tests/expected/geometry_wrapper.cpp b/wrap/tests/expected/geometry_wrapper.cpp index 35c2a2aec..c56545847 100644 --- a/wrap/tests/expected/geometry_wrapper.cpp +++ b/wrap/tests/expected/geometry_wrapper.cpp @@ -2,11 +2,13 @@ #include #include +#include #include #include #include +BOOST_CLASS_EXPORT_GUID(Point3, "Point3"); typedef std::set*> Collector_Point2; static Collector_Point2 collector_Point2;