From 34a09131256ad0cfd1ab320180d477f7e352c5a0 Mon Sep 17 00:00:00 2001 From: dellaert Date: Wed, 12 Nov 2014 19:09:30 +0100 Subject: [PATCH 1/4] Fixed issue with templateArgName overloading --- wrap/Module.cpp | 11 +- wrap/tests/expected2/MyFactorPosePoint2.m | 6 +- wrap/tests/expected2/MyTemplatePoint2.m | 71 ++++- wrap/tests/expected2/MyTemplatePoint3.m | 79 +++++- wrap/tests/expected2/aGlobalFunction.m | 2 +- wrap/tests/expected2/geometry_wrapper.cpp | 242 ++++++++++++++++-- .../expected2/overloadedGlobalFunction.m | 4 +- wrap/tests/geometry.h | 9 + 8 files changed, 384 insertions(+), 40 deletions(-) diff --git a/wrap/Module.cpp b/wrap/Module.cpp index d75f6e08b..5487ca998 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -65,12 +65,15 @@ typedef rule Rule; // If a number of template arguments were given, generate a number of expanded // class names, e.g., PriorFactor -> PriorFactorPose2, and add those classes static void handle_possible_template(vector& classes, const Class& cls, - const string& templateArgName, const vector& instantiations) { - if (instantiations.empty()) { + const vector& instantiations) { + if (cls.templateArgs.empty() || instantiations.empty()) { classes.push_back(cls); } else { + if (cls.templateArgs.size() != 1) + throw std::runtime_error( + "In-line template instantiations only handle a single template argument"); vector classInstantiations = // - cls.expandTemplate(templateArgName, instantiations); + cls.expandTemplate(cls.templateArgs.front(), instantiations); BOOST_FOREACH(const Class& c, classInstantiations) classes.push_back(c); } @@ -312,7 +315,7 @@ void Module::parseMarkup(const std::string& data) { [assign_a(deconstructor.name,cls.name)] [assign_a(cls.deconstructor, deconstructor)] [bl::bind(&handle_possible_template, bl::var(classes), bl::var(cls), - bl::var(templateArgName), bl::var(templateInstantiations))] + bl::var(templateInstantiations))] [assign_a(deconstructor,deconstructor0)] [assign_a(constructor, constructor0)] [assign_a(cls,cls0)] diff --git a/wrap/tests/expected2/MyFactorPosePoint2.m b/wrap/tests/expected2/MyFactorPosePoint2.m index c847226b5..08a72ddba 100644 --- a/wrap/tests/expected2/MyFactorPosePoint2.m +++ b/wrap/tests/expected2/MyFactorPosePoint2.m @@ -12,9 +12,9 @@ classdef MyFactorPosePoint2 < handle function obj = MyFactorPosePoint2(varargin) if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) my_ptr = varargin{2}; - geometry_wrapper(53, my_ptr); + geometry_wrapper(67, my_ptr); elseif nargin == 4 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') && isa(varargin{3},'double') && isa(varargin{4},'gtsam.noiseModel.Base') - my_ptr = geometry_wrapper(54, varargin{1}, varargin{2}, varargin{3}, varargin{4}); + my_ptr = geometry_wrapper(68, varargin{1}, varargin{2}, varargin{3}, varargin{4}); else error('Arguments do not match any overload of MyFactorPosePoint2 constructor'); end @@ -22,7 +22,7 @@ classdef MyFactorPosePoint2 < handle end function delete(obj) - geometry_wrapper(55, obj.ptr_MyFactorPosePoint2); + geometry_wrapper(69, obj.ptr_MyFactorPosePoint2); end function display(obj), obj.print(''); end diff --git a/wrap/tests/expected2/MyTemplatePoint2.m b/wrap/tests/expected2/MyTemplatePoint2.m index bb3d20449..f92bb4297 100644 --- a/wrap/tests/expected2/MyTemplatePoint2.m +++ b/wrap/tests/expected2/MyTemplatePoint2.m @@ -5,6 +5,13 @@ %MyTemplatePoint2() % %-------Methods------- +%accept_T(Point2 value) : returns void +%accept_Tptr(Point2 value) : returns void +%create_MixedPtrs() : returns pair< Point2, SharedPoint2 > +%create_ptrs() : returns pair< SharedPoint2, SharedPoint2 > +%return_T(Point2 value) : returns Point2 +%return_Tptr(Point2 value) : returns Point2 +%return_ptrs(Point2 p1, Point2 p2) : returns pair< SharedPoint2, SharedPoint2 > %templatedMethod(Test t) : returns void % classdef MyTemplatePoint2 < MyBase @@ -37,11 +44,73 @@ classdef MyTemplatePoint2 < MyBase %DISPLAY Calls print on the object function disp(obj), obj.display; end %DISP Calls print on the object + function varargout = accept_T(this, varargin) + % ACCEPT_T usage: accept_T(Point2 value) : returns void + % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html + if length(varargin) == 1 && isa(varargin{1},'Point2') + geometry_wrapper(47, this, varargin{:}); + else + error('Arguments do not match any overload of function MyTemplatePoint2.accept_T'); + end + end + + function varargout = accept_Tptr(this, varargin) + % ACCEPT_TPTR usage: accept_Tptr(Point2 value) : returns void + % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html + if length(varargin) == 1 && isa(varargin{1},'Point2') + geometry_wrapper(48, this, varargin{:}); + else + error('Arguments do not match any overload of function MyTemplatePoint2.accept_Tptr'); + end + end + + function varargout = create_MixedPtrs(this, varargin) + % CREATE_MIXEDPTRS usage: create_MixedPtrs() : returns pair< Point2, SharedPoint2 > + % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html + [ varargout{1} varargout{2} ] = geometry_wrapper(49, this, varargin{:}); + end + + function varargout = create_ptrs(this, varargin) + % CREATE_PTRS usage: create_ptrs() : returns pair< SharedPoint2, SharedPoint2 > + % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html + [ varargout{1} varargout{2} ] = geometry_wrapper(50, this, varargin{:}); + end + + function varargout = return_T(this, varargin) + % RETURN_T usage: return_T(Point2 value) : returns Point2 + % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html + if length(varargin) == 1 && isa(varargin{1},'Point2') + varargout{1} = geometry_wrapper(51, this, varargin{:}); + else + error('Arguments do not match any overload of function MyTemplatePoint2.return_T'); + end + end + + function varargout = return_Tptr(this, varargin) + % RETURN_TPTR usage: return_Tptr(Point2 value) : returns Point2 + % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html + if length(varargin) == 1 && isa(varargin{1},'Point2') + varargout{1} = geometry_wrapper(52, this, varargin{:}); + else + error('Arguments do not match any overload of function MyTemplatePoint2.return_Tptr'); + end + end + + function varargout = return_ptrs(this, varargin) + % RETURN_PTRS usage: return_ptrs(Point2 p1, Point2 p2) : returns pair< SharedPoint2, SharedPoint2 > + % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html + if length(varargin) == 2 && isa(varargin{1},'Point2') && isa(varargin{2},'Point2') + [ varargout{1} varargout{2} ] = geometry_wrapper(53, this, varargin{:}); + else + error('Arguments do not match any overload of function MyTemplatePoint2.return_ptrs'); + end + end + function varargout = templatedMethod(this, varargin) % TEMPLATEDMETHOD usage: templatedMethod(Test t) : returns void % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html if length(varargin) == 1 && isa(varargin{1},'Test') - geometry_wrapper(47, this, varargin{:}); + geometry_wrapper(54, this, varargin{:}); else error('Arguments do not match any overload of function MyTemplatePoint2.templatedMethod'); end diff --git a/wrap/tests/expected2/MyTemplatePoint3.m b/wrap/tests/expected2/MyTemplatePoint3.m index fd9104328..bf3e944b9 100644 --- a/wrap/tests/expected2/MyTemplatePoint3.m +++ b/wrap/tests/expected2/MyTemplatePoint3.m @@ -5,6 +5,13 @@ %MyTemplatePoint3() % %-------Methods------- +%accept_T(Point3 value) : returns void +%accept_Tptr(Point3 value) : returns void +%create_MixedPtrs() : returns pair< Point3, SharedPoint3 > +%create_ptrs() : returns pair< SharedPoint3, SharedPoint3 > +%return_T(Point3 value) : returns Point3 +%return_Tptr(Point3 value) : returns Point3 +%return_ptrs(Point3 p1, Point3 p2) : returns pair< SharedPoint3, SharedPoint3 > %templatedMethod(Test t) : returns void % classdef MyTemplatePoint3 < MyBase @@ -17,11 +24,11 @@ classdef MyTemplatePoint3 < MyBase if nargin == 2 my_ptr = varargin{2}; else - my_ptr = geometry_wrapper(49, varargin{2}); + my_ptr = geometry_wrapper(56, varargin{2}); end - base_ptr = geometry_wrapper(48, my_ptr); + base_ptr = geometry_wrapper(55, my_ptr); elseif nargin == 0 - [ my_ptr, base_ptr ] = geometry_wrapper(50); + [ my_ptr, base_ptr ] = geometry_wrapper(57); else error('Arguments do not match any overload of MyTemplatePoint3 constructor'); end @@ -30,18 +37,80 @@ classdef MyTemplatePoint3 < MyBase end function delete(obj) - geometry_wrapper(51, obj.ptr_MyTemplatePoint3); + geometry_wrapper(58, obj.ptr_MyTemplatePoint3); end function display(obj), obj.print(''); end %DISPLAY Calls print on the object function disp(obj), obj.display; end %DISP Calls print on the object + function varargout = accept_T(this, varargin) + % ACCEPT_T usage: accept_T(Point3 value) : returns void + % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html + if length(varargin) == 1 && isa(varargin{1},'Point3') + geometry_wrapper(59, this, varargin{:}); + else + error('Arguments do not match any overload of function MyTemplatePoint3.accept_T'); + end + end + + function varargout = accept_Tptr(this, varargin) + % ACCEPT_TPTR usage: accept_Tptr(Point3 value) : returns void + % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html + if length(varargin) == 1 && isa(varargin{1},'Point3') + geometry_wrapper(60, this, varargin{:}); + else + error('Arguments do not match any overload of function MyTemplatePoint3.accept_Tptr'); + end + end + + function varargout = create_MixedPtrs(this, varargin) + % CREATE_MIXEDPTRS usage: create_MixedPtrs() : returns pair< Point3, SharedPoint3 > + % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html + [ varargout{1} varargout{2} ] = geometry_wrapper(61, this, varargin{:}); + end + + function varargout = create_ptrs(this, varargin) + % CREATE_PTRS usage: create_ptrs() : returns pair< SharedPoint3, SharedPoint3 > + % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html + [ varargout{1} varargout{2} ] = geometry_wrapper(62, this, varargin{:}); + end + + function varargout = return_T(this, varargin) + % RETURN_T usage: return_T(Point3 value) : returns Point3 + % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html + if length(varargin) == 1 && isa(varargin{1},'Point3') + varargout{1} = geometry_wrapper(63, this, varargin{:}); + else + error('Arguments do not match any overload of function MyTemplatePoint3.return_T'); + end + end + + function varargout = return_Tptr(this, varargin) + % RETURN_TPTR usage: return_Tptr(Point3 value) : returns Point3 + % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html + if length(varargin) == 1 && isa(varargin{1},'Point3') + varargout{1} = geometry_wrapper(64, this, varargin{:}); + else + error('Arguments do not match any overload of function MyTemplatePoint3.return_Tptr'); + end + end + + function varargout = return_ptrs(this, varargin) + % RETURN_PTRS usage: return_ptrs(Point3 p1, Point3 p2) : returns pair< SharedPoint3, SharedPoint3 > + % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html + if length(varargin) == 2 && isa(varargin{1},'Point3') && isa(varargin{2},'Point3') + [ varargout{1} varargout{2} ] = geometry_wrapper(65, this, varargin{:}); + else + error('Arguments do not match any overload of function MyTemplatePoint3.return_ptrs'); + end + end + function varargout = templatedMethod(this, varargin) % TEMPLATEDMETHOD usage: templatedMethod(Test t) : returns void % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html if length(varargin) == 1 && isa(varargin{1},'Test') - geometry_wrapper(52, this, varargin{:}); + geometry_wrapper(66, this, varargin{:}); else error('Arguments do not match any overload of function MyTemplatePoint3.templatedMethod'); end diff --git a/wrap/tests/expected2/aGlobalFunction.m b/wrap/tests/expected2/aGlobalFunction.m index 84d93b939..2e87a30b0 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(56, varargin{:}); + varargout{1} = geometry_wrapper(70, 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 811a3fca8..00f64c708 100644 --- a/wrap/tests/expected2/geometry_wrapper.cpp +++ b/wrap/tests/expected2/geometry_wrapper.cpp @@ -588,7 +588,83 @@ void MyTemplatePoint2_deconstructor_46(int nargout, mxArray *out[], int nargin, } } -void MyTemplatePoint2_templatedMethod_47(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void MyTemplatePoint2_accept_T_47(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr Shared; + checkArguments("accept_T",nargout,nargin-1,1); + Shared obj = unwrap_shared_ptr(in[0], "ptr_MyTemplatePoint2"); + Point2& value = *unwrap_shared_ptr< Point2 >(in[1], "ptr_Point2"); + obj->accept_T(value); +} + +void MyTemplatePoint2_accept_Tptr_48(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr Shared; + checkArguments("accept_Tptr",nargout,nargin-1,1); + Shared obj = unwrap_shared_ptr(in[0], "ptr_MyTemplatePoint2"); + boost::shared_ptr value = unwrap_shared_ptr< Point2 >(in[1], "ptr_Point2"); + obj->accept_Tptr(value); +} + +void MyTemplatePoint2_create_MixedPtrs_49(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr SharedPoint2; + typedef boost::shared_ptr SharedPoint2; + typedef boost::shared_ptr Shared; + checkArguments("create_MixedPtrs",nargout,nargin-1,0); + Shared obj = unwrap_shared_ptr(in[0], "ptr_MyTemplatePoint2"); + pair< Point2, SharedPoint2 > pairResult = obj->create_MixedPtrs(); + out[0] = wrap_shared_ptr(SharedPoint2(new Point2(pairResult.first)),"Point2", false); + out[1] = wrap_shared_ptr(pairResult.second,"Point2", false); +} + +void MyTemplatePoint2_create_ptrs_50(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr SharedPoint2; + typedef boost::shared_ptr SharedPoint2; + typedef boost::shared_ptr Shared; + checkArguments("create_ptrs",nargout,nargin-1,0); + Shared obj = unwrap_shared_ptr(in[0], "ptr_MyTemplatePoint2"); + pair< SharedPoint2, SharedPoint2 > pairResult = obj->create_ptrs(); + out[0] = wrap_shared_ptr(pairResult.first,"Point2", false); + out[1] = wrap_shared_ptr(pairResult.second,"Point2", false); +} + +void MyTemplatePoint2_return_T_51(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr SharedPoint2; + typedef boost::shared_ptr Shared; + checkArguments("return_T",nargout,nargin-1,1); + Shared obj = unwrap_shared_ptr(in[0], "ptr_MyTemplatePoint2"); + boost::shared_ptr value = unwrap_shared_ptr< Point2 >(in[1], "ptr_Point2"); + out[0] = wrap_shared_ptr(SharedPoint2(new Point2(obj->return_T(value))),"Point2", false); +} + +void MyTemplatePoint2_return_Tptr_52(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr SharedPoint2; + typedef boost::shared_ptr Shared; + checkArguments("return_Tptr",nargout,nargin-1,1); + Shared obj = unwrap_shared_ptr(in[0], "ptr_MyTemplatePoint2"); + boost::shared_ptr value = unwrap_shared_ptr< Point2 >(in[1], "ptr_Point2"); + out[0] = wrap_shared_ptr(obj->return_Tptr(value),"Point2", false); +} + +void MyTemplatePoint2_return_ptrs_53(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr SharedPoint2; + typedef boost::shared_ptr SharedPoint2; + typedef boost::shared_ptr Shared; + checkArguments("return_ptrs",nargout,nargin-1,2); + Shared obj = unwrap_shared_ptr(in[0], "ptr_MyTemplatePoint2"); + boost::shared_ptr p1 = unwrap_shared_ptr< Point2 >(in[1], "ptr_Point2"); + boost::shared_ptr p2 = unwrap_shared_ptr< Point2 >(in[2], "ptr_Point2"); + pair< SharedPoint2, SharedPoint2 > pairResult = obj->return_ptrs(p1,p2); + out[0] = wrap_shared_ptr(pairResult.first,"Point2", false); + out[1] = wrap_shared_ptr(pairResult.second,"Point2", false); +} + +void MyTemplatePoint2_templatedMethod_54(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { typedef boost::shared_ptr Shared; checkArguments("templatedMethod",nargout,nargin-1,1); @@ -597,7 +673,7 @@ void MyTemplatePoint2_templatedMethod_47(int nargout, mxArray *out[], int nargin obj->templatedMethod(t); } -void MyTemplatePoint3_collectorInsertAndMakeBase_48(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void MyTemplatePoint3_collectorInsertAndMakeBase_55(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); typedef boost::shared_ptr Shared; @@ -610,7 +686,7 @@ void MyTemplatePoint3_collectorInsertAndMakeBase_48(int nargout, mxArray *out[], *reinterpret_cast(mxGetData(out[0])) = new SharedBase(*self); } -void MyTemplatePoint3_upcastFromVoid_49(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { +void MyTemplatePoint3_upcastFromVoid_56(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])); @@ -619,7 +695,7 @@ void MyTemplatePoint3_upcastFromVoid_49(int nargout, mxArray *out[], int nargin, *reinterpret_cast(mxGetData(out[0])) = self; } -void MyTemplatePoint3_constructor_50(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void MyTemplatePoint3_constructor_57(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); typedef boost::shared_ptr Shared; @@ -634,7 +710,7 @@ void MyTemplatePoint3_constructor_50(int nargout, mxArray *out[], int nargin, co *reinterpret_cast(mxGetData(out[1])) = new SharedBase(*self); } -void MyTemplatePoint3_deconstructor_51(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void MyTemplatePoint3_deconstructor_58(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { typedef boost::shared_ptr Shared; checkArguments("delete_MyTemplatePoint3",nargout,nargin,1); @@ -647,7 +723,83 @@ void MyTemplatePoint3_deconstructor_51(int nargout, mxArray *out[], int nargin, } } -void MyTemplatePoint3_templatedMethod_52(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void MyTemplatePoint3_accept_T_59(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr Shared; + checkArguments("accept_T",nargout,nargin-1,1); + Shared obj = unwrap_shared_ptr(in[0], "ptr_MyTemplatePoint3"); + Point3& value = *unwrap_shared_ptr< Point3 >(in[1], "ptr_Point3"); + obj->accept_T(value); +} + +void MyTemplatePoint3_accept_Tptr_60(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr Shared; + checkArguments("accept_Tptr",nargout,nargin-1,1); + Shared obj = unwrap_shared_ptr(in[0], "ptr_MyTemplatePoint3"); + boost::shared_ptr value = unwrap_shared_ptr< Point3 >(in[1], "ptr_Point3"); + obj->accept_Tptr(value); +} + +void MyTemplatePoint3_create_MixedPtrs_61(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr SharedPoint3; + typedef boost::shared_ptr SharedPoint3; + typedef boost::shared_ptr Shared; + checkArguments("create_MixedPtrs",nargout,nargin-1,0); + Shared obj = unwrap_shared_ptr(in[0], "ptr_MyTemplatePoint3"); + pair< Point3, SharedPoint3 > pairResult = obj->create_MixedPtrs(); + out[0] = wrap_shared_ptr(SharedPoint3(new Point3(pairResult.first)),"Point3", false); + out[1] = wrap_shared_ptr(pairResult.second,"Point3", false); +} + +void MyTemplatePoint3_create_ptrs_62(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr SharedPoint3; + typedef boost::shared_ptr SharedPoint3; + typedef boost::shared_ptr Shared; + checkArguments("create_ptrs",nargout,nargin-1,0); + Shared obj = unwrap_shared_ptr(in[0], "ptr_MyTemplatePoint3"); + pair< SharedPoint3, SharedPoint3 > pairResult = obj->create_ptrs(); + out[0] = wrap_shared_ptr(pairResult.first,"Point3", false); + out[1] = wrap_shared_ptr(pairResult.second,"Point3", false); +} + +void MyTemplatePoint3_return_T_63(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr SharedPoint3; + typedef boost::shared_ptr Shared; + checkArguments("return_T",nargout,nargin-1,1); + Shared obj = unwrap_shared_ptr(in[0], "ptr_MyTemplatePoint3"); + boost::shared_ptr value = unwrap_shared_ptr< Point3 >(in[1], "ptr_Point3"); + out[0] = wrap_shared_ptr(SharedPoint3(new Point3(obj->return_T(value))),"Point3", false); +} + +void MyTemplatePoint3_return_Tptr_64(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr SharedPoint3; + typedef boost::shared_ptr Shared; + checkArguments("return_Tptr",nargout,nargin-1,1); + Shared obj = unwrap_shared_ptr(in[0], "ptr_MyTemplatePoint3"); + boost::shared_ptr value = unwrap_shared_ptr< Point3 >(in[1], "ptr_Point3"); + out[0] = wrap_shared_ptr(obj->return_Tptr(value),"Point3", false); +} + +void MyTemplatePoint3_return_ptrs_65(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + typedef boost::shared_ptr SharedPoint3; + typedef boost::shared_ptr SharedPoint3; + typedef boost::shared_ptr Shared; + checkArguments("return_ptrs",nargout,nargin-1,2); + Shared obj = unwrap_shared_ptr(in[0], "ptr_MyTemplatePoint3"); + boost::shared_ptr p1 = unwrap_shared_ptr< Point3 >(in[1], "ptr_Point3"); + boost::shared_ptr p2 = unwrap_shared_ptr< Point3 >(in[2], "ptr_Point3"); + pair< SharedPoint3, SharedPoint3 > pairResult = obj->return_ptrs(p1,p2); + out[0] = wrap_shared_ptr(pairResult.first,"Point3", false); + out[1] = wrap_shared_ptr(pairResult.second,"Point3", false); +} + +void MyTemplatePoint3_templatedMethod_66(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { typedef boost::shared_ptr Shared; checkArguments("templatedMethod",nargout,nargin-1,1); @@ -656,7 +808,7 @@ void MyTemplatePoint3_templatedMethod_52(int nargout, mxArray *out[], int nargin obj->templatedMethod(t); } -void MyFactorPosePoint2_collectorInsertAndMakeBase_53(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void MyFactorPosePoint2_collectorInsertAndMakeBase_67(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); typedef boost::shared_ptr Shared; @@ -665,7 +817,7 @@ void MyFactorPosePoint2_collectorInsertAndMakeBase_53(int nargout, mxArray *out[ collector_MyFactorPosePoint2.insert(self); } -void MyFactorPosePoint2_constructor_54(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void MyFactorPosePoint2_constructor_68(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); typedef boost::shared_ptr Shared; @@ -680,7 +832,7 @@ void MyFactorPosePoint2_constructor_54(int nargout, mxArray *out[], int nargin, *reinterpret_cast (mxGetData(out[0])) = self; } -void MyFactorPosePoint2_deconstructor_55(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void MyFactorPosePoint2_deconstructor_69(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { typedef boost::shared_ptr Shared; checkArguments("delete_MyFactorPosePoint2",nargout,nargin,1); @@ -693,18 +845,18 @@ void MyFactorPosePoint2_deconstructor_55(int nargout, mxArray *out[], int nargin } } -void aGlobalFunction_56(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void aGlobalFunction_70(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("aGlobalFunction",nargout,nargin,0); out[0] = wrap< Vector >(aGlobalFunction()); } -void overloadedGlobalFunction_57(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void overloadedGlobalFunction_71(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_58(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void overloadedGlobalFunction_72(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("overloadedGlobalFunction",nargout,nargin,2); int a = unwrap< int >(in[0]); @@ -865,40 +1017,82 @@ void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) MyTemplatePoint2_deconstructor_46(nargout, out, nargin-1, in+1); break; case 47: - MyTemplatePoint2_templatedMethod_47(nargout, out, nargin-1, in+1); + MyTemplatePoint2_accept_T_47(nargout, out, nargin-1, in+1); break; case 48: - MyTemplatePoint3_collectorInsertAndMakeBase_48(nargout, out, nargin-1, in+1); + MyTemplatePoint2_accept_Tptr_48(nargout, out, nargin-1, in+1); break; case 49: - MyTemplatePoint3_upcastFromVoid_49(nargout, out, nargin-1, in+1); + MyTemplatePoint2_create_MixedPtrs_49(nargout, out, nargin-1, in+1); break; case 50: - MyTemplatePoint3_constructor_50(nargout, out, nargin-1, in+1); + MyTemplatePoint2_create_ptrs_50(nargout, out, nargin-1, in+1); break; case 51: - MyTemplatePoint3_deconstructor_51(nargout, out, nargin-1, in+1); + MyTemplatePoint2_return_T_51(nargout, out, nargin-1, in+1); break; case 52: - MyTemplatePoint3_templatedMethod_52(nargout, out, nargin-1, in+1); + MyTemplatePoint2_return_Tptr_52(nargout, out, nargin-1, in+1); break; case 53: - MyFactorPosePoint2_collectorInsertAndMakeBase_53(nargout, out, nargin-1, in+1); + MyTemplatePoint2_return_ptrs_53(nargout, out, nargin-1, in+1); break; case 54: - MyFactorPosePoint2_constructor_54(nargout, out, nargin-1, in+1); + MyTemplatePoint2_templatedMethod_54(nargout, out, nargin-1, in+1); break; case 55: - MyFactorPosePoint2_deconstructor_55(nargout, out, nargin-1, in+1); + MyTemplatePoint3_collectorInsertAndMakeBase_55(nargout, out, nargin-1, in+1); break; case 56: - aGlobalFunction_56(nargout, out, nargin-1, in+1); + MyTemplatePoint3_upcastFromVoid_56(nargout, out, nargin-1, in+1); break; case 57: - overloadedGlobalFunction_57(nargout, out, nargin-1, in+1); + MyTemplatePoint3_constructor_57(nargout, out, nargin-1, in+1); break; case 58: - overloadedGlobalFunction_58(nargout, out, nargin-1, in+1); + MyTemplatePoint3_deconstructor_58(nargout, out, nargin-1, in+1); + break; + case 59: + MyTemplatePoint3_accept_T_59(nargout, out, nargin-1, in+1); + break; + case 60: + MyTemplatePoint3_accept_Tptr_60(nargout, out, nargin-1, in+1); + break; + case 61: + MyTemplatePoint3_create_MixedPtrs_61(nargout, out, nargin-1, in+1); + break; + case 62: + MyTemplatePoint3_create_ptrs_62(nargout, out, nargin-1, in+1); + break; + case 63: + MyTemplatePoint3_return_T_63(nargout, out, nargin-1, in+1); + break; + case 64: + MyTemplatePoint3_return_Tptr_64(nargout, out, nargin-1, in+1); + break; + case 65: + MyTemplatePoint3_return_ptrs_65(nargout, out, nargin-1, in+1); + break; + case 66: + MyTemplatePoint3_templatedMethod_66(nargout, out, nargin-1, in+1); + break; + case 67: + MyFactorPosePoint2_collectorInsertAndMakeBase_67(nargout, out, nargin-1, in+1); + break; + case 68: + MyFactorPosePoint2_constructor_68(nargout, out, nargin-1, in+1); + break; + case 69: + MyFactorPosePoint2_deconstructor_69(nargout, out, nargin-1, in+1); + break; + case 70: + aGlobalFunction_70(nargout, out, nargin-1, in+1); + break; + case 71: + overloadedGlobalFunction_71(nargout, out, nargin-1, in+1); + break; + case 72: + overloadedGlobalFunction_72(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 31653ba61..b242dbac0 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(57, varargin{:}); + varargout{1} = geometry_wrapper(71, varargin{:}); elseif length(varargin) == 2 && isa(varargin{1},'numeric') && isa(varargin{2},'double') - varargout{1} = geometry_wrapper(58, varargin{:}); + varargout{1} = geometry_wrapper(72, 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 406793cad..9bc56f1ed 100644 --- a/wrap/tests/geometry.h +++ b/wrap/tests/geometry.h @@ -103,6 +103,15 @@ virtual class MyTemplate : MyBase { template void templatedMethod(const Test& t); + + // Stress test templates and pointer combinations + void accept_T(const T& value) const; + void accept_Tptr(T* value) const; + T* return_Tptr(T* value) const; + T return_T(T* value) const; + pair create_ptrs () const; + pair create_MixedPtrs () const; + pair return_ptrs (T* p1, T* p2) const; }; // A doubly templated class From 72d44fe0af0b1cacdf317b8736bd2f6b2858229e Mon Sep 17 00:00:00 2001 From: dellaert Date: Wed, 12 Nov 2014 20:50:20 +0100 Subject: [PATCH 2/4] Fixed docs --- wrap/tests/expected2/MyTemplatePoint2.m | 12 ++++++------ wrap/tests/expected2/MyTemplatePoint3.m | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/wrap/tests/expected2/MyTemplatePoint2.m b/wrap/tests/expected2/MyTemplatePoint2.m index f92bb4297..272ab9ebd 100644 --- a/wrap/tests/expected2/MyTemplatePoint2.m +++ b/wrap/tests/expected2/MyTemplatePoint2.m @@ -7,11 +7,11 @@ %-------Methods------- %accept_T(Point2 value) : returns void %accept_Tptr(Point2 value) : returns void -%create_MixedPtrs() : returns pair< Point2, SharedPoint2 > -%create_ptrs() : returns pair< SharedPoint2, SharedPoint2 > +%create_MixedPtrs() : returns pair< Point2, Point2 > +%create_ptrs() : returns pair< Point2, Point2 > %return_T(Point2 value) : returns Point2 %return_Tptr(Point2 value) : returns Point2 -%return_ptrs(Point2 p1, Point2 p2) : returns pair< SharedPoint2, SharedPoint2 > +%return_ptrs(Point2 p1, Point2 p2) : returns pair< Point2, Point2 > %templatedMethod(Test t) : returns void % classdef MyTemplatePoint2 < MyBase @@ -65,13 +65,13 @@ classdef MyTemplatePoint2 < MyBase end function varargout = create_MixedPtrs(this, varargin) - % CREATE_MIXEDPTRS usage: create_MixedPtrs() : returns pair< Point2, SharedPoint2 > + % CREATE_MIXEDPTRS usage: create_MixedPtrs() : returns pair< Point2, Point2 > % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html [ varargout{1} varargout{2} ] = geometry_wrapper(49, this, varargin{:}); end function varargout = create_ptrs(this, varargin) - % CREATE_PTRS usage: create_ptrs() : returns pair< SharedPoint2, SharedPoint2 > + % CREATE_PTRS usage: create_ptrs() : returns pair< Point2, Point2 > % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html [ varargout{1} varargout{2} ] = geometry_wrapper(50, this, varargin{:}); end @@ -97,7 +97,7 @@ classdef MyTemplatePoint2 < MyBase end function varargout = return_ptrs(this, varargin) - % RETURN_PTRS usage: return_ptrs(Point2 p1, Point2 p2) : returns pair< SharedPoint2, SharedPoint2 > + % RETURN_PTRS usage: return_ptrs(Point2 p1, Point2 p2) : returns pair< Point2, Point2 > % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html if length(varargin) == 2 && isa(varargin{1},'Point2') && isa(varargin{2},'Point2') [ varargout{1} varargout{2} ] = geometry_wrapper(53, this, varargin{:}); diff --git a/wrap/tests/expected2/MyTemplatePoint3.m b/wrap/tests/expected2/MyTemplatePoint3.m index bf3e944b9..ab66bd30c 100644 --- a/wrap/tests/expected2/MyTemplatePoint3.m +++ b/wrap/tests/expected2/MyTemplatePoint3.m @@ -7,11 +7,11 @@ %-------Methods------- %accept_T(Point3 value) : returns void %accept_Tptr(Point3 value) : returns void -%create_MixedPtrs() : returns pair< Point3, SharedPoint3 > -%create_ptrs() : returns pair< SharedPoint3, SharedPoint3 > +%create_MixedPtrs() : returns pair< Point3, Point3 > +%create_ptrs() : returns pair< Point3, Point3 > %return_T(Point3 value) : returns Point3 %return_Tptr(Point3 value) : returns Point3 -%return_ptrs(Point3 p1, Point3 p2) : returns pair< SharedPoint3, SharedPoint3 > +%return_ptrs(Point3 p1, Point3 p2) : returns pair< Point3, Point3 > %templatedMethod(Test t) : returns void % classdef MyTemplatePoint3 < MyBase @@ -65,13 +65,13 @@ classdef MyTemplatePoint3 < MyBase end function varargout = create_MixedPtrs(this, varargin) - % CREATE_MIXEDPTRS usage: create_MixedPtrs() : returns pair< Point3, SharedPoint3 > + % CREATE_MIXEDPTRS usage: create_MixedPtrs() : returns pair< Point3, Point3 > % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html [ varargout{1} varargout{2} ] = geometry_wrapper(61, this, varargin{:}); end function varargout = create_ptrs(this, varargin) - % CREATE_PTRS usage: create_ptrs() : returns pair< SharedPoint3, SharedPoint3 > + % CREATE_PTRS usage: create_ptrs() : returns pair< Point3, Point3 > % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html [ varargout{1} varargout{2} ] = geometry_wrapper(62, this, varargin{:}); end @@ -97,7 +97,7 @@ classdef MyTemplatePoint3 < MyBase end function varargout = return_ptrs(this, varargin) - % RETURN_PTRS usage: return_ptrs(Point3 p1, Point3 p2) : returns pair< SharedPoint3, SharedPoint3 > + % RETURN_PTRS usage: return_ptrs(Point3 p1, Point3 p2) : returns pair< Point3, Point3 > % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html if length(varargin) == 2 && isa(varargin{1},'Point3') && isa(varargin{2},'Point3') [ varargout{1} varargout{2} ] = geometry_wrapper(65, this, varargin{:}); From 7d4f5a48203a3fdaa6bd2c722db67e7781b6048b Mon Sep 17 00:00:00 2001 From: dellaert Date: Wed, 12 Nov 2014 20:51:47 +0100 Subject: [PATCH 3/4] Make explicit whether wrapper or proxy is written to... --- wrap/Argument.cpp | 31 +++++++++--------- wrap/Argument.h | 12 +++---- wrap/Method.cpp | 78 ++++++++++++++++++++++---------------------- wrap/Method.h | 21 ++++++------ wrap/ReturnValue.cpp | 30 ++++++++--------- 5 files changed, 86 insertions(+), 86 deletions(-) diff --git a/wrap/Argument.cpp b/wrap/Argument.cpp index 6e9ac5514..cc235207a 100644 --- a/wrap/Argument.cpp +++ b/wrap/Argument.cpp @@ -156,36 +156,37 @@ void ArgumentList::emit_prototype(FileWriter& file, const string& name) const { file.oss << ")"; } /* ************************************************************************* */ -void ArgumentList::emit_call(FileWriter& file, const ReturnValue& returnVal, - const string& wrapperName, int id, bool staticMethod) const { - returnVal.emit_matlab(file); - file.oss << wrapperName << "(" << id; +void ArgumentList::emit_call(FileWriter& proxyFile, + const ReturnValue& returnVal, const string& wrapperName, int id, + bool staticMethod) const { + returnVal.emit_matlab(proxyFile); + proxyFile.oss << wrapperName << "(" << id; if (!staticMethod) - file.oss << ", this"; - file.oss << ", varargin{:});\n"; + proxyFile.oss << ", this"; + proxyFile.oss << ", varargin{:});\n"; } /* ************************************************************************* */ -void ArgumentList::emit_conditional_call(FileWriter& file, +void ArgumentList::emit_conditional_call(FileWriter& proxyFile, const ReturnValue& returnVal, const string& wrapperName, int id, bool staticMethod) const { // Check nr of arguments - file.oss << "if length(varargin) == " << size(); + proxyFile.oss << "if length(varargin) == " << size(); if (size() > 0) - file.oss << " && "; + proxyFile.oss << " && "; // ...and their type.names bool first = true; for (size_t i = 0; i < size(); i++) { if (!first) - file.oss << " && "; - file.oss << "isa(varargin{" << i + 1 << "},'" << (*this)[i].matlabClass(".") - << "')"; + proxyFile.oss << " && "; + proxyFile.oss << "isa(varargin{" << i + 1 << "},'" + << (*this)[i].matlabClass(".") << "')"; first = false; } - file.oss << "\n"; + proxyFile.oss << "\n"; // output call to C++ wrapper - file.oss << " "; - emit_call(file, returnVal, wrapperName, id, staticMethod); + proxyFile.oss << " "; + emit_call(proxyFile, returnVal, wrapperName, id, staticMethod); } /* ************************************************************************* */ diff --git a/wrap/Argument.h b/wrap/Argument.h index 73bc66929..8c0bb9a33 100644 --- a/wrap/Argument.h +++ b/wrap/Argument.h @@ -77,23 +77,23 @@ struct ArgumentList: public std::vector { void emit_prototype(FileWriter& file, const std::string& name) const; /** - * emit emit MATLAB call to wrapper - * @param file output stream + * emit emit MATLAB call to proxy + * @param proxyFile output stream * @param returnVal the return value * @param wrapperName of method or function * @param staticMethod flag to emit "this" in call */ - void emit_call(FileWriter& file, const ReturnValue& returnVal, + void emit_call(FileWriter& proxyFile, const ReturnValue& returnVal, const std::string& wrapperName, int id, bool staticMethod = false) const; /** - * emit conditional MATLAB call to wrapper (checking arguments first) - * @param file output stream + * emit conditional MATLAB call to proxy (checking arguments first) + * @param proxyFile output stream * @param returnVal the return value * @param wrapperName of method or function * @param staticMethod flag to emit "this" in call */ - void emit_conditional_call(FileWriter& file, const ReturnValue& returnVal, + void emit_conditional_call(FileWriter& proxyFile, const ReturnValue& returnVal, const std::string& wrapperName, int id, bool staticMethod = false) const; }; diff --git a/wrap/Method.cpp b/wrap/Method.cpp index 933d78858..8f18c5f94 100644 --- a/wrap/Method.cpp +++ b/wrap/Method.cpp @@ -39,51 +39,51 @@ void Method::addOverload(bool verbose, bool is_const, const std::string& name, } /* ************************************************************************* */ -void Method::proxy_wrapper_fragments(FileWriter& file, FileWriter& wrapperFile, - const string& cppClassName, const std::string& matlabQualName, - const std::string& matlabUniqueName, const string& wrapperName, - const TypeAttributesTable& typeAttributes, +void Method::proxy_wrapper_fragments(FileWriter& proxyFile, + FileWriter& wrapperFile, const string& cppClassName, + const std::string& matlabQualName, const std::string& matlabUniqueName, + const string& wrapperName, const TypeAttributesTable& typeAttributes, vector& functionNames) const { // Create function header - file.oss << " function varargout = " << name << "(this, varargin)\n"; + proxyFile.oss << " function varargout = " << name << "(this, varargin)\n"; // Emit comments for documentation string up_name = boost::to_upper_copy(name); - file.oss << " % " << up_name << " usage: "; + proxyFile.oss << " % " << up_name << " usage: "; unsigned int argLCount = 0; BOOST_FOREACH(ArgumentList argList, argLists) { - argList.emit_prototype(file, name); + argList.emit_prototype(proxyFile, name); if (argLCount != argLists.size() - 1) - file.oss << ", "; + proxyFile.oss << ", "; else - file.oss << " : returns " - << returnVals[0].return_type(false) << endl; + proxyFile.oss << " : returns " << returnVals[0].return_type(false) + << endl; argLCount++; } // Emit URL to Doxygen page - file.oss << " % " + proxyFile.oss << " % " << "Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html" << endl; // Document all overloads, if any if (argLists.size() > 1) { - file.oss << " % " << "" << endl; - file.oss << " % " << "Method Overloads" << endl; + proxyFile.oss << " % " << "" << endl; + proxyFile.oss << " % " << "Method Overloads" << endl; BOOST_FOREACH(ArgumentList argList, argLists) { - file.oss << " % "; - argList.emit_prototype(file, name); - file.oss << endl; + proxyFile.oss << " % "; + argList.emit_prototype(proxyFile, name); + proxyFile.oss << endl; } } // Handle special case of single overload with all numeric arguments if (argLists.size() == 1 && argLists[0].allScalar()) { // Output proxy matlab code - file.oss << " "; + proxyFile.oss << " "; const int id = (int) functionNames.size(); - argLists[0].emit_call(file, returnVals[0], wrapperName, id); + argLists[0].emit_call(proxyFile, returnVals[0], wrapperName, id); // Output C++ wrapper code const string wrapFunctionName = wrapper_fragment(wrapperFile, cppClassName, @@ -96,9 +96,9 @@ void Method::proxy_wrapper_fragments(FileWriter& file, FileWriter& wrapperFile, for (size_t overload = 0; overload < argLists.size(); ++overload) { // Output proxy matlab code - file.oss << " " << (overload == 0 ? "" : "else"); + proxyFile.oss << " " << (overload == 0 ? "" : "else"); const int id = (int) functionNames.size(); - argLists[overload].emit_conditional_call(file, returnVals[overload], + argLists[overload].emit_conditional_call(proxyFile, returnVals[overload], wrapperName, id); // Output C++ wrapper code @@ -108,20 +108,20 @@ void Method::proxy_wrapper_fragments(FileWriter& file, FileWriter& wrapperFile, // Add to function list functionNames.push_back(wrapFunctionName); } - file.oss << " else\n"; - file.oss + proxyFile.oss << " else\n"; + proxyFile.oss << " error('Arguments do not match any overload of function " << matlabQualName << "." << name << "');" << endl; - file.oss << " end\n"; + proxyFile.oss << " end\n"; } - file.oss << " end\n"; + proxyFile.oss << " end\n"; } /* ************************************************************************* */ -string Method::wrapper_fragment(FileWriter& file, const string& cppClassName, - const string& matlabUniqueName, int overload, int id, - const TypeAttributesTable& typeAttributes) const { +string Method::wrapper_fragment(FileWriter& wrapperFile, + const string& cppClassName, const string& matlabUniqueName, int overload, + int id, const TypeAttributesTable& typeAttributes) const { // generate code @@ -132,39 +132,39 @@ string Method::wrapper_fragment(FileWriter& file, const string& cppClassName, const ReturnValue& returnVal = returnVals[overload]; // call - file.oss << "void " << wrapFunctionName + wrapperFile.oss << "void " << wrapFunctionName << "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n"; // start - file.oss << "{\n"; + wrapperFile.oss << "{\n"; - returnVal.wrapTypeUnwrap(file); + returnVal.wrapTypeUnwrap(wrapperFile); - file.oss << " typedef boost::shared_ptr<" << cppClassName << "> Shared;" - << endl; + wrapperFile.oss << " typedef boost::shared_ptr<" << cppClassName + << "> Shared;" << endl; // check arguments // extra argument obj -> nargin-1 is passed ! // example: checkArguments("equals",nargout,nargin-1,2); - file.oss << " checkArguments(\"" << name << "\",nargout,nargin-1," + wrapperFile.oss << " checkArguments(\"" << name << "\",nargout,nargin-1," << args.size() << ");\n"; // get class pointer // example: shared_ptr = unwrap_shared_ptr< Test >(in[0], "Test"); - file.oss << " Shared obj = unwrap_shared_ptr<" << cppClassName + wrapperFile.oss << " Shared obj = unwrap_shared_ptr<" << cppClassName << ">(in[0], \"ptr_" << matlabUniqueName << "\");" << endl; // unwrap arguments, see Argument.cpp - args.matlab_unwrap(file, 1); + args.matlab_unwrap(wrapperFile, 1); // call method and wrap result // example: out[0]=wrap(self->return_field(t)); if (returnVal.type1.name != "void") - returnVal.wrap_result("obj->" + name + "(" + args.names() + ")", file, - typeAttributes); + returnVal.wrap_result("obj->" + name + "(" + args.names() + ")", + wrapperFile, typeAttributes); else - file.oss << " obj->" + name + "(" + args.names() + ");\n"; + wrapperFile.oss << " obj->" + name + "(" + args.names() + ");\n"; // finish - file.oss << "}\n"; + wrapperFile.oss << "}\n"; return wrapFunctionName; } diff --git a/wrap/Method.h b/wrap/Method.h index 9926a5179..fa512d874 100644 --- a/wrap/Method.h +++ b/wrap/Method.h @@ -32,7 +32,8 @@ struct Method { /// Constructor creates empty object Method(bool verbose = true) : - verbose_(verbose), is_const_(false) {} + verbose_(verbose), is_const_(false) { + } // Then the instance variables are set directly by the Module constructor bool verbose_; @@ -45,22 +46,20 @@ struct Method { // with those in rhs, but in subsequent calls it adds additional argument // lists as function overloads. void addOverload(bool verbose, bool is_const, const std::string& name, - const ArgumentList& args, const ReturnValue& retVal); + const ArgumentList& args, const ReturnValue& retVal); // MATLAB code generation // classPath is class directory, e.g., ../matlab/@Point2 void proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, - const std::string& cppClassName, const std::string& matlabQualName, const std::string& matlabUniqueName, - const std::string& wrapperName, const TypeAttributesTable& typeAttributes, - std::vector& functionNames) const; + const std::string& cppClassName, const std::string& matlabQualName, + const std::string& matlabUniqueName, const std::string& wrapperName, + const TypeAttributesTable& typeAttributes, + std::vector& functionNames) const; private: - std::string wrapper_fragment(FileWriter& file, - const std::string& cppClassName, - const std::string& matlabUniqueName, - int overload, - int id, - const TypeAttributesTable& typeAttributes) const; ///< cpp wrapper + std::string wrapper_fragment(FileWriter& wrapperFile, + const std::string& cppClassName, const std::string& matlabUniqueName, + int overload, int id, const TypeAttributesTable& typeAttributes) const; ///< cpp wrapper }; } // \namespace wrap diff --git a/wrap/ReturnValue.cpp b/wrap/ReturnValue.cpp index cd8273731..5287410e0 100644 --- a/wrap/ReturnValue.cpp +++ b/wrap/ReturnValue.cpp @@ -7,10 +7,10 @@ * @author Richard Roberts */ -#include - #include "ReturnValue.h" #include "utilities.h" +#include +#include using namespace std; using namespace wrap; @@ -52,9 +52,9 @@ void ReturnType::wrap_result(const string& out, const string& result, } /* ************************************************************************* */ -void ReturnType::wrapTypeUnwrap(FileWriter& file) const { +void ReturnType::wrapTypeUnwrap(FileWriter& wrapperFile) const { if (category == CLASS) - file.oss << " typedef boost::shared_ptr<" << qualifiedName("::") + wrapperFile.oss << " typedef boost::shared_ptr<" << qualifiedName("::") << "> Shared" << name << ";" << endl; } @@ -72,33 +72,33 @@ string ReturnValue::matlab_returnType() const { } /* ************************************************************************* */ -void ReturnValue::wrap_result(const string& result, FileWriter& file, +void ReturnValue::wrap_result(const string& result, FileWriter& wrapperFile, const TypeAttributesTable& typeAttributes) const { if (isPair) { // For a pair, store the returned pair so we do not evaluate the function twice - file.oss << " " << return_type(true) << " pairResult = " << result + wrapperFile.oss << " " << return_type(true) << " pairResult = " << result << ";\n"; - type1.wrap_result(" out[0]", "pairResult.first", file, typeAttributes); - type2.wrap_result(" out[1]", "pairResult.second", file, typeAttributes); + type1.wrap_result(" out[0]", "pairResult.first", wrapperFile, typeAttributes); + type2.wrap_result(" out[1]", "pairResult.second", wrapperFile, typeAttributes); } else { // Not a pair - type1.wrap_result(" out[0]", result, file, typeAttributes); + type1.wrap_result(" out[0]", result, wrapperFile, typeAttributes); } } /* ************************************************************************* */ -void ReturnValue::wrapTypeUnwrap(FileWriter& file) const { - type1.wrapTypeUnwrap(file); +void ReturnValue::wrapTypeUnwrap(FileWriter& wrapperFile) const { + type1.wrapTypeUnwrap(wrapperFile); if (isPair) - type2.wrapTypeUnwrap(file); + type2.wrapTypeUnwrap(wrapperFile); } /* ************************************************************************* */ -void ReturnValue::emit_matlab(FileWriter& file) const { +void ReturnValue::emit_matlab(FileWriter& proxyFile) const { string output; if (isPair) - file.oss << "[ varargout{1} varargout{2} ] = "; + proxyFile.oss << "[ varargout{1} varargout{2} ] = "; else if (type1.category != ReturnType::VOID) - file.oss << "varargout{1} = "; + proxyFile.oss << "varargout{1} = "; } /* ************************************************************************* */ From e9a58ff2250acca1544b1f5e4f095fbef2e3796f Mon Sep 17 00:00:00 2001 From: dellaert Date: Wed, 12 Nov 2014 20:52:07 +0100 Subject: [PATCH 4/4] Fixed pointer issue --- wrap/Class.cpp | 20 ++++++++++---------- wrap/ReturnValue.h | 9 +++++---- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/wrap/Class.cpp b/wrap/Class.cpp index 8f36ff77b..4574e050f 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -276,14 +276,14 @@ map expandMethodTemplate(const map& methods, BOOST_FOREACH(const ReturnValue& retVal, method.returnVals) { ReturnValue instRetVal = retVal; if (retVal.type1.name == templateArg) { - instRetVal.type1 = qualifiedType; + instRetVal.type1.rename(qualifiedType); } else if (retVal.type1.name == "This") { - instRetVal.type1 = expandedClass; + instRetVal.type1.rename(expandedClass); } if (retVal.type2.name == templateArg) { - instRetVal.type2 = qualifiedType; + instRetVal.type2.rename(qualifiedType); } else if (retVal.type2.name == "This") { - instRetVal.type2 = expandedClass; + instRetVal.type2.rename(expandedClass); } instMethod.returnVals.push_back(instRetVal); } @@ -309,10 +309,10 @@ Class Class::expandTemplate(const string& templateArg, /* ************************************************************************* */ vector Class::expandTemplate(const string& templateArg, - const vector& instantiations) const { + const vector& instantiations) const { vector result; BOOST_FOREACH(const Qualified& instName, instantiations) { - Qualified expandedClass = (Qualified)(*this); + Qualified expandedClass = (Qualified) (*this); expandedClass.name += instName.name; Class inst = expandTemplate(templateArg, instName, expandedClass); inst.name = expandedClass.name; @@ -359,8 +359,8 @@ void Class::comment_fragment(FileWriter& proxyFile) const { BOOST_FOREACH(ArgumentList argList, m.argLists) { proxyFile.oss << "%"; argList.emit_prototype(proxyFile, m.name); - proxyFile.oss << " : returns " - << m.returnVals[0].return_type(false) << endl; + proxyFile.oss << " : returns " << m.returnVals[0].return_type(false) + << endl; } } @@ -371,8 +371,8 @@ void Class::comment_fragment(FileWriter& proxyFile) const { BOOST_FOREACH(ArgumentList argList, m.argLists) { proxyFile.oss << "%"; argList.emit_prototype(proxyFile, m.name); - proxyFile.oss << " : returns " - << m.returnVals[0].return_type(false) << endl; + proxyFile.oss << " : returns " << m.returnVals[0].return_type(false) + << endl; } } diff --git a/wrap/ReturnValue.h b/wrap/ReturnValue.h index 5b9be18d5..fa88dcb48 100644 --- a/wrap/ReturnValue.h +++ b/wrap/ReturnValue.h @@ -34,8 +34,9 @@ struct ReturnType: Qualified { isPtr(false), category(CLASS) { } - ReturnType(const Qualified& q) : - Qualified(q), isPtr(false), category(CLASS) { + void rename(const Qualified& q) { + name = q.name; + namespaces = q.namespaces; } /// Check if this type is in a set of valid types @@ -78,12 +79,12 @@ struct ReturnValue { std::string matlab_returnType() const; - void wrap_result(const std::string& result, FileWriter& file, + void wrap_result(const std::string& result, FileWriter& wrapperFile, const TypeAttributesTable& typeAttributes) const; void wrapTypeUnwrap(FileWriter& wrapperFile) const; - void emit_matlab(FileWriter& file) const; + void emit_matlab(FileWriter& proxyFile) const; }; } // \namespace wrap