diff --git a/wrap/Argument.h b/wrap/Argument.h index 729792eb8..02f104418 100644 --- a/wrap/Argument.h +++ b/wrap/Argument.h @@ -126,10 +126,8 @@ template inline void verifyArguments(const std::vector& validArgs, const std::map& vt) { typedef typename std::map::value_type NamedMethod; - BOOST_FOREACH(const NamedMethod& namedMethod, vt) { - const T& t = namedMethod.second; - t.verifyArguments(validArgs, t.name_); - } + BOOST_FOREACH(const NamedMethod& namedMethod, vt) + namedMethod.second.verifyArguments(validArgs); } } // \namespace wrap diff --git a/wrap/Class.cpp b/wrap/Class.cpp index f7f9ba7ee..3a3432eb3 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -381,17 +381,13 @@ void Class::comment_fragment(FileWriter& proxyFile) const { if (!methods.empty()) proxyFile.oss << "%\n%-------Methods-------\n"; - BOOST_FOREACH(const Methods::value_type& name_m, methods) { - const Method& m = name_m.second; - m.comment_fragment(proxyFile, m.name_); - } + BOOST_FOREACH(const Methods::value_type& name_m, methods) + name_m.second.comment_fragment(proxyFile); if (!static_methods.empty()) proxyFile.oss << "%\n%-------Static Methods-------\n"; - BOOST_FOREACH(const StaticMethods::value_type& name_m, static_methods) { - const StaticMethod& m = name_m.second; - m.comment_fragment(proxyFile, m.name_); - } + BOOST_FOREACH(const StaticMethods::value_type& name_m, static_methods) + name_m.second.comment_fragment(proxyFile); if (hasSerialization) { proxyFile.oss << "%\n%-------Serialization Interface-------\n"; diff --git a/wrap/Function.h b/wrap/Function.h index 3af7b38fc..1d40fcbea 100644 --- a/wrap/Function.h +++ b/wrap/Function.h @@ -28,7 +28,15 @@ namespace wrap { /// Function class -struct Function { +class Function { + +protected: + + bool verbose_; + std::string name_; ///< name of method + Qualified templateArgValue_; ///< value of template argument if applicable + +public: /// Constructor creates empty object Function(bool verbose = true) : @@ -39,9 +47,16 @@ struct Function { verbose_(verbose), name_(name) { } - bool verbose_; - std::string name_; ///< name of method - Qualified templateArgValue_; ///< value of template argument if applicable + std::string name() const { + return name_; + } + + std::string matlabName() const { + if (templateArgValue_.empty()) + return name_; + else + return name_ + templateArgValue_.name; + } // The first time this function is called, it initializes the class members // with those in rhs, but in subsequent calls it adds additional argument @@ -205,10 +220,8 @@ template inline void verifyReturnTypes(const std::vector& validTypes, const std::map& vt) { typedef typename std::map::value_type NamedMethod; - BOOST_FOREACH(const NamedMethod& namedMethod, vt) { - const F& t = namedMethod.second; - t.verifyReturnTypes(validTypes, t.name_); - } + BOOST_FOREACH(const NamedMethod& namedMethod, vt) + namedMethod.second.verifyReturnTypes(validTypes); } } // \namespace wrap diff --git a/wrap/GlobalFunction.h b/wrap/GlobalFunction.h index 6f8686925..18bb91995 100644 --- a/wrap/GlobalFunction.h +++ b/wrap/GlobalFunction.h @@ -27,6 +27,14 @@ struct GlobalFunction: public Function, public SignatureOverloads { Function(name,verbose) { } + void verifyArguments(const std::vector& validArgs) const { + SignatureOverloads::verifyArguments(validArgs, name_); + } + + void verifyReturnTypes(const std::vector& validtypes) const { + SignatureOverloads::verifyReturnTypes(validtypes, name_); + } + // adds an overloaded version of this function, void addOverload(bool verbose, const Qualified& overload, const ArgumentList& args, const ReturnValue& retVal, diff --git a/wrap/Method.cpp b/wrap/Method.cpp index 19e302e2a..a7072c9e7 100644 --- a/wrap/Method.cpp +++ b/wrap/Method.cpp @@ -39,7 +39,7 @@ void Method::addOverload(bool verbose, bool is_const, Str name, /* ************************************************************************* */ void Method::proxy_header(FileWriter& proxyFile) const { - proxyFile.oss << " function varargout = " << name_ << "(this, varargin)\n"; + proxyFile.oss << " function varargout = " << matlabName() << "(this, varargin)\n"; } /* ************************************************************************* */ diff --git a/wrap/StaticMethod.cpp b/wrap/StaticMethod.cpp index 67c52906c..d6b3f94f6 100644 --- a/wrap/StaticMethod.cpp +++ b/wrap/StaticMethod.cpp @@ -39,7 +39,7 @@ void StaticMethod::addOverload(bool verbose, Str name, const ArgumentList& args, /* ************************************************************************* */ void StaticMethod::proxy_header(FileWriter& proxyFile) const { - string upperName = name_; + string upperName = matlabName(); upperName[0] = toupper(upperName[0], locale()); proxyFile.oss << " function varargout = " << upperName << "(varargin)\n"; } @@ -51,6 +51,7 @@ void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile, const TypeAttributesTable& typeAttributes, vector& functionNames) const { + // emit header, e.g., function varargout = templatedMethod(this, varargin) proxy_header(proxyFile); // Emit comments for documentation diff --git a/wrap/StaticMethod.h b/wrap/StaticMethod.h index 524dbb3ae..672dd0e70 100644 --- a/wrap/StaticMethod.h +++ b/wrap/StaticMethod.h @@ -36,6 +36,19 @@ struct StaticMethod: public Function, public SignatureOverloads { void addOverload(bool verbose, Str name, const ArgumentList& args, const ReturnValue& retVal, const Qualified& instName); + // emit a list of comments, one for each overload + void comment_fragment(FileWriter& proxyFile) const { + SignatureOverloads::comment_fragment(proxyFile, name_); + } + + void verifyArguments(const std::vector& validArgs) const { + SignatureOverloads::verifyArguments(validArgs, name_); + } + + void verifyReturnTypes(const std::vector& validtypes) const { + SignatureOverloads::verifyReturnTypes(validtypes, name_); + } + // MATLAB code generation // classPath is class directory, e.g., ../matlab/@Point2 void proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, diff --git a/wrap/tests/testWrap.cpp b/wrap/tests/testWrap.cpp index f26244772..8268c9a8a 100644 --- a/wrap/tests/testWrap.cpp +++ b/wrap/tests/testWrap.cpp @@ -97,7 +97,7 @@ TEST( wrap, Small ) { // Method 1 Method m1 = cls.method("x"); - EXPECT(assert_equal("x", m1.name_)); + EXPECT(assert_equal("x", m1.name())); EXPECT(m1.is_const_); LONGS_EQUAL(1, m1.nrOverloads()); @@ -109,7 +109,7 @@ TEST( wrap, Small ) { // Method 2 Method m2 = cls.method("returnMatrix"); - EXPECT(assert_equal("returnMatrix", m2.name_)); + EXPECT(assert_equal("returnMatrix", m2.name())); EXPECT(m2.is_const_); LONGS_EQUAL(1, m2.nrOverloads()); @@ -121,7 +121,7 @@ TEST( wrap, Small ) { // Method 3 Method m3 = cls.method("returnPoint2"); - EXPECT(assert_equal("returnPoint2", m3.name_)); + EXPECT(assert_equal("returnPoint2", m3.name())); EXPECT(m3.is_const_); LONGS_EQUAL(1, m3.nrOverloads()); @@ -134,7 +134,7 @@ TEST( wrap, Small ) { // Static Method 1 // static Vector returnVector(); StaticMethod sm1 = cls.static_methods.at("returnVector"); - EXPECT(assert_equal("returnVector", sm1.name_)); + EXPECT(assert_equal("returnVector", sm1.name())); LONGS_EQUAL(1, sm1.nrOverloads()); ReturnValue rv4 = sm1.returnValue(0); @@ -195,7 +195,7 @@ TEST( wrap, Geometry ) { EXPECT(assert_equal("char", m1.returnValue(0).type1.name)); EXPECT_LONGS_EQUAL(ReturnType::BASIS, m1.returnValue(0).type1.category); EXPECT(!m1.returnValue(0).isPair); - EXPECT(assert_equal("returnChar", m1.name_)); + EXPECT(assert_equal("returnChar", m1.name())); LONGS_EQUAL(1, m1.nrOverloads()); EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size()); EXPECT(m1.is_const_); @@ -209,7 +209,7 @@ TEST( wrap, Geometry ) { EXPECT(assert_equal("VectorNotEigen", m1.returnValue(0).type1.name)); EXPECT_LONGS_EQUAL(ReturnType::CLASS, m1.returnValue(0).type1.category); EXPECT(!m1.returnValue(0).isPair); - EXPECT(assert_equal("vectorConfusion", m1.name_)); + EXPECT(assert_equal("vectorConfusion", m1.name())); LONGS_EQUAL(1, m1.nrOverloads()); EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size()); EXPECT(!m1.is_const_); @@ -251,7 +251,7 @@ TEST( wrap, Geometry ) { LONGS_EQUAL(1, m1.nrOverloads()); EXPECT(assert_equal("double", m1.returnValue(0).type1.name)); EXPECT_LONGS_EQUAL(ReturnType::BASIS, m1.returnValue(0).type1.category); - EXPECT(assert_equal("norm", m1.name_)); + EXPECT(assert_equal("norm", m1.name())); LONGS_EQUAL(1, m1.nrOverloads()); EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size()); EXPECT(m1.is_const_); @@ -312,7 +312,7 @@ TEST( wrap, Geometry ) { CHECK(module.global_functions.find("aGlobalFunction") != module.global_functions.end()); { GlobalFunction gfunc = module.global_functions.at("aGlobalFunction"); - EXPECT(assert_equal("aGlobalFunction", gfunc.name_)); + EXPECT(assert_equal("aGlobalFunction", gfunc.name())); LONGS_EQUAL(1, gfunc.nrOverloads()); EXPECT(assert_equal("Vector", gfunc.returnValue(0).type1.name)); EXPECT_LONGS_EQUAL(1, gfunc.nrOverloads()); @@ -386,7 +386,7 @@ TEST( wrap, parse_namespaces ) { CHECK(module.global_functions.find("aGlobalFunction") != module.global_functions.end()); { GlobalFunction gfunc = module.global_functions.at("aGlobalFunction"); - EXPECT(assert_equal("aGlobalFunction", gfunc.name_)); + EXPECT(assert_equal("aGlobalFunction", gfunc.name())); LONGS_EQUAL(2, gfunc.nrOverloads()); EXPECT(assert_equal("Vector", gfunc.returnValue(0).type1.name));