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