From 67bc951ac2851437f5777b7d0f3f09eb39b55ad9 Mon Sep 17 00:00:00 2001 From: dellaert Date: Thu, 13 Nov 2014 23:21:05 +0100 Subject: [PATCH] Fixed proxy files and calls for static methods --- wrap/Method.h | 14 ++++++++++++-- wrap/StaticMethod.cpp | 10 ++++++---- wrap/StaticMethod.h | 4 ++++ wrap/tests/expected2/+gtsam/Point3.m | 18 ++---------------- wrap/tests/expected2/MyTemplatePoint2.m | 18 +++++++++++------- wrap/tests/expected2/MyTemplatePoint3.m | 18 +++++++++++------- wrap/tests/expected_namespaces/+ns2/ClassA.m | 2 +- wrap/tests/testWrap.cpp | 12 ++++++------ 8 files changed, 53 insertions(+), 43 deletions(-) diff --git a/wrap/Method.h b/wrap/Method.h index be3e1c97f..d097cc322 100644 --- a/wrap/Method.h +++ b/wrap/Method.h @@ -23,7 +23,11 @@ namespace wrap { /// Method class -struct Method: public StaticMethod { +class Method: public StaticMethod { + + bool is_const_; + +public: typedef const std::string& Str; @@ -32,7 +36,13 @@ struct Method: public StaticMethod { StaticMethod(verbose), is_const_(false) { } - bool is_const_; + virtual bool isStatic() const { + return false; + } + + virtual bool isConst() const { + return is_const_; + } // The first time this function is called, it initializes the class members // with those in rhs, but in subsequent calls it adds additional argument diff --git a/wrap/StaticMethod.cpp b/wrap/StaticMethod.cpp index d6b3f94f6..d3bd75628 100644 --- a/wrap/StaticMethod.cpp +++ b/wrap/StaticMethod.cpp @@ -55,9 +55,9 @@ void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile, proxy_header(proxyFile); // Emit comments for documentation - string up_name = boost::to_upper_copy(name_); + string up_name = boost::to_upper_copy(matlabName()); proxyFile.oss << " % " << up_name << " usage: "; - usage_fragment(proxyFile, name_); + usage_fragment(proxyFile, matlabName()); // Emit URL to Doxygen page proxyFile.oss << " % " @@ -67,9 +67,11 @@ void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile, // Handle special case of single overload with all numeric arguments if (nrOverloads() == 1 && argumentList(0).allScalar()) { // Output proxy matlab code + // TODO: document why is it OK to not check arguments in this case proxyFile.oss << " "; const int id = (int) functionNames.size(); - argumentList(0).emit_call(proxyFile, returnValue(0), wrapperName, id); + argumentList(0).emit_call(proxyFile, returnValue(0), wrapperName, id, + isStatic()); // Output C++ wrapper code const string wrapFunctionName = wrapper_fragment(wrapperFile, cppClassName, @@ -85,7 +87,7 @@ void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile, proxyFile.oss << " " << (i == 0 ? "" : "else"); const int id = (int) functionNames.size(); argumentList(i).emit_conditional_call(proxyFile, returnValue(i), - wrapperName, id); + wrapperName, id, isStatic()); // Output C++ wrapper code const string wrapFunctionName = wrapper_fragment(wrapperFile, diff --git a/wrap/StaticMethod.h b/wrap/StaticMethod.h index 672dd0e70..af5cbce59 100644 --- a/wrap/StaticMethod.h +++ b/wrap/StaticMethod.h @@ -33,6 +33,10 @@ struct StaticMethod: public Function, public SignatureOverloads { Function(verbosity) { } + virtual bool isStatic() const { + return true; + } + void addOverload(bool verbose, Str name, const ArgumentList& args, const ReturnValue& retVal, const Qualified& instName); diff --git a/wrap/tests/expected2/+gtsam/Point3.m b/wrap/tests/expected2/+gtsam/Point3.m index d445c78ef..3ef336ff1 100644 --- a/wrap/tests/expected2/+gtsam/Point3.m +++ b/wrap/tests/expected2/+gtsam/Point3.m @@ -48,27 +48,13 @@ classdef Point3 < handle function varargout = StaticFunctionRet(varargin) % STATICFUNCTIONRET usage: StaticFunctionRet(double z) : returns gtsam::Point3 % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html - % - % Usage - % STATICFUNCTIONRET(double z) - if length(varargin) == 1 && isa(varargin{1},'double') - varargout{1} = geometry_wrapper(15, varargin{:}); - else - error('Arguments do not match any overload of function gtsam.Point3.StaticFunctionRet'); - end + varargout{1} = geometry_wrapper(15, varargin{:}); end function varargout = StaticFunction(varargin) % STATICFUNCTION usage: staticFunction() : returns double % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html - % - % Usage - % STATICFUNCTION() - if length(varargin) == 0 - varargout{1} = geometry_wrapper(16, varargin{:}); - else - error('Arguments do not match any overload of function gtsam.Point3.StaticFunction'); - end + varargout{1} = geometry_wrapper(16, varargin{:}); end end diff --git a/wrap/tests/expected2/MyTemplatePoint2.m b/wrap/tests/expected2/MyTemplatePoint2.m index d06595f9b..57a7bfd66 100644 --- a/wrap/tests/expected2/MyTemplatePoint2.m +++ b/wrap/tests/expected2/MyTemplatePoint2.m @@ -107,16 +107,20 @@ classdef MyTemplatePoint2 < MyBase end end - function varargout = templatedMethod(this, varargin) - % TEMPLATEDMETHOD usage: templatedMethod(Point2 t), templatedMethod(Point3 t) : returns void + function varargout = templatedMethodPoint2(this, varargin) + % TEMPLATEDMETHODPOINT2 usage: templatedMethodPoint2(Point2 t) : returns void % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html - % - % Method Overloads - % templatedMethod(Point2 t) - % templatedMethod(Point3 t) if length(varargin) == 1 && isa(varargin{1},'gtsam.Point2') geometry_wrapper(54, this, varargin{:}); - elseif length(varargin) == 1 && isa(varargin{1},'gtsam.Point3') + else + error('Arguments do not match any overload of function MyTemplatePoint2.templatedMethod'); + end + end + + function varargout = templatedMethodPoint3(this, varargin) + % TEMPLATEDMETHODPOINT3 usage: templatedMethodPoint3(Point3 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},'gtsam.Point3') geometry_wrapper(55, this, varargin{:}); else error('Arguments do not match any overload of function MyTemplatePoint2.templatedMethod'); diff --git a/wrap/tests/expected2/MyTemplatePoint3.m b/wrap/tests/expected2/MyTemplatePoint3.m index 500316769..a585bee6e 100644 --- a/wrap/tests/expected2/MyTemplatePoint3.m +++ b/wrap/tests/expected2/MyTemplatePoint3.m @@ -107,16 +107,20 @@ classdef MyTemplatePoint3 < MyBase end end - function varargout = templatedMethod(this, varargin) - % TEMPLATEDMETHOD usage: templatedMethod(Point2 t), templatedMethod(Point3 t) : returns void + function varargout = templatedMethodPoint2(this, varargin) + % TEMPLATEDMETHODPOINT2 usage: templatedMethodPoint2(Point2 t) : returns void % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html - % - % Method Overloads - % templatedMethod(Point2 t) - % templatedMethod(Point3 t) if length(varargin) == 1 && isa(varargin{1},'gtsam.Point2') geometry_wrapper(67, this, varargin{:}); - elseif length(varargin) == 1 && isa(varargin{1},'gtsam.Point3') + else + error('Arguments do not match any overload of function MyTemplatePoint3.templatedMethod'); + end + end + + function varargout = templatedMethodPoint3(this, varargin) + % TEMPLATEDMETHODPOINT3 usage: templatedMethodPoint3(Point3 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},'gtsam.Point3') geometry_wrapper(68, this, varargin{:}); else error('Arguments do not match any overload of function MyTemplatePoint3.templatedMethod'); diff --git a/wrap/tests/expected_namespaces/+ns2/ClassA.m b/wrap/tests/expected_namespaces/+ns2/ClassA.m index 9f0055af9..14095899c 100644 --- a/wrap/tests/expected_namespaces/+ns2/ClassA.m +++ b/wrap/tests/expected_namespaces/+ns2/ClassA.m @@ -65,7 +65,7 @@ classdef ClassA < handle function varargout = Afunction(varargin) % AFUNCTION usage: afunction() : returns double % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html - varargout{1} = testNamespaces_wrapper(12, this, varargin{:}); + varargout{1} = testNamespaces_wrapper(12, varargin{:}); end end diff --git a/wrap/tests/testWrap.cpp b/wrap/tests/testWrap.cpp index 8268c9a8a..8fe862182 100644 --- a/wrap/tests/testWrap.cpp +++ b/wrap/tests/testWrap.cpp @@ -98,7 +98,7 @@ TEST( wrap, Small ) { // Method 1 Method m1 = cls.method("x"); EXPECT(assert_equal("x", m1.name())); - EXPECT(m1.is_const_); + EXPECT(m1.isConst()); LONGS_EQUAL(1, m1.nrOverloads()); ReturnValue rv1 = m1.returnValue(0); @@ -110,7 +110,7 @@ TEST( wrap, Small ) { // Method 2 Method m2 = cls.method("returnMatrix"); EXPECT(assert_equal("returnMatrix", m2.name())); - EXPECT(m2.is_const_); + EXPECT(m2.isConst()); LONGS_EQUAL(1, m2.nrOverloads()); ReturnValue rv2 = m2.returnValue(0); @@ -122,7 +122,7 @@ TEST( wrap, Small ) { // Method 3 Method m3 = cls.method("returnPoint2"); EXPECT(assert_equal("returnPoint2", m3.name())); - EXPECT(m3.is_const_); + EXPECT(m3.isConst()); LONGS_EQUAL(1, m3.nrOverloads()); ReturnValue rv3 = m3.returnValue(0); @@ -198,7 +198,7 @@ TEST( wrap, Geometry ) { EXPECT(assert_equal("returnChar", m1.name())); LONGS_EQUAL(1, m1.nrOverloads()); EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size()); - EXPECT(m1.is_const_); + EXPECT(m1.isConst()); } { @@ -212,7 +212,7 @@ TEST( wrap, Geometry ) { EXPECT(assert_equal("vectorConfusion", m1.name())); LONGS_EQUAL(1, m1.nrOverloads()); EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size()); - EXPECT(!m1.is_const_); + EXPECT(!m1.isConst()); } EXPECT_LONGS_EQUAL(0, cls.static_methods.size()); @@ -254,7 +254,7 @@ TEST( wrap, Geometry ) { EXPECT(assert_equal("norm", m1.name())); LONGS_EQUAL(1, m1.nrOverloads()); EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size()); - EXPECT(m1.is_const_); + EXPECT(m1.isConst()); #ifndef WRAP_DISABLE_SERIALIZE // check serialization flag