diff --git a/wrap/Argument.cpp b/wrap/Argument.cpp index 07f68a11d..062b7b120 100644 --- a/wrap/Argument.cpp +++ b/wrap/Argument.cpp @@ -25,6 +25,13 @@ using namespace std; using namespace wrap; +/* ************************************************************************* */ +string Argument::matlabClass() const { + if (type=="Vector") return string("double"); + if (type=="Matrix") return string("double"); + return type; +} + /* ************************************************************************* */ void Argument::matlab_unwrap(ofstream& ofs, const string& matlabName) const { ofs << " "; @@ -62,7 +69,7 @@ string Argument::qualifiedType(const string& delim) const { string ArgumentList::types() const { string str; bool first=true; - BOOST_FOREACH(Argument arg, *this) { + BOOST_FOREACH(Argument arg, *this) { if (!first) str += ","; str += arg.type; first=false; } return str; @@ -73,20 +80,14 @@ string ArgumentList::signature() const { string sig; bool cap=false; - BOOST_FOREACH(Argument arg, *this) - { - + BOOST_FOREACH(Argument arg, *this) { BOOST_FOREACH(char ch, arg.type) - if(isupper(ch)) - { + if(isupper(ch)) { sig += ch; - //If there is a capital letter, we don't want to readd it below + //If there is a capital letter, we don't want to read it below cap=true; } - - if(!cap) - sig += arg.type[0]; - + if(!cap) sig += arg.type[0]; //Reset to default cap = false; } diff --git a/wrap/Argument.h b/wrap/Argument.h index cb5b1b8c8..9b9bd6bfb 100644 --- a/wrap/Argument.h +++ b/wrap/Argument.h @@ -28,21 +28,31 @@ struct Argument { std::string type; std::string name; std::vector namespaces; + Argument() : is_const(false), is_ref(false), is_ptr(false) { } - std::string qualifiedType(const std::string& delim = "") const; // adds namespaces to type + /// return MATLAB class for use in isa(x,class) + std::string matlabClass() const; + + /// adds namespaces to type + std::string qualifiedType(const std::string& delim = "") const; /// MATLAB code generation, MATLAB to C++ void matlab_unwrap(std::ofstream& ofs, const std::string& matlabName) const; }; -/// Argument list +/// Argument list is just a container with Arguments struct ArgumentList: public std::vector { - std::vector args; // why does it contain this? + + /// create a comma-separated string listing all argument types (not used) std::string types() const; + + /// create a short "signature" string std::string signature() const; + + /// create a comma-separated string listing all argument names, used in m-files std::string names() const; // MATLAB code generation: diff --git a/wrap/Constructor.cpp b/wrap/Constructor.cpp index a822f722f..3f08a6f2a 100644 --- a/wrap/Constructor.cpp +++ b/wrap/Constructor.cpp @@ -33,10 +33,22 @@ string Constructor::matlab_wrapper_name(const string& className) const { /* ************************************************************************* */ void Constructor::matlab_proxy_fragment(ofstream& ofs, const string& className) const { - ofs << " if nargin == " << args.size() << ", obj.self = " - << matlab_wrapper_name(className) << "("; + size_t nrArgs = args.size(); + // check for number of arguments... + ofs << " if (nargin == " << nrArgs; + if (nrArgs>0) ofs << " & "; + // ...and their types bool first = true; - for(size_t i=0;i