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