From 0e1f07acaa8416e086299d427c9b6f889eccb5b5 Mon Sep 17 00:00:00 2001 From: Alex Cunningham Date: Sat, 22 Jun 2013 23:16:53 +0000 Subject: [PATCH] Added matlab codegen for matlab save/load hooks. Can now save and load a gtsam object to/from a mat file --- wrap/Class.cpp | 24 +++++++++++++++++++++++- wrap/tests/expected/Point3.m | 8 ++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/wrap/Class.cpp b/wrap/Class.cpp index 15c4a742c..eadaa1521 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -467,7 +467,17 @@ void Class::serialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFi proxyFile.oss << " else\n"; proxyFile.oss << " error('Arguments do not match any overload of function " << matlabQualName << ".string_serialize');\n"; proxyFile.oss << " end\n"; - proxyFile.oss << " end\n"; + proxyFile.oss << " end\n\n"; + + // Generate code for matlab save function +// function sobj = saveobj(obj) +// % SAVEOBJ Saves the object to a matlab-readable format +// sobj = obj.string_serialize(); +// end + + proxyFile.oss << " function sobj = saveobj(obj)\n"; + proxyFile.oss << " % SAVEOBJ Saves the object to a matlab-readable format\n"; + proxyFile.oss << " sobj = obj.string_serialize();\n"; } /* ************************************************************************* */ @@ -529,6 +539,18 @@ void Class::deserialization_fragments(FileWriter& proxyFile, FileWriter& wrapper proxyFile.oss << " error('Arguments do not match any overload of function " << matlabQualName << ".string_deserialize');\n"; proxyFile.oss << " end\n"; proxyFile.oss << " end\n\n"; + + + // Generate matlab load function +// function obj = loadobj(sobj) +// % LOADOBJ Saves the object to a matlab-readable format +// obj = Point3.string_deserialize(sobj); +// end + + proxyFile.oss << " function obj = loadobj(sobj)\n"; + proxyFile.oss << " % LOADOBJ Saves the object to a matlab-readable format\n"; + proxyFile.oss << " obj = " << matlabQualName << ".string_deserialize(sobj);\n"; + proxyFile.oss << " end" << endl; } /* ************************************************************************* */ diff --git a/wrap/tests/expected/Point3.m b/wrap/tests/expected/Point3.m index 27b7f46fe..775eca916 100644 --- a/wrap/tests/expected/Point3.m +++ b/wrap/tests/expected/Point3.m @@ -62,6 +62,10 @@ classdef Point3 < handle error('Arguments do not match any overload of function Point3.string_serialize'); end end + + function sobj = saveobj(obj) + % SAVEOBJ Saves the object to a matlab-readable format + sobj = obj.string_serialize(); end methods(Static = true) @@ -101,5 +105,9 @@ classdef Point3 < handle end end + function obj = loadobj(sobj) + % LOADOBJ Saves the object to a matlab-readable format + obj = Point3.string_deserialize(sobj); + end end end