diff --git a/wrap/FileWriter.cpp b/wrap/FileWriter.cpp index 3f5461078..783661819 100644 --- a/wrap/FileWriter.cpp +++ b/wrap/FileWriter.cpp @@ -15,14 +15,15 @@ using namespace std; using namespace wrap; /* ************************************************************************* */ -FileWriter::FileWriter(const string& filename, bool verbose, const string& comment_str) -: verbose_(verbose),filename_(filename), comment_str_(comment_str) -{ +FileWriter::FileWriter(const string& filename, bool verbose, + const string& comment_str) : + verbose_(verbose), filename_(filename), comment_str_(comment_str) { } /* ************************************************************************* */ void FileWriter::emit(bool add_header, bool force_overwrite) const { - if (verbose_) cerr << "generating " << filename_ << " "; + if (verbose_) + cerr << "generating " << filename_ << " "; // read in file if it exists string existing_contents; bool file_exists = true; @@ -35,23 +36,17 @@ void FileWriter::emit(bool add_header, bool force_overwrite) const { // Only write a file if it is new, an update, or overwrite is forced string new_contents = oss.str(); if (force_overwrite || !file_exists || existing_contents != new_contents) { - ofstream ofs(filename_.c_str(), ios::binary); // Binary to use LF line endings instead of CRLF - if (!ofs) throw CantOpenFile(filename_); + // Binary to use LF line endings instead of CRLF + ofstream ofs(filename_.c_str(), ios::binary); + if (!ofs) + throw CantOpenFile(filename_); // dump in stringstream ofs << new_contents; ofs.close(); - if (verbose_) cerr << " ...complete" << endl; - - // Add small message whenever writing a new file and not running in full verbose mode - if (!verbose_) - cout << "wrap: generating " << filename_ << endl; - } else { - if (verbose_) cerr << " ...no update" << endl; } + if (verbose_) + cerr << " ...no update" << endl; } /* ************************************************************************* */ - - - diff --git a/wrap/Module.cpp b/wrap/Module.cpp index 2148c177e..dc1ce4684 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -401,7 +401,7 @@ void Module::parseMarkup(const std::string& data) { #ifndef WRAP_DISABLE_SERIALIZE cls.isSerializable = true; #else - cout << "Ignoring serializable() flag in class " << cls.name << endl; + // cout << "Ignoring serializable() flag in class " << cls.name << endl; #endif cls.methods.erase(serializable_it); } @@ -412,7 +412,7 @@ void Module::parseMarkup(const std::string& data) { cls.isSerializable = true; cls.hasSerialization= true; #else - cout << "Ignoring serialize() flag in class " << cls.name << endl; + // cout << "Ignoring serialize() flag in class " << cls.name << endl; #endif cls.methods.erase(serialize_it); } diff --git a/wrap/tests/expected2/aGlobalFunction.m b/wrap/tests/expected2/aGlobalFunction.m index 8d08242e3..a7450e591 100644 --- a/wrap/tests/expected2/aGlobalFunction.m +++ b/wrap/tests/expected2/aGlobalFunction.m @@ -1,6 +1,6 @@ function varargout = aGlobalFunction(varargin) if length(varargin) == 0 - varargout{1} = geometry_wrapper(40, varargin{:}); + varargout{1} = geometry_wrapper(51, varargin{:}); else error('Arguments do not match any overload of function aGlobalFunction'); end diff --git a/wrap/tests/expected2/geometry_wrapper.cpp b/wrap/tests/expected2/geometry_wrapper.cpp index fa307c51b..132c03674 100644 --- a/wrap/tests/expected2/geometry_wrapper.cpp +++ b/wrap/tests/expected2/geometry_wrapper.cpp @@ -4,6 +4,8 @@ #include +typedef MyTemplate MyTemplatePoint2; +typedef MyTemplate MyTemplatePoint3; typedef std::set*> Collector_Point2; static Collector_Point2 collector_Point2; @@ -11,6 +13,12 @@ typedef std::set*> Collector_Point3; static Collector_Point3 collector_Point3; typedef std::set*> Collector_Test; static Collector_Test collector_Test; +typedef std::set*> Collector_MyBase; +static Collector_MyBase collector_MyBase; +typedef std::set*> Collector_MyTemplatePoint2; +static Collector_MyTemplatePoint2 collector_MyTemplatePoint2; +typedef std::set*> Collector_MyTemplatePoint3; +static Collector_MyTemplatePoint3 collector_MyTemplatePoint3; void _deleteAllObjects() { @@ -36,6 +44,24 @@ void _deleteAllObjects() collector_Test.erase(iter++); anyDeleted = true; } } + { for(Collector_MyBase::iterator iter = collector_MyBase.begin(); + iter != collector_MyBase.end(); ) { + delete *iter; + collector_MyBase.erase(iter++); + anyDeleted = true; + } } + { for(Collector_MyTemplatePoint2::iterator iter = collector_MyTemplatePoint2.begin(); + iter != collector_MyTemplatePoint2.end(); ) { + delete *iter; + collector_MyTemplatePoint2.erase(iter++); + anyDeleted = true; + } } + { for(Collector_MyTemplatePoint3::iterator iter = collector_MyTemplatePoint3.begin(); + iter != collector_MyTemplatePoint3.end(); ) { + delete *iter; + collector_MyTemplatePoint3.erase(iter++); + anyDeleted = true; + } } if(anyDeleted) cout << "WARNING: Wrap modules with variables in the workspace have been reloaded due to\n" @@ -48,6 +74,9 @@ void _geometry_RTTIRegister() { const mxArray *alreadyCreated = mexGetVariablePtr("global", "gtsam_geometry_rttiRegistry_created"); if(!alreadyCreated) { std::map types; + types.insert(std::make_pair(typeid(MyBase).name(), "MyBase")); + types.insert(std::make_pair(typeid(MyTemplatePoint2).name(), "MyTemplatePoint2")); + types.insert(std::make_pair(typeid(MyTemplatePoint3).name(), "MyTemplatePoint3")); mxArray *registry = mexGetVariable("global", "gtsamwrap_rttiRegistry"); if(!registry) @@ -469,18 +498,149 @@ void Test_return_vector2_39(int nargout, mxArray *out[], int nargin, const mxArr out[0] = wrap< Vector >(obj->return_vector2(value)); } -void aGlobalFunction_40(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void MyBase_collectorInsertAndMakeBase_40(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + mexAtExit(&_deleteAllObjects); + typedef boost::shared_ptr Shared; + + Shared *self = *reinterpret_cast (mxGetData(in[0])); + collector_MyBase.insert(self); +} + +void MyBase_upcastFromVoid_41(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { + mexAtExit(&_deleteAllObjects); + typedef boost::shared_ptr Shared; + boost::shared_ptr *asVoid = *reinterpret_cast**> (mxGetData(in[0])); + out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL); + Shared *self = new Shared(boost::static_pointer_cast(*asVoid)); + *reinterpret_cast(mxGetData(out[0])) = self; +} + +void MyBase_deconstructor_42(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr Shared; + checkArguments("delete_MyBase",nargout,nargin,1); + Shared *self = *reinterpret_cast(mxGetData(in[0])); + Collector_MyBase::iterator item; + item = collector_MyBase.find(self); + if(item != collector_MyBase.end()) { + delete self; + collector_MyBase.erase(item); + } +} + +void MyTemplatePoint2_collectorInsertAndMakeBase_43(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + mexAtExit(&_deleteAllObjects); + typedef boost::shared_ptr Shared; + + Shared *self = *reinterpret_cast (mxGetData(in[0])); + collector_MyTemplatePoint2.insert(self); + + typedef boost::shared_ptr SharedBase; + out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL); + *reinterpret_cast(mxGetData(out[0])) = new SharedBase(*self); +} + +void MyTemplatePoint2_upcastFromVoid_44(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { + mexAtExit(&_deleteAllObjects); + typedef boost::shared_ptr Shared; + boost::shared_ptr *asVoid = *reinterpret_cast**> (mxGetData(in[0])); + out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL); + Shared *self = new Shared(boost::static_pointer_cast(*asVoid)); + *reinterpret_cast(mxGetData(out[0])) = self; +} + +void MyTemplatePoint2_constructor_45(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + mexAtExit(&_deleteAllObjects); + typedef boost::shared_ptr Shared; + + Shared *self = new Shared(new MyTemplatePoint2()); + collector_MyTemplatePoint2.insert(self); + out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL); + *reinterpret_cast (mxGetData(out[0])) = self; + + typedef boost::shared_ptr SharedBase; + out[1] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL); + *reinterpret_cast(mxGetData(out[1])) = new SharedBase(*self); +} + +void MyTemplatePoint2_deconstructor_46(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr Shared; + checkArguments("delete_MyTemplatePoint2",nargout,nargin,1); + Shared *self = *reinterpret_cast(mxGetData(in[0])); + Collector_MyTemplatePoint2::iterator item; + item = collector_MyTemplatePoint2.find(self); + if(item != collector_MyTemplatePoint2.end()) { + delete self; + collector_MyTemplatePoint2.erase(item); + } +} + +void MyTemplatePoint3_collectorInsertAndMakeBase_47(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + mexAtExit(&_deleteAllObjects); + typedef boost::shared_ptr Shared; + + Shared *self = *reinterpret_cast (mxGetData(in[0])); + collector_MyTemplatePoint3.insert(self); + + typedef boost::shared_ptr SharedBase; + out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL); + *reinterpret_cast(mxGetData(out[0])) = new SharedBase(*self); +} + +void MyTemplatePoint3_upcastFromVoid_48(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { + mexAtExit(&_deleteAllObjects); + typedef boost::shared_ptr Shared; + boost::shared_ptr *asVoid = *reinterpret_cast**> (mxGetData(in[0])); + out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL); + Shared *self = new Shared(boost::static_pointer_cast(*asVoid)); + *reinterpret_cast(mxGetData(out[0])) = self; +} + +void MyTemplatePoint3_constructor_49(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + mexAtExit(&_deleteAllObjects); + typedef boost::shared_ptr Shared; + + Shared *self = new Shared(new MyTemplatePoint3()); + collector_MyTemplatePoint3.insert(self); + out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL); + *reinterpret_cast (mxGetData(out[0])) = self; + + typedef boost::shared_ptr SharedBase; + out[1] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL); + *reinterpret_cast(mxGetData(out[1])) = new SharedBase(*self); +} + +void MyTemplatePoint3_deconstructor_50(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr Shared; + checkArguments("delete_MyTemplatePoint3",nargout,nargin,1); + Shared *self = *reinterpret_cast(mxGetData(in[0])); + Collector_MyTemplatePoint3::iterator item; + item = collector_MyTemplatePoint3.find(self); + if(item != collector_MyTemplatePoint3.end()) { + delete self; + collector_MyTemplatePoint3.erase(item); + } +} + +void aGlobalFunction_51(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("aGlobalFunction",nargout,nargin,0); out[0] = wrap< Vector >(aGlobalFunction()); } -void overloadedGlobalFunction_41(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void overloadedGlobalFunction_52(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("overloadedGlobalFunction",nargout,nargin,1); int a = unwrap< int >(in[0]); out[0] = wrap< Vector >(overloadedGlobalFunction(a)); } -void overloadedGlobalFunction_42(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void overloadedGlobalFunction_53(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("overloadedGlobalFunction",nargout,nargin,2); int a = unwrap< int >(in[0]); @@ -620,13 +780,46 @@ void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) Test_return_vector2_39(nargout, out, nargin-1, in+1); break; case 40: - aGlobalFunction_40(nargout, out, nargin-1, in+1); + MyBase_collectorInsertAndMakeBase_40(nargout, out, nargin-1, in+1); break; case 41: - overloadedGlobalFunction_41(nargout, out, nargin-1, in+1); + MyBase_upcastFromVoid_41(nargout, out, nargin-1, in+1); break; case 42: - overloadedGlobalFunction_42(nargout, out, nargin-1, in+1); + MyBase_deconstructor_42(nargout, out, nargin-1, in+1); + break; + case 43: + MyTemplatePoint2_collectorInsertAndMakeBase_43(nargout, out, nargin-1, in+1); + break; + case 44: + MyTemplatePoint2_upcastFromVoid_44(nargout, out, nargin-1, in+1); + break; + case 45: + MyTemplatePoint2_constructor_45(nargout, out, nargin-1, in+1); + break; + case 46: + MyTemplatePoint2_deconstructor_46(nargout, out, nargin-1, in+1); + break; + case 47: + MyTemplatePoint3_collectorInsertAndMakeBase_47(nargout, out, nargin-1, in+1); + break; + case 48: + MyTemplatePoint3_upcastFromVoid_48(nargout, out, nargin-1, in+1); + break; + case 49: + MyTemplatePoint3_constructor_49(nargout, out, nargin-1, in+1); + break; + case 50: + MyTemplatePoint3_deconstructor_50(nargout, out, nargin-1, in+1); + break; + case 51: + aGlobalFunction_51(nargout, out, nargin-1, in+1); + break; + case 52: + overloadedGlobalFunction_52(nargout, out, nargin-1, in+1); + break; + case 53: + overloadedGlobalFunction_53(nargout, out, nargin-1, in+1); break; } } catch(const std::exception& e) { diff --git a/wrap/tests/expected2/overloadedGlobalFunction.m b/wrap/tests/expected2/overloadedGlobalFunction.m index a053e0331..e080a038a 100644 --- a/wrap/tests/expected2/overloadedGlobalFunction.m +++ b/wrap/tests/expected2/overloadedGlobalFunction.m @@ -1,8 +1,8 @@ function varargout = overloadedGlobalFunction(varargin) if length(varargin) == 1 && isa(varargin{1},'numeric') - varargout{1} = geometry_wrapper(41, varargin{:}); + varargout{1} = geometry_wrapper(52, varargin{:}); elseif length(varargin) == 2 && isa(varargin{1},'numeric') && isa(varargin{2},'double') - varargout{1} = geometry_wrapper(42, varargin{:}); + varargout{1} = geometry_wrapper(53, varargin{:}); else error('Arguments do not match any overload of function overloadedGlobalFunction'); end diff --git a/wrap/tests/geometry.h b/wrap/tests/geometry.h index bc233763d..238a25d72 100644 --- a/wrap/tests/geometry.h +++ b/wrap/tests/geometry.h @@ -91,6 +91,18 @@ Vector aGlobalFunction(); Vector overloadedGlobalFunction(int a); Vector overloadedGlobalFunction(int a, double b); +// A base class +virtual class MyBase { + +}; + +// A templated class +template +virtual class MyTemplate : MyBase { + MyTemplate(); +}; + + // comments at the end! // even more comments at the end! diff --git a/wrap/tests/testWrap.cpp b/wrap/tests/testWrap.cpp index 2eec2b3fb..399fa61aa 100644 --- a/wrap/tests/testWrap.cpp +++ b/wrap/tests/testWrap.cpp @@ -153,7 +153,7 @@ TEST( wrap, small_parse ) { TEST( wrap, parse_geometry ) { string markup_header_path = topdir + "/wrap/tests"; Module module(markup_header_path.c_str(), "geometry",enable_verbose); - EXPECT_LONGS_EQUAL(3, module.classes.size()); + EXPECT_LONGS_EQUAL(6, module.classes.size()); // forward declarations LONGS_EQUAL(2, module.forward_declarations.size()); @@ -164,7 +164,7 @@ TEST( wrap, parse_geometry ) { strvec exp_includes; exp_includes += "folder/path/to/Test.h"; EXPECT(assert_equal(exp_includes, module.includes)); - LONGS_EQUAL(3, module.classes.size()); + LONGS_EQUAL(6, module.classes.size()); // Key for ReturnValue::return_category // CLASS = 1,