diff --git a/wrap/Class.cpp b/wrap/Class.cpp index d219452a3..fab977802 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -33,7 +33,7 @@ using namespace std; using namespace wrap; /* ************************************************************************* */ -void Class::matlab_proxy(const string& toolboxPath, const string& wrapperName, +void Class::matlab_proxy(Str toolboxPath, Str wrapperName, const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile, vector& functionNames) const { @@ -144,7 +144,7 @@ void Class::matlab_proxy(const string& toolboxPath, const string& wrapperName, /* ************************************************************************* */ void Class::pointer_constructor_fragments(FileWriter& proxyFile, - FileWriter& wrapperFile, const string& wrapperName, + FileWriter& wrapperFile, Str wrapperName, vector& functionNames) const { const string matlabUniqueName = qualifiedName(); @@ -251,7 +251,7 @@ Class Class::expandTemplate(const TemplateSubstitution& ts) const { } /* ************************************************************************* */ -vector Class::expandTemplate(const string& templateArg, +vector Class::expandTemplate(Str templateArg, const vector& instantiations) const { vector result; BOOST_FOREACH(const Qualified& instName, instantiations) { @@ -269,26 +269,29 @@ vector Class::expandTemplate(const string& templateArg, } /* ************************************************************************* */ -void Class::addMethod(bool verbose, bool is_const, const string& name, - const ArgumentList& args, const ReturnValue& retVal, - const string& templateArgName, const vector& templateArgValues) { +void Class::addMethod(bool verbose, bool is_const, Str methodName, + const ArgumentList& argumentList, const ReturnValue& returnValue, + Str templateArgName, const vector& templateArgValues) { // Check if templated if (!templateArgName.empty() && templateArgValues.size() > 0) { // Create method to expand // For all values of the template argument, create a new method BOOST_FOREACH(const Qualified& instName, templateArgValues) { - string expandedName = name + instName.name; + const TemplateSubstitution ts(templateArgName, instName, this->name); // substitute template in arguments - const TemplateSubstitution ts(templateArgName, instName, name); - ArgumentList expandedArgs = args.expandTemplate(ts); + ArgumentList expandedArgs = argumentList.expandTemplate(ts); // do the same for return types - ReturnValue expandedRetVal = retVal.expandTemplate(ts); - methods[expandedName].addOverload(verbose, is_const, name, expandedArgs, - expandedRetVal, instName); + ReturnValue expandedRetVal = returnValue.expandTemplate(ts); + // Now stick in new overload stack with expandedMethodName key + // but note we use the same, unexpanded methodName in overload + string expandedMethodName = methodName + instName.name; + methods[expandedMethodName].addOverload(verbose, is_const, methodName, + expandedArgs, expandedRetVal, instName); } } else // just add overload - methods[name].addOverload(verbose, is_const, name, args, retVal); + methods[methodName].addOverload(verbose, is_const, methodName, argumentList, + returnValue); } /* ************************************************************************* */ @@ -357,7 +360,7 @@ void Class::appendInheritedMethods(const Class& cls, /* ************************************************************************* */ string Class::getTypedef() const { string result; - BOOST_FOREACH(const string& namesp, namespaces) { + BOOST_FOREACH(Str namesp, namespaces) { result += ("namespace " + namesp + " { "); } result += ("typedef " + typedefName + " " + name + ";"); @@ -408,7 +411,7 @@ void Class::comment_fragment(FileWriter& proxyFile) const { /* ************************************************************************* */ void Class::serialization_fragments(FileWriter& proxyFile, - FileWriter& wrapperFile, const string& wrapperName, + FileWriter& wrapperFile, Str wrapperName, vector& functionNames) const { //void Point3_string_serialize_17(int nargout, mxArray *out[], int nargin, const mxArray *in[]) @@ -500,7 +503,7 @@ void Class::serialization_fragments(FileWriter& proxyFile, /* ************************************************************************* */ void Class::deserialization_fragments(FileWriter& proxyFile, - FileWriter& wrapperFile, const string& wrapperName, + FileWriter& wrapperFile, Str wrapperName, vector& functionNames) const { //void Point3_string_deserialize_18(int nargout, mxArray *out[], int nargin, const mxArray *in[]) //{ diff --git a/wrap/Class.h b/wrap/Class.h index 610c9b7b4..809f40049 100644 --- a/wrap/Class.h +++ b/wrap/Class.h @@ -38,6 +38,7 @@ class Class: public Qualified { public: + typedef const std::string& Str; typedef std::map StaticMethods; // Then the instance variables are set directly by the Module constructor @@ -58,25 +59,30 @@ public: verbose), verbose_(verbose) { } - size_t nrMethods() const { return methods.size(); } - Method& method(const std::string& name) { return methods.at(name); } - bool exists(const std::string& name) const { return methods.find(name) != methods.end(); } + size_t nrMethods() const { + return methods.size(); + } + Method& method(Str name) { + return methods.at(name); + } + bool exists(Str name) const { + return methods.find(name) != methods.end(); + } // And finally MATLAB code is emitted, methods below called by Module::matlab_code - void matlab_proxy(const std::string& toolboxPath, - const std::string& wrapperName, const TypeAttributesTable& typeAttributes, - FileWriter& wrapperFile, std::vector& functionNames) const; ///< emit proxy class + void matlab_proxy(Str toolboxPath, Str wrapperName, + const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile, + std::vector& functionNames) const; ///< emit proxy class Class expandTemplate(const TemplateSubstitution& ts) const; - std::vector expandTemplate(const std::string& templateArg, + std::vector expandTemplate(Str templateArg, const std::vector& instantiations) const; /// Add potentially overloaded, potentially templated method - void addMethod(bool verbose, bool is_const, const std::string& name, - const ArgumentList& args, const ReturnValue& retVal, - const std::string& templateArgName, - const std::vector& templateArgValues); + void addMethod(bool verbose, bool is_const, Str methodName, + const ArgumentList& argumentList, const ReturnValue& returnValue, + Str templateArgName, const std::vector& templateArgValues); /// Post-process classes for serialization markers void erase_serialization(); // non-const ! @@ -96,18 +102,16 @@ public: /// Creates a member function that performs serialization void serialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, - const std::string& wrapperName, - std::vector& functionNames) const; + Str wrapperName, std::vector& functionNames) const; /// Creates a static member function that performs deserialization void deserialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, - const std::string& wrapperName, - std::vector& functionNames) const; + Str wrapperName, std::vector& functionNames) const; private: void pointer_constructor_fragments(FileWriter& proxyFile, - FileWriter& wrapperFile, const std::string& wrapperName, + FileWriter& wrapperFile, Str wrapperName, std::vector& functionNames) const; void comment_fragment(FileWriter& proxyFile) const; diff --git a/wrap/Method.cpp b/wrap/Method.cpp index d342df04b..19e302e2a 100644 --- a/wrap/Method.cpp +++ b/wrap/Method.cpp @@ -29,7 +29,7 @@ using namespace std; using namespace wrap; /* ************************************************************************* */ -void Method::addOverload(bool verbose, bool is_const, const std::string& name, +void Method::addOverload(bool verbose, bool is_const, Str name, const ArgumentList& args, const ReturnValue& retVal, const Qualified& instName) { @@ -43,8 +43,8 @@ void Method::proxy_header(FileWriter& proxyFile) const { } /* ************************************************************************* */ -string Method::wrapper_call(FileWriter& wrapperFile, const string& cppClassName, - const string& matlabUniqueName, const ArgumentList& args, +string Method::wrapper_call(FileWriter& wrapperFile, Str cppClassName, + Str matlabUniqueName, const ArgumentList& args, const ReturnValue& returnVal, const TypeAttributesTable& typeAttributes, const Qualified& instName) const { // check arguments diff --git a/wrap/Method.h b/wrap/Method.h index 8b8c7eaab..d1e382a13 100644 --- a/wrap/Method.h +++ b/wrap/Method.h @@ -25,6 +25,8 @@ namespace wrap { /// Method class struct Method: public StaticMethod { + typedef const std::string& Str; + /// Constructor creates empty object Method(bool verbose = true) : StaticMethod(verbose), is_const_(false) { @@ -35,7 +37,7 @@ struct Method: public StaticMethod { // The first time this function is called, it initializes the class members // 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, + void addOverload(bool verbose, bool is_const, Str name, const ArgumentList& args, const ReturnValue& retVal, const Qualified& instName = Qualified()); @@ -44,10 +46,9 @@ private: // Emit method header void proxy_header(FileWriter& proxyFile) const; - std::string wrapper_call(FileWriter& wrapperFile, - const std::string& cppClassName, const std::string& matlabUniqueName, - const ArgumentList& args, const ReturnValue& returnVal, - const TypeAttributesTable& typeAttributes, + virtual std::string wrapper_call(FileWriter& wrapperFile, Str cppClassName, + Str matlabUniqueName, const ArgumentList& args, + const ReturnValue& returnVal, const TypeAttributesTable& typeAttributes, const Qualified& instName) const; }; diff --git a/wrap/StaticMethod.cpp b/wrap/StaticMethod.cpp index a4d54f4dd..4d3a9acde 100644 --- a/wrap/StaticMethod.cpp +++ b/wrap/StaticMethod.cpp @@ -30,9 +30,8 @@ using namespace std; using namespace wrap; /* ************************************************************************* */ -void StaticMethod::addOverload(bool verbose, const std::string& name, - const ArgumentList& args, const ReturnValue& retVal, - const Qualified& instName) { +void StaticMethod::addOverload(bool verbose, Str name, const ArgumentList& args, + const ReturnValue& retVal, const Qualified& instName) { Function::addOverload(verbose, name, instName); SignatureOverloads::addOverload(args, retVal); @@ -41,15 +40,15 @@ void StaticMethod::addOverload(bool verbose, const std::string& name, /* ************************************************************************* */ void StaticMethod::proxy_header(FileWriter& proxyFile) const { string upperName = name_; - upperName[0] = std::toupper(upperName[0], std::locale()); + upperName[0] = toupper(upperName[0], locale()); proxyFile.oss << " function varargout = " << upperName << "(varargin)\n"; } /* ************************************************************************* */ void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile, - FileWriter& wrapperFile, const string& cppClassName, - const std::string& matlabQualName, const std::string& matlabUniqueName, - const string& wrapperName, const TypeAttributesTable& typeAttributes, + FileWriter& wrapperFile, Str cppClassName, Str matlabQualName, + Str matlabUniqueName, Str wrapperName, + const TypeAttributesTable& typeAttributes, vector& functionNames) const { proxy_header(proxyFile); @@ -109,9 +108,9 @@ void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile, } /* ************************************************************************* */ -string StaticMethod::wrapper_fragment(FileWriter& wrapperFile, - const string& cppClassName, const string& matlabUniqueName, int overload, - int id, const TypeAttributesTable& typeAttributes, +string StaticMethod::wrapper_fragment(FileWriter& wrapperFile, Str cppClassName, + Str matlabUniqueName, int overload, int id, + const TypeAttributesTable& typeAttributes, const Qualified& instName) const { // generate code @@ -152,10 +151,9 @@ string StaticMethod::wrapper_fragment(FileWriter& wrapperFile, } /* ************************************************************************* */ -string StaticMethod::wrapper_call(FileWriter& wrapperFile, - const string& cppClassName, const string& matlabUniqueName, - const ArgumentList& args, const ReturnValue& returnVal, - const TypeAttributesTable& typeAttributes, +string StaticMethod::wrapper_call(FileWriter& wrapperFile, Str cppClassName, + Str matlabUniqueName, const ArgumentList& args, + const ReturnValue& returnVal, const TypeAttributesTable& typeAttributes, const Qualified& instName) const { // check arguments // NOTE: for static functions, there is no object passed diff --git a/wrap/StaticMethod.h b/wrap/StaticMethod.h index 9b9740bdb..cab440ef1 100644 --- a/wrap/StaticMethod.h +++ b/wrap/StaticMethod.h @@ -26,36 +26,35 @@ namespace wrap { /// StaticMethod class struct StaticMethod: public Function, public SignatureOverloads { + typedef const std::string& Str; + /// Constructor creates empty object StaticMethod(bool verbosity = true) : Function(verbosity) { } - void addOverload(bool verbose, const std::string& name, - const ArgumentList& args, const ReturnValue& retVal, - const Qualified& instName); + void addOverload(bool verbose, Str name, const ArgumentList& args, + const ReturnValue& retVal, const Qualified& instName); // 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, + Str cppClassName, Str matlabQualName, Str matlabUniqueName, + Str wrapperName, const TypeAttributesTable& typeAttributes, std::vector& functionNames) const; protected: virtual void proxy_header(FileWriter& proxyFile) const; - std::string wrapper_fragment(FileWriter& wrapperFile, - const std::string& cppClassName, const std::string& matlabUniqueName, - int overload, int id, const TypeAttributesTable& typeAttributes, - const Qualified& instName = Qualified()) const; ///< cpp wrapper + std::string wrapper_fragment(FileWriter& wrapperFile, Str cppClassName, + Str matlabUniqueName, int overload, int id, + const TypeAttributesTable& typeAttributes, const Qualified& instName = + Qualified()) const; ///< cpp wrapper - virtual std::string wrapper_call(FileWriter& wrapperFile, - const std::string& cppClassName, const std::string& matlabUniqueName, - const ArgumentList& args, const ReturnValue& returnVal, - const TypeAttributesTable& typeAttributes, + virtual std::string wrapper_call(FileWriter& wrapperFile, Str cppClassName, + Str matlabUniqueName, const ArgumentList& args, + const ReturnValue& returnVal, const TypeAttributesTable& typeAttributes, const Qualified& instName) const; };