typedef to cope with abundance of strings

release/4.3a0
dellaert 2014-11-13 17:34:33 +01:00
parent b451e97f6f
commit fe481dc775
6 changed files with 73 additions and 68 deletions

View File

@ -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<string>& 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<string>& functionNames) const {
const string matlabUniqueName = qualifiedName();
@ -251,7 +251,7 @@ Class Class::expandTemplate(const TemplateSubstitution& ts) const {
}
/* ************************************************************************* */
vector<Class> Class::expandTemplate(const string& templateArg,
vector<Class> Class::expandTemplate(Str templateArg,
const vector<Qualified>& instantiations) const {
vector<Class> result;
BOOST_FOREACH(const Qualified& instName, instantiations) {
@ -269,26 +269,29 @@ vector<Class> 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<Qualified>& templateArgValues) {
void Class::addMethod(bool verbose, bool is_const, Str methodName,
const ArgumentList& argumentList, const ReturnValue& returnValue,
Str templateArgName, const vector<Qualified>& 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<string>& 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<string>& functionNames) const {
//void Point3_string_deserialize_18(int nargout, mxArray *out[], int nargin, const mxArray *in[])
//{

View File

@ -38,6 +38,7 @@ class Class: public Qualified {
public:
typedef const std::string& Str;
typedef std::map<std::string, StaticMethod> 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<std::string>& functionNames) const; ///< emit proxy class
void matlab_proxy(Str toolboxPath, Str wrapperName,
const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile,
std::vector<std::string>& functionNames) const; ///< emit proxy class
Class expandTemplate(const TemplateSubstitution& ts) const;
std::vector<Class> expandTemplate(const std::string& templateArg,
std::vector<Class> expandTemplate(Str templateArg,
const std::vector<Qualified>& 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<Qualified>& templateArgValues);
void addMethod(bool verbose, bool is_const, Str methodName,
const ArgumentList& argumentList, const ReturnValue& returnValue,
Str templateArgName, const std::vector<Qualified>& 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<std::string>& functionNames) const;
Str wrapperName, std::vector<std::string>& functionNames) const;
/// Creates a static member function that performs deserialization
void deserialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFile,
const std::string& wrapperName,
std::vector<std::string>& functionNames) const;
Str wrapperName, std::vector<std::string>& functionNames) const;
private:
void pointer_constructor_fragments(FileWriter& proxyFile,
FileWriter& wrapperFile, const std::string& wrapperName,
FileWriter& wrapperFile, Str wrapperName,
std::vector<std::string>& functionNames) const;
void comment_fragment(FileWriter& proxyFile) const;

View File

@ -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

View File

@ -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;
};

View File

@ -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<string>& 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

View File

@ -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<std::string>& 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;
};