diff --git a/wrap/Method.cpp b/wrap/Method.cpp index 8f18c5f94..3aaee7be9 100644 --- a/wrap/Method.cpp +++ b/wrap/Method.cpp @@ -31,6 +31,12 @@ using namespace wrap; /* ************************************************************************* */ void Method::addOverload(bool verbose, bool is_const, const std::string& name, const ArgumentList& args, const ReturnValue& retVal) { + if (name.empty()) + this->name = name; + else if (this->name != name) + throw std::runtime_error( + "Method::addOverload: tried to add overload with name " + name + + " instead of expected " + this->name); this->verbose_ = verbose; this->is_const_ = is_const; this->name = name; diff --git a/wrap/ReturnValue.h b/wrap/ReturnValue.h index fa88dcb48..83a860638 100644 --- a/wrap/ReturnValue.h +++ b/wrap/ReturnValue.h @@ -34,6 +34,11 @@ struct ReturnType: Qualified { isPtr(false), category(CLASS) { } + ReturnType(const std::string& name) : + isPtr(false), category(CLASS) { + Qualified::name = name; + } + void rename(const Qualified& q) { name = q.name; namespaces = q.namespaces; @@ -75,6 +80,11 @@ struct ReturnValue { isPair(false) { } + /// Constructor + ReturnValue(const ReturnType& type) : + isPair(false), type1(type) { + } + std::string return_type(bool add_ptr) const; std::string matlab_returnType() const; diff --git a/wrap/tests/testMethod.cpp b/wrap/tests/testMethod.cpp index 23923e1cc..d27b89644 100644 --- a/wrap/tests/testMethod.cpp +++ b/wrap/tests/testMethod.cpp @@ -17,19 +17,34 @@ **/ #include - #include - #include using namespace std; using namespace wrap; /* ************************************************************************* */ +// Constructor TEST( Method, Constructor ) { Method method; } /* ************************************************************************* */ -int main() { TestResult tr; return TestRegistry::runAllTests(tr); } +// addOverload +TEST( Method, addOverload ) { + Method method; + method.name = "myName"; + bool verbose = true, is_const = true; + ArgumentList args; + const ReturnValue retVal(ReturnType("return_type")); + method.addOverload(verbose, is_const, "myName", args, retVal); + EXPECT_LONGS_EQUAL(1,method.argLists.size()); + EXPECT_LONGS_EQUAL(1,method.returnVals.size()); +} + +/* ************************************************************************* */ +int main() { + TestResult tr; + return TestRegistry::runAllTests(tr); +} /* ************************************************************************* */