Fixed include sorting bug in wrap

release/4.3a0
Alex Cunningham 2012-07-11 15:58:01 +00:00
parent 1993e6952b
commit 774fcb5ca9
3 changed files with 75 additions and 33 deletions

View File

@ -321,7 +321,6 @@ void Module::generateIncludes(FileWriter& file) const {
// collect includes // collect includes
vector<string> all_includes; vector<string> all_includes;
BOOST_FOREACH(const Class& cls, classes) { BOOST_FOREACH(const Class& cls, classes) {
// generateIncludes(wrapperFile, cls.name, cls.includes);
bool added_include = false; bool added_include = false;
BOOST_FOREACH(const string& s, cls.includes) { BOOST_FOREACH(const string& s, cls.includes) {
if (!s.empty()) { if (!s.empty()) {
@ -335,12 +334,11 @@ void Module::generateIncludes(FileWriter& file) const {
// sort and remove duplicates // sort and remove duplicates
sort(all_includes.begin(), all_includes.end()); sort(all_includes.begin(), all_includes.end());
unique(all_includes.begin(), all_includes.end()); vector<string>::const_iterator last_include = unique(all_includes.begin(), all_includes.end());
vector<string>::const_iterator it = all_includes.begin();
// add includes to file // add includes to file
BOOST_FOREACH(const string& include, all_includes) { for (; it != last_include; ++it)
file.oss << "#include <" << include << ">" << endl; file.oss << "#include <" << *it << ">" << endl;
}
file.oss << "\n"; file.oss << "\n";
} }

View File

@ -32,6 +32,27 @@ void _deleteAllObjects()
collector_Test.erase(iter++); collector_Test.erase(iter++);
} }
} }
static bool _RTTIRegister_geometry_done = false;
void _geometry_RTTIRegister() {
std::map<std::string, std::string> types;
mxArray *registry = mexGetVariable("global", "gtsamwrap_rttiRegistry");
if(!registry)
registry = mxCreateStructMatrix(1, 1, 0, NULL);
typedef std::pair<std::string, std::string> 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[]) void Point2_collectorInsertAndMakeBase_0(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{ {
mexAtExit(&_deleteAllObjects); mexAtExit(&_deleteAllObjects);
@ -40,6 +61,7 @@ void Point2_collectorInsertAndMakeBase_0(int nargout, mxArray *out[], int nargin
Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0])); Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
collector_Point2.insert(self); collector_Point2.insert(self);
} }
void Point2_constructor_1(int nargout, mxArray *out[], int nargin, const mxArray *in[]) void Point2_constructor_1(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{ {
mexAtExit(&_deleteAllObjects); mexAtExit(&_deleteAllObjects);
@ -117,8 +139,7 @@ void Point2_vectorConfusion_8(int nargout, mxArray *out[], int nargin, const mxA
typedef boost::shared_ptr<Point2> Shared; typedef boost::shared_ptr<Point2> Shared;
checkArguments("vectorConfusion",nargout,nargin-1,0); checkArguments("vectorConfusion",nargout,nargin-1,0);
Shared obj = unwrap_shared_ptr<Point2>(in[0], "ptr_Point2"); Shared obj = unwrap_shared_ptr<Point2>(in[0], "ptr_Point2");
SharedVectorNotEigen* ret = new SharedVectorNotEigen(new VectorNotEigen(obj->vectorConfusion())); out[0] = wrap_shared_ptr(SharedVectorNotEigen(new VectorNotEigen(obj->vectorConfusion())),"VectorNotEigen", false);
out[0] = wrap_shared_ptr(ret,"VectorNotEigen");
} }
void Point2_x_9(int nargout, mxArray *out[], int nargin, const mxArray *in[]) void Point2_x_9(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -146,6 +167,7 @@ using namespace geometry;
Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0])); Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
collector_Point3.insert(self); collector_Point3.insert(self);
} }
void Point3_constructor_12(int nargout, mxArray *out[], int nargin, const mxArray *in[]) void Point3_constructor_12(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{ {
mexAtExit(&_deleteAllObjects); mexAtExit(&_deleteAllObjects);
@ -191,8 +213,7 @@ using namespace geometry;
typedef boost::shared_ptr<Point3> Shared; typedef boost::shared_ptr<Point3> Shared;
checkArguments("Point3.StaticFunctionRet",nargout,nargin,1); checkArguments("Point3.StaticFunctionRet",nargout,nargin,1);
double z = unwrap< double >(in[0]); double z = unwrap< double >(in[0]);
SharedPoint3* ret = new SharedPoint3(new Point3(Point3::StaticFunctionRet(z))); out[0] = wrap_shared_ptr(SharedPoint3(new Point3(Point3::StaticFunctionRet(z))),"Point3", false);
out[0] = wrap_shared_ptr(ret,"Point3");
} }
void Point3_staticFunction_16(int nargout, mxArray *out[], int nargin, const mxArray *in[]) void Point3_staticFunction_16(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -212,6 +233,7 @@ using namespace geometry;
Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0])); Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
collector_Test.insert(self); collector_Test.insert(self);
} }
void Test_constructor_18(int nargout, mxArray *out[], int nargin, const mxArray *in[]) void Test_constructor_18(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{ {
mexAtExit(&_deleteAllObjects); mexAtExit(&_deleteAllObjects);
@ -270,10 +292,8 @@ using namespace geometry;
typedef boost::shared_ptr<Test> Shared; typedef boost::shared_ptr<Test> Shared;
checkArguments("create_MixedPtrs",nargout,nargin-1,0); checkArguments("create_MixedPtrs",nargout,nargin-1,0);
Shared obj = unwrap_shared_ptr<Test>(in[0], "ptr_Test"); Shared obj = unwrap_shared_ptr<Test>(in[0], "ptr_Test");
SharedTest* ret = new SharedTest(new Test(obj->create_MixedPtrs().first)); out[0] = wrap_shared_ptr(SharedTest(new Test(obj->create_MixedPtrs().first)),"Test", false);
out[0] = wrap_shared_ptr(ret,"Test"); out[0] = wrap_shared_ptr(obj->create_MixedPtrs().second,"Test", false);
SharedTest* ret = new SharedTest(obj->create_MixedPtrs().second);
out[1] = wrap_shared_ptr(ret,"Test");
} }
void Test_create_ptrs_23(int nargout, mxArray *out[], int nargin, const mxArray *in[]) 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<Test> Shared; typedef boost::shared_ptr<Test> Shared;
checkArguments("create_ptrs",nargout,nargin-1,0); checkArguments("create_ptrs",nargout,nargin-1,0);
Shared obj = unwrap_shared_ptr<Test>(in[0], "ptr_Test"); Shared obj = unwrap_shared_ptr<Test>(in[0], "ptr_Test");
SharedTest* ret = new SharedTest(obj->create_ptrs().first); out[0] = wrap_shared_ptr(obj->create_ptrs().first,"Test", false);
out[0] = wrap_shared_ptr(ret,"Test"); out[0] = wrap_shared_ptr(obj->create_ptrs().second,"Test", false);
SharedTest* ret = new SharedTest(obj->create_ptrs().second);
out[1] = wrap_shared_ptr(ret,"Test");
} }
void Test_print_24(int nargout, mxArray *out[], int nargin, const mxArray *in[]) 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); checkArguments("return_Point2Ptr",nargout,nargin-1,1);
Shared obj = unwrap_shared_ptr<Test>(in[0], "ptr_Test"); Shared obj = unwrap_shared_ptr<Test>(in[0], "ptr_Test");
bool value = unwrap< bool >(in[1]); bool value = unwrap< bool >(in[1]);
SharedPoint2* ret = new SharedPoint2(obj->return_Point2Ptr(value)); out[0] = wrap_shared_ptr(obj->return_Point2Ptr(value),"Point2", false);
out[0] = wrap_shared_ptr(ret,"Point2");
} }
void Test_return_Test_26(int nargout, mxArray *out[], int nargin, const mxArray *in[]) 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); checkArguments("return_Test",nargout,nargin-1,1);
Shared obj = unwrap_shared_ptr<Test>(in[0], "ptr_Test"); Shared obj = unwrap_shared_ptr<Test>(in[0], "ptr_Test");
boost::shared_ptr<Test> value = unwrap_shared_ptr< Test >(in[1], "ptr_Test"); boost::shared_ptr<Test> value = unwrap_shared_ptr< Test >(in[1], "ptr_Test");
SharedTest* ret = new SharedTest(new Test(obj->return_Test(value))); out[0] = wrap_shared_ptr(SharedTest(new Test(obj->return_Test(value))),"Test", false);
out[0] = wrap_shared_ptr(ret,"Test");
} }
void Test_return_TestPtr_27(int nargout, mxArray *out[], int nargin, const mxArray *in[]) 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); checkArguments("return_TestPtr",nargout,nargin-1,1);
Shared obj = unwrap_shared_ptr<Test>(in[0], "ptr_Test"); Shared obj = unwrap_shared_ptr<Test>(in[0], "ptr_Test");
boost::shared_ptr<Test> value = unwrap_shared_ptr< Test >(in[1], "ptr_Test"); boost::shared_ptr<Test> value = unwrap_shared_ptr< Test >(in[1], "ptr_Test");
SharedTest* ret = new SharedTest(obj->return_TestPtr(value)); out[0] = wrap_shared_ptr(obj->return_TestPtr(value),"Test", false);
out[0] = wrap_shared_ptr(ret,"Test");
} }
void Test_return_bool_28(int nargout, mxArray *out[], int nargin, const mxArray *in[]) 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<Test>(in[0], "ptr_Test"); Shared obj = unwrap_shared_ptr<Test>(in[0], "ptr_Test");
boost::shared_ptr<Test> p1 = unwrap_shared_ptr< Test >(in[1], "ptr_Test"); boost::shared_ptr<Test> p1 = unwrap_shared_ptr< Test >(in[1], "ptr_Test");
boost::shared_ptr<Test> p2 = unwrap_shared_ptr< Test >(in[2], "ptr_Test"); boost::shared_ptr<Test> p2 = unwrap_shared_ptr< Test >(in[2], "ptr_Test");
SharedTest* ret = new SharedTest(obj->return_ptrs(p1,p2).first); out[0] = wrap_shared_ptr(obj->return_ptrs(p1,p2).first,"Test", false);
out[0] = wrap_shared_ptr(ret,"Test"); out[0] = wrap_shared_ptr(obj->return_ptrs(p1,p2).second,"Test", false);
SharedTest* ret = new SharedTest(obj->return_ptrs(p1,p2).second);
out[1] = wrap_shared_ptr(ret,"Test");
} }
void Test_return_size_t_36(int nargout, mxArray *out[], int nargin, const mxArray *in[]) 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; mstream mout;
std::streambuf *outbuf = std::cout.rdbuf(&mout); std::streambuf *outbuf = std::cout.rdbuf(&mout);
if(!_RTTIRegister_geometry_done) {
_geometry_RTTIRegister();
_RTTIRegister_geometry_done = true;
}
int id = unwrap<int>(in[0]); int id = unwrap<int>(in[0]);
switch(id) { switch(id) {

View File

@ -9,9 +9,6 @@
#include <path/to/ns2.h> #include <path/to/ns2.h>
#include <path/to/ns2/ClassA.h> #include <path/to/ns2/ClassA.h>
#include <path/to/ns3.h> #include <path/to/ns3.h>
#include <path/to/ns2.h>
#include <path/to/ns2/ClassA.h>
#include <path/to/ns3.h>
typedef std::set<boost::shared_ptr<ns1::ClassA>*> Collector_ns1ClassA; typedef std::set<boost::shared_ptr<ns1::ClassA>*> Collector_ns1ClassA;
static Collector_ns1ClassA collector_ns1ClassA; static Collector_ns1ClassA collector_ns1ClassA;
@ -59,6 +56,27 @@ void _deleteAllObjects()
collector_ClassD.erase(iter++); collector_ClassD.erase(iter++);
} }
} }
static bool _RTTIRegister_testNamespaces_done = false;
void _testNamespaces_RTTIRegister() {
std::map<std::string, std::string> types;
mxArray *registry = mexGetVariable("global", "gtsamwrap_rttiRegistry");
if(!registry)
registry = mxCreateStructMatrix(1, 1, 0, NULL);
typedef std::pair<std::string, std::string> 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[]) void ns1ClassA_collectorInsertAndMakeBase_0(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{ {
mexAtExit(&_deleteAllObjects); mexAtExit(&_deleteAllObjects);
@ -67,6 +85,7 @@ void ns1ClassA_collectorInsertAndMakeBase_0(int nargout, mxArray *out[], int nar
Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0])); Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
collector_ns1ClassA.insert(self); collector_ns1ClassA.insert(self);
} }
void ns1ClassA_constructor_1(int nargout, mxArray *out[], int nargin, const mxArray *in[]) void ns1ClassA_constructor_1(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{ {
mexAtExit(&_deleteAllObjects); mexAtExit(&_deleteAllObjects);
@ -99,6 +118,7 @@ void ns1ClassB_collectorInsertAndMakeBase_3(int nargout, mxArray *out[], int nar
Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0])); Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
collector_ns1ClassB.insert(self); collector_ns1ClassB.insert(self);
} }
void ns1ClassB_constructor_4(int nargout, mxArray *out[], int nargin, const mxArray *in[]) void ns1ClassB_constructor_4(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{ {
mexAtExit(&_deleteAllObjects); mexAtExit(&_deleteAllObjects);
@ -131,6 +151,7 @@ void ns2ClassA_collectorInsertAndMakeBase_6(int nargout, mxArray *out[], int nar
Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0])); Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
collector_ns2ClassA.insert(self); collector_ns2ClassA.insert(self);
} }
void ns2ClassA_constructor_7(int nargout, mxArray *out[], int nargin, const mxArray *in[]) void ns2ClassA_constructor_7(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{ {
mexAtExit(&_deleteAllObjects); mexAtExit(&_deleteAllObjects);
@ -179,8 +200,7 @@ void ns2ClassA_nsReturn_11(int nargout, mxArray *out[], int nargin, const mxArra
checkArguments("nsReturn",nargout,nargin-1,1); checkArguments("nsReturn",nargout,nargin-1,1);
Shared obj = unwrap_shared_ptr<ns2::ClassA>(in[0], "ptr_ns2ClassA"); Shared obj = unwrap_shared_ptr<ns2::ClassA>(in[0], "ptr_ns2ClassA");
double q = unwrap< double >(in[1]); double q = unwrap< double >(in[1]);
SharedClassB* ret = new SharedClassB(new ns2::ns3::ClassB(obj->nsReturn(q))); out[0] = wrap_shared_ptr(SharedClassB(new ns2::ns3::ClassB(obj->nsReturn(q))),"ns2ns3ClassB", false);
out[0] = wrap_shared_ptr(ret,"ns2ns3ClassB");
} }
void ns2ClassA_afunction_12(int nargout, mxArray *out[], int nargin, const mxArray *in[]) 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<Shared**> (mxGetData(in[0])); Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
collector_ns2ns3ClassB.insert(self); collector_ns2ns3ClassB.insert(self);
} }
void ns2ns3ClassB_constructor_14(int nargout, mxArray *out[], int nargin, const mxArray *in[]) void ns2ns3ClassB_constructor_14(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{ {
mexAtExit(&_deleteAllObjects); mexAtExit(&_deleteAllObjects);
@ -230,6 +251,7 @@ void ns2ClassC_collectorInsertAndMakeBase_16(int nargout, mxArray *out[], int na
Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0])); Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
collector_ns2ClassC.insert(self); collector_ns2ClassC.insert(self);
} }
void ns2ClassC_constructor_17(int nargout, mxArray *out[], int nargin, const mxArray *in[]) void ns2ClassC_constructor_17(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{ {
mexAtExit(&_deleteAllObjects); mexAtExit(&_deleteAllObjects);
@ -262,6 +284,7 @@ void ClassD_collectorInsertAndMakeBase_19(int nargout, mxArray *out[], int nargi
Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0])); Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
collector_ClassD.insert(self); collector_ClassD.insert(self);
} }
void ClassD_constructor_20(int nargout, mxArray *out[], int nargin, const mxArray *in[]) void ClassD_constructor_20(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{ {
mexAtExit(&_deleteAllObjects); mexAtExit(&_deleteAllObjects);
@ -292,6 +315,10 @@ void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
mstream mout; mstream mout;
std::streambuf *outbuf = std::cout.rdbuf(&mout); std::streambuf *outbuf = std::cout.rdbuf(&mout);
if(!_RTTIRegister_testNamespaces_done) {
_testNamespaces_RTTIRegister();
_RTTIRegister_testNamespaces_done = true;
}
int id = unwrap<int>(in[0]); int id = unwrap<int>(in[0]);
switch(id) { switch(id) {