struct Constructor: public ArgumentOverloads
parent
efd544527f
commit
09e3c7df9f
|
@ -73,13 +73,15 @@ void Class::matlab_proxy(Str toolboxPath, Str wrapperName,
|
|||
pointer_constructor_fragments(proxyFile, wrapperFile, wrapperName,
|
||||
functionNames);
|
||||
wrapperFile.oss << "\n";
|
||||
|
||||
// Regular constructors
|
||||
BOOST_FOREACH(ArgumentList a, constructor.args_list) {
|
||||
for (size_t i = 0; i < constructor.nrOverloads(); i++) {
|
||||
ArgumentList args = constructor.argumentList(i);
|
||||
const int id = (int) functionNames.size();
|
||||
constructor.proxy_fragment(proxyFile, wrapperName, !qualifiedParent.empty(),
|
||||
id, a);
|
||||
id, args);
|
||||
const string wrapFunctionName = constructor.wrapper_fragment(wrapperFile,
|
||||
cppName, matlabUniqueName, cppBaseName, id, a);
|
||||
cppName, matlabUniqueName, cppBaseName, id, args);
|
||||
wrapperFile.oss << "\n";
|
||||
functionNames.push_back(wrapFunctionName);
|
||||
}
|
||||
|
@ -244,8 +246,7 @@ Class Class::expandTemplate(const TemplateSubstitution& ts) const {
|
|||
Class inst = *this;
|
||||
inst.methods = expandMethodTemplate(methods, ts);
|
||||
inst.static_methods = expandMethodTemplate(static_methods, ts);
|
||||
inst.constructor.args_list = inst.constructor.expandArgumentListsTemplate(ts);
|
||||
inst.constructor.name = inst.name;
|
||||
inst.constructor = constructor.expandTemplate(ts);
|
||||
inst.deconstructor.name = inst.name;
|
||||
cout << inst << endl;
|
||||
return inst;
|
||||
|
@ -374,19 +375,12 @@ string Class::getTypedef() const {
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
||||
void Class::comment_fragment(FileWriter& proxyFile) const {
|
||||
proxyFile.oss << "%class " << name << ", see Doxygen page for details\n";
|
||||
proxyFile.oss
|
||||
<< "%at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html\n";
|
||||
|
||||
if (!constructor.args_list.empty())
|
||||
proxyFile.oss << "%\n%-------Constructors-------\n";
|
||||
BOOST_FOREACH(ArgumentList argList, constructor.args_list) {
|
||||
proxyFile.oss << "%";
|
||||
argList.emit_prototype(proxyFile, name);
|
||||
proxyFile.oss << "\n";
|
||||
}
|
||||
constructor.comment_fragment(proxyFile);
|
||||
|
||||
if (!methods.empty())
|
||||
proxyFile.oss << "%\n%-------Methods-------\n";
|
||||
|
|
|
@ -112,7 +112,10 @@ public:
|
|||
Str wrapperName, std::vector<std::string>& functionNames) const;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const Class& cls) {
|
||||
os << "class " << cls.name << "{\n";
|
||||
os << "class " << cls.name << "{\n";
|
||||
os << cls.constructor << ";\n";
|
||||
BOOST_FOREACH(const StaticMethod& m, cls.static_methods | boost::adaptors::map_values)
|
||||
os << m << ";\n";
|
||||
BOOST_FOREACH(const Method& m, cls.methods | boost::adaptors::map_values)
|
||||
os << m << ";\n";
|
||||
os << "};" << std::endl;
|
||||
|
|
|
@ -36,17 +36,6 @@ string Constructor::matlab_wrapper_name(const string& className) const {
|
|||
return str;
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
vector<ArgumentList> Constructor::expandArgumentListsTemplate(
|
||||
const TemplateSubstitution& ts) const {
|
||||
vector<ArgumentList> result;
|
||||
BOOST_FOREACH(const ArgumentList& argList, args_list) {
|
||||
ArgumentList instArgList = argList.expandTemplate(ts);
|
||||
result.push_back(instArgList);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Constructor::proxy_fragment(FileWriter& file, const std::string& wrapperName,
|
||||
bool hasParent, const int id, const ArgumentList args) const {
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Argument.h"
|
||||
#include "Function.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -26,7 +26,7 @@
|
|||
namespace wrap {
|
||||
|
||||
// Constructor class
|
||||
struct Constructor {
|
||||
struct Constructor: public ArgumentOverloads {
|
||||
|
||||
/// Constructor creates an empty class
|
||||
Constructor(bool verbose = false) :
|
||||
|
@ -34,13 +34,15 @@ struct Constructor {
|
|||
}
|
||||
|
||||
// Then the instance variables are set directly by the Module constructor
|
||||
std::vector<ArgumentList> args_list;
|
||||
std::string name;
|
||||
bool verbose_;
|
||||
|
||||
// TODO eliminate copy/paste with function
|
||||
std::vector<ArgumentList> expandArgumentListsTemplate(
|
||||
const TemplateSubstitution& ts) const;
|
||||
Constructor expandTemplate(const TemplateSubstitution& ts) const {
|
||||
Constructor inst = *this;
|
||||
inst.argLists_ = expandArgumentListsTemplate(ts);
|
||||
inst.name = inst.name;
|
||||
return inst;
|
||||
}
|
||||
|
||||
// MATLAB code generation
|
||||
// toolboxPath is main toolbox directory, e.g., ../matlab
|
||||
|
@ -49,6 +51,16 @@ struct Constructor {
|
|||
/// wrapper name
|
||||
std::string matlab_wrapper_name(const std::string& className) const;
|
||||
|
||||
void comment_fragment(FileWriter& proxyFile) const {
|
||||
if (nrOverloads() > 0)
|
||||
proxyFile.oss << "%\n%-------Constructors-------\n";
|
||||
for (size_t i = 0; i < nrOverloads(); i++) {
|
||||
proxyFile.oss << "%";
|
||||
argumentList(i).emit_prototype(proxyFile, name);
|
||||
proxyFile.oss << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create fragment to select constructor in proxy class, e.g.,
|
||||
* if nargin == 2, obj.self = new_Pose3_RP(varargin{1},varargin{2}); end
|
||||
|
@ -66,6 +78,12 @@ struct Constructor {
|
|||
void generate_construct(FileWriter& file, const std::string& cppClassName,
|
||||
std::vector<ArgumentList>& args_list) const;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const Constructor& m) {
|
||||
for (size_t i = 0; i < m.nrOverloads(); i++)
|
||||
os << m.name << m.argLists_[i];
|
||||
return os;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // \namespace wrap
|
||||
|
|
|
@ -217,7 +217,7 @@ void Module::parseMarkup(const std::string& data) {
|
|||
Constructor constructor0(verbose), constructor(verbose);
|
||||
Rule constructor_p =
|
||||
(className_p >> '(' >> argumentList_p >> ')' >> ';' >> !comments_p)
|
||||
[push_back_a(constructor.args_list, args)]
|
||||
[bl::bind(&Constructor::addOverload, bl::var(constructor), bl::var(args))]
|
||||
[clear_a(args)];
|
||||
|
||||
vector<string> namespaces_return; /// namespace for current return type
|
||||
|
|
|
@ -43,6 +43,12 @@ struct StaticMethod: public Function, public SignatureOverloads {
|
|||
Str wrapperName, const TypeAttributesTable& typeAttributes,
|
||||
std::vector<std::string>& functionNames) const;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const StaticMethod& m) {
|
||||
for (size_t i = 0; i < m.nrOverloads(); i++)
|
||||
os << "static " << m.returnVals_[i] << " " << m.name_ << m.argLists_[i];
|
||||
return os;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual void proxy_header(FileWriter& proxyFile) const;
|
||||
|
|
|
@ -184,7 +184,7 @@ TEST( wrap, Geometry ) {
|
|||
|
||||
Class cls = module.classes.at(0);
|
||||
EXPECT(assert_equal("Point2", cls.name));
|
||||
EXPECT_LONGS_EQUAL(2, cls.constructor.args_list.size());
|
||||
EXPECT_LONGS_EQUAL(2, cls.constructor.nrOverloads());
|
||||
EXPECT_LONGS_EQUAL(7, cls.nrMethods());
|
||||
|
||||
{
|
||||
|
@ -229,13 +229,13 @@ TEST( wrap, Geometry ) {
|
|||
{
|
||||
Class cls = module.classes.at(1);
|
||||
EXPECT(assert_equal("Point3", cls.name));
|
||||
EXPECT_LONGS_EQUAL(1, cls.constructor.args_list.size());
|
||||
EXPECT_LONGS_EQUAL(1, cls.constructor.nrOverloads());
|
||||
EXPECT_LONGS_EQUAL(1, cls.nrMethods());
|
||||
EXPECT_LONGS_EQUAL(2, cls.static_methods.size());
|
||||
EXPECT_LONGS_EQUAL(1, cls.namespaces.size());
|
||||
|
||||
// first constructor takes 3 doubles
|
||||
ArgumentList c1 = cls.constructor.args_list.front();
|
||||
ArgumentList c1 = cls.constructor.argumentList(0);
|
||||
EXPECT_LONGS_EQUAL(3, c1.size());
|
||||
|
||||
// check first double argument
|
||||
|
@ -266,7 +266,7 @@ TEST( wrap, Geometry ) {
|
|||
// Test class is the third one
|
||||
{
|
||||
Class testCls = module.classes.at(2);
|
||||
EXPECT_LONGS_EQUAL( 2, testCls.constructor.args_list.size());
|
||||
EXPECT_LONGS_EQUAL( 2, testCls.constructor.nrOverloads());
|
||||
EXPECT_LONGS_EQUAL(19, testCls.nrMethods());
|
||||
EXPECT_LONGS_EQUAL( 0, testCls.static_methods.size());
|
||||
EXPECT_LONGS_EQUAL( 0, testCls.namespaces.size());
|
||||
|
|
Loading…
Reference in New Issue