Added matlabName, and made data members private
parent
8a05136ca0
commit
e07da1c82d
|
@ -126,10 +126,8 @@ template<class T>
|
||||||
inline void verifyArguments(const std::vector<std::string>& validArgs,
|
inline void verifyArguments(const std::vector<std::string>& validArgs,
|
||||||
const std::map<std::string, T>& vt) {
|
const std::map<std::string, T>& vt) {
|
||||||
typedef typename std::map<std::string, T>::value_type NamedMethod;
|
typedef typename std::map<std::string, T>::value_type NamedMethod;
|
||||||
BOOST_FOREACH(const NamedMethod& namedMethod, vt) {
|
BOOST_FOREACH(const NamedMethod& namedMethod, vt)
|
||||||
const T& t = namedMethod.second;
|
namedMethod.second.verifyArguments(validArgs);
|
||||||
t.verifyArguments(validArgs, t.name_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
|
@ -381,17 +381,13 @@ void Class::comment_fragment(FileWriter& proxyFile) const {
|
||||||
|
|
||||||
if (!methods.empty())
|
if (!methods.empty())
|
||||||
proxyFile.oss << "%\n%-------Methods-------\n";
|
proxyFile.oss << "%\n%-------Methods-------\n";
|
||||||
BOOST_FOREACH(const Methods::value_type& name_m, methods) {
|
BOOST_FOREACH(const Methods::value_type& name_m, methods)
|
||||||
const Method& m = name_m.second;
|
name_m.second.comment_fragment(proxyFile);
|
||||||
m.comment_fragment(proxyFile, m.name_);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!static_methods.empty())
|
if (!static_methods.empty())
|
||||||
proxyFile.oss << "%\n%-------Static Methods-------\n";
|
proxyFile.oss << "%\n%-------Static Methods-------\n";
|
||||||
BOOST_FOREACH(const StaticMethods::value_type& name_m, static_methods) {
|
BOOST_FOREACH(const StaticMethods::value_type& name_m, static_methods)
|
||||||
const StaticMethod& m = name_m.second;
|
name_m.second.comment_fragment(proxyFile);
|
||||||
m.comment_fragment(proxyFile, m.name_);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasSerialization) {
|
if (hasSerialization) {
|
||||||
proxyFile.oss << "%\n%-------Serialization Interface-------\n";
|
proxyFile.oss << "%\n%-------Serialization Interface-------\n";
|
||||||
|
|
|
@ -28,7 +28,15 @@
|
||||||
namespace wrap {
|
namespace wrap {
|
||||||
|
|
||||||
/// Function class
|
/// 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
|
/// Constructor creates empty object
|
||||||
Function(bool verbose = true) :
|
Function(bool verbose = true) :
|
||||||
|
@ -39,9 +47,16 @@ struct Function {
|
||||||
verbose_(verbose), name_(name) {
|
verbose_(verbose), name_(name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool verbose_;
|
std::string name() const {
|
||||||
std::string name_; ///< name of method
|
return name_;
|
||||||
Qualified templateArgValue_; ///< value of template argument if applicable
|
}
|
||||||
|
|
||||||
|
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
|
// 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
|
||||||
|
@ -205,10 +220,8 @@ template<class F>
|
||||||
inline void verifyReturnTypes(const std::vector<std::string>& validTypes,
|
inline void verifyReturnTypes(const std::vector<std::string>& validTypes,
|
||||||
const std::map<std::string, F>& vt) {
|
const std::map<std::string, F>& vt) {
|
||||||
typedef typename std::map<std::string, F>::value_type NamedMethod;
|
typedef typename std::map<std::string, F>::value_type NamedMethod;
|
||||||
BOOST_FOREACH(const NamedMethod& namedMethod, vt) {
|
BOOST_FOREACH(const NamedMethod& namedMethod, vt)
|
||||||
const F& t = namedMethod.second;
|
namedMethod.second.verifyReturnTypes(validTypes);
|
||||||
t.verifyReturnTypes(validTypes, t.name_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
|
@ -27,6 +27,14 @@ struct GlobalFunction: public Function, public SignatureOverloads {
|
||||||
Function(name,verbose) {
|
Function(name,verbose) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void verifyArguments(const std::vector<std::string>& validArgs) const {
|
||||||
|
SignatureOverloads::verifyArguments(validArgs, name_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void verifyReturnTypes(const std::vector<std::string>& validtypes) const {
|
||||||
|
SignatureOverloads::verifyReturnTypes(validtypes, name_);
|
||||||
|
}
|
||||||
|
|
||||||
// adds an overloaded version of this function,
|
// adds an overloaded version of this function,
|
||||||
void addOverload(bool verbose, const Qualified& overload,
|
void addOverload(bool verbose, const Qualified& overload,
|
||||||
const ArgumentList& args, const ReturnValue& retVal,
|
const ArgumentList& args, const ReturnValue& retVal,
|
||||||
|
|
|
@ -39,7 +39,7 @@ void Method::addOverload(bool verbose, bool is_const, Str name,
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Method::proxy_header(FileWriter& proxyFile) const {
|
void Method::proxy_header(FileWriter& proxyFile) const {
|
||||||
proxyFile.oss << " function varargout = " << name_ << "(this, varargin)\n";
|
proxyFile.oss << " function varargout = " << matlabName() << "(this, varargin)\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -39,7 +39,7 @@ void StaticMethod::addOverload(bool verbose, Str name, const ArgumentList& args,
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void StaticMethod::proxy_header(FileWriter& proxyFile) const {
|
void StaticMethod::proxy_header(FileWriter& proxyFile) const {
|
||||||
string upperName = name_;
|
string upperName = matlabName();
|
||||||
upperName[0] = toupper(upperName[0], locale());
|
upperName[0] = toupper(upperName[0], locale());
|
||||||
proxyFile.oss << " function varargout = " << upperName << "(varargin)\n";
|
proxyFile.oss << " function varargout = " << upperName << "(varargin)\n";
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile,
|
||||||
const TypeAttributesTable& typeAttributes,
|
const TypeAttributesTable& typeAttributes,
|
||||||
vector<string>& functionNames) const {
|
vector<string>& functionNames) const {
|
||||||
|
|
||||||
|
// emit header, e.g., function varargout = templatedMethod(this, varargin)
|
||||||
proxy_header(proxyFile);
|
proxy_header(proxyFile);
|
||||||
|
|
||||||
// Emit comments for documentation
|
// Emit comments for documentation
|
||||||
|
|
|
@ -36,6 +36,19 @@ struct StaticMethod: public Function, public SignatureOverloads {
|
||||||
void addOverload(bool verbose, Str name, const ArgumentList& args,
|
void addOverload(bool verbose, Str name, const ArgumentList& args,
|
||||||
const ReturnValue& retVal, const Qualified& instName);
|
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<std::string>& validArgs) const {
|
||||||
|
SignatureOverloads::verifyArguments(validArgs, name_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void verifyReturnTypes(const std::vector<std::string>& validtypes) const {
|
||||||
|
SignatureOverloads::verifyReturnTypes(validtypes, name_);
|
||||||
|
}
|
||||||
|
|
||||||
// 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,
|
||||||
|
|
|
@ -97,7 +97,7 @@ TEST( wrap, Small ) {
|
||||||
|
|
||||||
// Method 1
|
// Method 1
|
||||||
Method m1 = cls.method("x");
|
Method m1 = cls.method("x");
|
||||||
EXPECT(assert_equal("x", m1.name_));
|
EXPECT(assert_equal("x", m1.name()));
|
||||||
EXPECT(m1.is_const_);
|
EXPECT(m1.is_const_);
|
||||||
LONGS_EQUAL(1, m1.nrOverloads());
|
LONGS_EQUAL(1, m1.nrOverloads());
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ TEST( wrap, Small ) {
|
||||||
|
|
||||||
// Method 2
|
// Method 2
|
||||||
Method m2 = cls.method("returnMatrix");
|
Method m2 = cls.method("returnMatrix");
|
||||||
EXPECT(assert_equal("returnMatrix", m2.name_));
|
EXPECT(assert_equal("returnMatrix", m2.name()));
|
||||||
EXPECT(m2.is_const_);
|
EXPECT(m2.is_const_);
|
||||||
LONGS_EQUAL(1, m2.nrOverloads());
|
LONGS_EQUAL(1, m2.nrOverloads());
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ TEST( wrap, Small ) {
|
||||||
|
|
||||||
// Method 3
|
// Method 3
|
||||||
Method m3 = cls.method("returnPoint2");
|
Method m3 = cls.method("returnPoint2");
|
||||||
EXPECT(assert_equal("returnPoint2", m3.name_));
|
EXPECT(assert_equal("returnPoint2", m3.name()));
|
||||||
EXPECT(m3.is_const_);
|
EXPECT(m3.is_const_);
|
||||||
LONGS_EQUAL(1, m3.nrOverloads());
|
LONGS_EQUAL(1, m3.nrOverloads());
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ TEST( wrap, Small ) {
|
||||||
// Static Method 1
|
// Static Method 1
|
||||||
// static Vector returnVector();
|
// static Vector returnVector();
|
||||||
StaticMethod sm1 = cls.static_methods.at("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());
|
LONGS_EQUAL(1, sm1.nrOverloads());
|
||||||
|
|
||||||
ReturnValue rv4 = sm1.returnValue(0);
|
ReturnValue rv4 = sm1.returnValue(0);
|
||||||
|
@ -195,7 +195,7 @@ TEST( wrap, Geometry ) {
|
||||||
EXPECT(assert_equal("char", m1.returnValue(0).type1.name));
|
EXPECT(assert_equal("char", m1.returnValue(0).type1.name));
|
||||||
EXPECT_LONGS_EQUAL(ReturnType::BASIS, m1.returnValue(0).type1.category);
|
EXPECT_LONGS_EQUAL(ReturnType::BASIS, m1.returnValue(0).type1.category);
|
||||||
EXPECT(!m1.returnValue(0).isPair);
|
EXPECT(!m1.returnValue(0).isPair);
|
||||||
EXPECT(assert_equal("returnChar", m1.name_));
|
EXPECT(assert_equal("returnChar", m1.name()));
|
||||||
LONGS_EQUAL(1, m1.nrOverloads());
|
LONGS_EQUAL(1, m1.nrOverloads());
|
||||||
EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size());
|
EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size());
|
||||||
EXPECT(m1.is_const_);
|
EXPECT(m1.is_const_);
|
||||||
|
@ -209,7 +209,7 @@ TEST( wrap, Geometry ) {
|
||||||
EXPECT(assert_equal("VectorNotEigen", m1.returnValue(0).type1.name));
|
EXPECT(assert_equal("VectorNotEigen", m1.returnValue(0).type1.name));
|
||||||
EXPECT_LONGS_EQUAL(ReturnType::CLASS, m1.returnValue(0).type1.category);
|
EXPECT_LONGS_EQUAL(ReturnType::CLASS, m1.returnValue(0).type1.category);
|
||||||
EXPECT(!m1.returnValue(0).isPair);
|
EXPECT(!m1.returnValue(0).isPair);
|
||||||
EXPECT(assert_equal("vectorConfusion", m1.name_));
|
EXPECT(assert_equal("vectorConfusion", m1.name()));
|
||||||
LONGS_EQUAL(1, m1.nrOverloads());
|
LONGS_EQUAL(1, m1.nrOverloads());
|
||||||
EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size());
|
EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size());
|
||||||
EXPECT(!m1.is_const_);
|
EXPECT(!m1.is_const_);
|
||||||
|
@ -251,7 +251,7 @@ TEST( wrap, Geometry ) {
|
||||||
LONGS_EQUAL(1, m1.nrOverloads());
|
LONGS_EQUAL(1, m1.nrOverloads());
|
||||||
EXPECT(assert_equal("double", m1.returnValue(0).type1.name));
|
EXPECT(assert_equal("double", m1.returnValue(0).type1.name));
|
||||||
EXPECT_LONGS_EQUAL(ReturnType::BASIS, m1.returnValue(0).type1.category);
|
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());
|
LONGS_EQUAL(1, m1.nrOverloads());
|
||||||
EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size());
|
EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size());
|
||||||
EXPECT(m1.is_const_);
|
EXPECT(m1.is_const_);
|
||||||
|
@ -312,7 +312,7 @@ TEST( wrap, Geometry ) {
|
||||||
CHECK(module.global_functions.find("aGlobalFunction") != module.global_functions.end());
|
CHECK(module.global_functions.find("aGlobalFunction") != module.global_functions.end());
|
||||||
{
|
{
|
||||||
GlobalFunction gfunc = module.global_functions.at("aGlobalFunction");
|
GlobalFunction gfunc = module.global_functions.at("aGlobalFunction");
|
||||||
EXPECT(assert_equal("aGlobalFunction", gfunc.name_));
|
EXPECT(assert_equal("aGlobalFunction", gfunc.name()));
|
||||||
LONGS_EQUAL(1, gfunc.nrOverloads());
|
LONGS_EQUAL(1, gfunc.nrOverloads());
|
||||||
EXPECT(assert_equal("Vector", gfunc.returnValue(0).type1.name));
|
EXPECT(assert_equal("Vector", gfunc.returnValue(0).type1.name));
|
||||||
EXPECT_LONGS_EQUAL(1, gfunc.nrOverloads());
|
EXPECT_LONGS_EQUAL(1, gfunc.nrOverloads());
|
||||||
|
@ -386,7 +386,7 @@ TEST( wrap, parse_namespaces ) {
|
||||||
CHECK(module.global_functions.find("aGlobalFunction") != module.global_functions.end());
|
CHECK(module.global_functions.find("aGlobalFunction") != module.global_functions.end());
|
||||||
{
|
{
|
||||||
GlobalFunction gfunc = module.global_functions.at("aGlobalFunction");
|
GlobalFunction gfunc = module.global_functions.at("aGlobalFunction");
|
||||||
EXPECT(assert_equal("aGlobalFunction", gfunc.name_));
|
EXPECT(assert_equal("aGlobalFunction", gfunc.name()));
|
||||||
LONGS_EQUAL(2, gfunc.nrOverloads());
|
LONGS_EQUAL(2, gfunc.nrOverloads());
|
||||||
EXPECT(assert_equal("Vector", gfunc.returnValue(0).type1.name));
|
EXPECT(assert_equal("Vector", gfunc.returnValue(0).type1.name));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue