From 774fcb5ca902e9cca79fcea8c850d9e65d4323ca Mon Sep 17 00:00:00 2001 From: Alex Cunningham Date: Wed, 11 Jul 2012 15:58:01 +0000 Subject: [PATCH] Fixed include sorting bug in wrap --- wrap/Module.cpp | 10 ++- wrap/tests/expected/geometry_wrapper.cpp | 61 ++++++++++++------- .../testNamespaces_wrapper.cpp | 37 +++++++++-- 3 files changed, 75 insertions(+), 33 deletions(-) diff --git a/wrap/Module.cpp b/wrap/Module.cpp index 9e2fd6380..997e14266 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -321,7 +321,6 @@ void Module::generateIncludes(FileWriter& file) const { // collect includes vector all_includes; BOOST_FOREACH(const Class& cls, classes) { -// generateIncludes(wrapperFile, cls.name, cls.includes); bool added_include = false; BOOST_FOREACH(const string& s, cls.includes) { if (!s.empty()) { @@ -335,12 +334,11 @@ void Module::generateIncludes(FileWriter& file) const { // sort and remove duplicates sort(all_includes.begin(), all_includes.end()); - unique(all_includes.begin(), all_includes.end()); - + vector::const_iterator last_include = unique(all_includes.begin(), all_includes.end()); + vector::const_iterator it = all_includes.begin(); // add includes to file - BOOST_FOREACH(const string& include, all_includes) { - file.oss << "#include <" << include << ">" << endl; - } + for (; it != last_include; ++it) + file.oss << "#include <" << *it << ">" << endl; file.oss << "\n"; } diff --git a/wrap/tests/expected/geometry_wrapper.cpp b/wrap/tests/expected/geometry_wrapper.cpp index a2e01ab92..515f886f4 100644 --- a/wrap/tests/expected/geometry_wrapper.cpp +++ b/wrap/tests/expected/geometry_wrapper.cpp @@ -32,6 +32,27 @@ void _deleteAllObjects() collector_Test.erase(iter++); } } + +static bool _RTTIRegister_geometry_done = false; +void _geometry_RTTIRegister() { + std::map types; + + mxArray *registry = mexGetVariable("global", "gtsamwrap_rttiRegistry"); + if(!registry) + registry = mxCreateStructMatrix(1, 1, 0, NULL); + typedef std::pair StringPair; + BOOST_FOREACH(const StringPair& rtti_matlab, types) { + int fieldId = mxAddField(registry, rtti_matlab.first.c_str()); + if(fieldId < 0) + mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly"); + mxArray *matlabName = mxCreateString(rtti_matlab.second.c_str()); + mxSetFieldByNumber(registry, 0, fieldId, matlabName); + } + if(mexPutVariable("global", "gtsamwrap_rttiRegistry", registry) != 0) + mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly"); + mxDestroyArray(registry); +} + void Point2_collectorInsertAndMakeBase_0(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); @@ -40,6 +61,7 @@ void Point2_collectorInsertAndMakeBase_0(int nargout, mxArray *out[], int nargin Shared *self = *reinterpret_cast (mxGetData(in[0])); collector_Point2.insert(self); } + void Point2_constructor_1(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); @@ -117,8 +139,7 @@ void Point2_vectorConfusion_8(int nargout, mxArray *out[], int nargin, const mxA typedef boost::shared_ptr Shared; checkArguments("vectorConfusion",nargout,nargin-1,0); Shared obj = unwrap_shared_ptr(in[0], "ptr_Point2"); - SharedVectorNotEigen* ret = new SharedVectorNotEigen(new VectorNotEigen(obj->vectorConfusion())); - out[0] = wrap_shared_ptr(ret,"VectorNotEigen"); + out[0] = wrap_shared_ptr(SharedVectorNotEigen(new VectorNotEigen(obj->vectorConfusion())),"VectorNotEigen", false); } void Point2_x_9(int nargout, mxArray *out[], int nargin, const mxArray *in[]) @@ -146,6 +167,7 @@ using namespace geometry; Shared *self = *reinterpret_cast (mxGetData(in[0])); collector_Point3.insert(self); } + void Point3_constructor_12(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); @@ -191,8 +213,7 @@ using namespace geometry; typedef boost::shared_ptr Shared; checkArguments("Point3.StaticFunctionRet",nargout,nargin,1); double z = unwrap< double >(in[0]); - SharedPoint3* ret = new SharedPoint3(new Point3(Point3::StaticFunctionRet(z))); - out[0] = wrap_shared_ptr(ret,"Point3"); + out[0] = wrap_shared_ptr(SharedPoint3(new Point3(Point3::StaticFunctionRet(z))),"Point3", false); } void Point3_staticFunction_16(int nargout, mxArray *out[], int nargin, const mxArray *in[]) @@ -212,6 +233,7 @@ using namespace geometry; Shared *self = *reinterpret_cast (mxGetData(in[0])); collector_Test.insert(self); } + void Test_constructor_18(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); @@ -270,10 +292,8 @@ using namespace geometry; typedef boost::shared_ptr Shared; checkArguments("create_MixedPtrs",nargout,nargin-1,0); Shared obj = unwrap_shared_ptr(in[0], "ptr_Test"); - SharedTest* ret = new SharedTest(new Test(obj->create_MixedPtrs().first)); - out[0] = wrap_shared_ptr(ret,"Test"); - SharedTest* ret = new SharedTest(obj->create_MixedPtrs().second); - out[1] = wrap_shared_ptr(ret,"Test"); + out[0] = wrap_shared_ptr(SharedTest(new Test(obj->create_MixedPtrs().first)),"Test", false); + out[0] = wrap_shared_ptr(obj->create_MixedPtrs().second,"Test", false); } void Test_create_ptrs_23(int nargout, mxArray *out[], int nargin, const mxArray *in[]) @@ -284,10 +304,8 @@ using namespace geometry; typedef boost::shared_ptr Shared; checkArguments("create_ptrs",nargout,nargin-1,0); Shared obj = unwrap_shared_ptr(in[0], "ptr_Test"); - SharedTest* ret = new SharedTest(obj->create_ptrs().first); - out[0] = wrap_shared_ptr(ret,"Test"); - SharedTest* ret = new SharedTest(obj->create_ptrs().second); - out[1] = wrap_shared_ptr(ret,"Test"); + out[0] = wrap_shared_ptr(obj->create_ptrs().first,"Test", false); + out[0] = wrap_shared_ptr(obj->create_ptrs().second,"Test", false); } void Test_print_24(int nargout, mxArray *out[], int nargin, const mxArray *in[]) @@ -307,8 +325,7 @@ using namespace geometry; checkArguments("return_Point2Ptr",nargout,nargin-1,1); Shared obj = unwrap_shared_ptr(in[0], "ptr_Test"); bool value = unwrap< bool >(in[1]); - SharedPoint2* ret = new SharedPoint2(obj->return_Point2Ptr(value)); - out[0] = wrap_shared_ptr(ret,"Point2"); + out[0] = wrap_shared_ptr(obj->return_Point2Ptr(value),"Point2", false); } void Test_return_Test_26(int nargout, mxArray *out[], int nargin, const mxArray *in[]) @@ -319,8 +336,7 @@ using namespace geometry; checkArguments("return_Test",nargout,nargin-1,1); Shared obj = unwrap_shared_ptr(in[0], "ptr_Test"); boost::shared_ptr value = unwrap_shared_ptr< Test >(in[1], "ptr_Test"); - SharedTest* ret = new SharedTest(new Test(obj->return_Test(value))); - out[0] = wrap_shared_ptr(ret,"Test"); + out[0] = wrap_shared_ptr(SharedTest(new Test(obj->return_Test(value))),"Test", false); } void Test_return_TestPtr_27(int nargout, mxArray *out[], int nargin, const mxArray *in[]) @@ -331,8 +347,7 @@ using namespace geometry; checkArguments("return_TestPtr",nargout,nargin-1,1); Shared obj = unwrap_shared_ptr(in[0], "ptr_Test"); boost::shared_ptr value = unwrap_shared_ptr< Test >(in[1], "ptr_Test"); - SharedTest* ret = new SharedTest(obj->return_TestPtr(value)); - out[0] = wrap_shared_ptr(ret,"Test"); + out[0] = wrap_shared_ptr(obj->return_TestPtr(value),"Test", false); } void Test_return_bool_28(int nargout, mxArray *out[], int nargin, const mxArray *in[]) @@ -417,10 +432,8 @@ using namespace geometry; Shared obj = unwrap_shared_ptr(in[0], "ptr_Test"); boost::shared_ptr p1 = unwrap_shared_ptr< Test >(in[1], "ptr_Test"); boost::shared_ptr p2 = unwrap_shared_ptr< Test >(in[2], "ptr_Test"); - SharedTest* ret = new SharedTest(obj->return_ptrs(p1,p2).first); - out[0] = wrap_shared_ptr(ret,"Test"); - SharedTest* ret = new SharedTest(obj->return_ptrs(p1,p2).second); - out[1] = wrap_shared_ptr(ret,"Test"); + out[0] = wrap_shared_ptr(obj->return_ptrs(p1,p2).first,"Test", false); + out[0] = wrap_shared_ptr(obj->return_ptrs(p1,p2).second,"Test", false); } void Test_return_size_t_36(int nargout, mxArray *out[], int nargin, const mxArray *in[]) @@ -469,6 +482,10 @@ void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) mstream mout; std::streambuf *outbuf = std::cout.rdbuf(&mout); + if(!_RTTIRegister_geometry_done) { + _geometry_RTTIRegister(); + _RTTIRegister_geometry_done = true; + } int id = unwrap(in[0]); switch(id) { diff --git a/wrap/tests/expected_namespaces/testNamespaces_wrapper.cpp b/wrap/tests/expected_namespaces/testNamespaces_wrapper.cpp index 53f28d10e..dc88fc296 100644 --- a/wrap/tests/expected_namespaces/testNamespaces_wrapper.cpp +++ b/wrap/tests/expected_namespaces/testNamespaces_wrapper.cpp @@ -9,9 +9,6 @@ #include #include #include -#include -#include -#include typedef std::set*> Collector_ns1ClassA; static Collector_ns1ClassA collector_ns1ClassA; @@ -59,6 +56,27 @@ void _deleteAllObjects() collector_ClassD.erase(iter++); } } + +static bool _RTTIRegister_testNamespaces_done = false; +void _testNamespaces_RTTIRegister() { + std::map types; + + mxArray *registry = mexGetVariable("global", "gtsamwrap_rttiRegistry"); + if(!registry) + registry = mxCreateStructMatrix(1, 1, 0, NULL); + typedef std::pair StringPair; + BOOST_FOREACH(const StringPair& rtti_matlab, types) { + int fieldId = mxAddField(registry, rtti_matlab.first.c_str()); + if(fieldId < 0) + mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly"); + mxArray *matlabName = mxCreateString(rtti_matlab.second.c_str()); + mxSetFieldByNumber(registry, 0, fieldId, matlabName); + } + if(mexPutVariable("global", "gtsamwrap_rttiRegistry", registry) != 0) + mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly"); + mxDestroyArray(registry); +} + void ns1ClassA_collectorInsertAndMakeBase_0(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); @@ -67,6 +85,7 @@ void ns1ClassA_collectorInsertAndMakeBase_0(int nargout, mxArray *out[], int nar Shared *self = *reinterpret_cast (mxGetData(in[0])); collector_ns1ClassA.insert(self); } + void ns1ClassA_constructor_1(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); @@ -99,6 +118,7 @@ void ns1ClassB_collectorInsertAndMakeBase_3(int nargout, mxArray *out[], int nar Shared *self = *reinterpret_cast (mxGetData(in[0])); collector_ns1ClassB.insert(self); } + void ns1ClassB_constructor_4(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); @@ -131,6 +151,7 @@ void ns2ClassA_collectorInsertAndMakeBase_6(int nargout, mxArray *out[], int nar Shared *self = *reinterpret_cast (mxGetData(in[0])); collector_ns2ClassA.insert(self); } + void ns2ClassA_constructor_7(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); @@ -179,8 +200,7 @@ void ns2ClassA_nsReturn_11(int nargout, mxArray *out[], int nargin, const mxArra checkArguments("nsReturn",nargout,nargin-1,1); Shared obj = unwrap_shared_ptr(in[0], "ptr_ns2ClassA"); double q = unwrap< double >(in[1]); - SharedClassB* ret = new SharedClassB(new ns2::ns3::ClassB(obj->nsReturn(q))); - out[0] = wrap_shared_ptr(ret,"ns2ns3ClassB"); + out[0] = wrap_shared_ptr(SharedClassB(new ns2::ns3::ClassB(obj->nsReturn(q))),"ns2ns3ClassB", false); } void ns2ClassA_afunction_12(int nargout, mxArray *out[], int nargin, const mxArray *in[]) @@ -198,6 +218,7 @@ void ns2ns3ClassB_collectorInsertAndMakeBase_13(int nargout, mxArray *out[], int Shared *self = *reinterpret_cast (mxGetData(in[0])); collector_ns2ns3ClassB.insert(self); } + void ns2ns3ClassB_constructor_14(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); @@ -230,6 +251,7 @@ void ns2ClassC_collectorInsertAndMakeBase_16(int nargout, mxArray *out[], int na Shared *self = *reinterpret_cast (mxGetData(in[0])); collector_ns2ClassC.insert(self); } + void ns2ClassC_constructor_17(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); @@ -262,6 +284,7 @@ void ClassD_collectorInsertAndMakeBase_19(int nargout, mxArray *out[], int nargi Shared *self = *reinterpret_cast (mxGetData(in[0])); collector_ClassD.insert(self); } + void ClassD_constructor_20(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); @@ -292,6 +315,10 @@ void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) mstream mout; std::streambuf *outbuf = std::cout.rdbuf(&mout); + if(!_RTTIRegister_testNamespaces_done) { + _testNamespaces_RTTIRegister(); + _RTTIRegister_testNamespaces_done = true; + } int id = unwrap(in[0]); switch(id) {