Fixed instance variable naming convention
parent
0fd12d9a05
commit
307fd2737a
|
|
@ -78,7 +78,7 @@ void Class::matlab_make_fragment(ofstream& ofs,
|
||||||
ofs << mex << c.matlab_wrapper_name(name) << ".cpp" << endl;
|
ofs << mex << c.matlab_wrapper_name(name) << ".cpp" << endl;
|
||||||
ofs << endl << "cd @" << name << endl;
|
ofs << endl << "cd @" << name << endl;
|
||||||
BOOST_FOREACH(Method m, methods)
|
BOOST_FOREACH(Method m, methods)
|
||||||
ofs << mex << m.name << ".cpp" << endl;
|
ofs << mex << m.name_ << ".cpp" << endl;
|
||||||
ofs << endl;
|
ofs << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,32 +36,32 @@ string maybe_shared_ptr(bool add, const string& type) {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
string Method::return_type(bool add_ptr, pairing p) {
|
string Method::return_type(bool add_ptr, pairing p) {
|
||||||
if (p==pair && returns_pair) {
|
if (p==pair && returns_pair_) {
|
||||||
string str = "pair< " +
|
string str = "pair< " +
|
||||||
maybe_shared_ptr(add_ptr && returns_ptr, returns ) + ", " +
|
maybe_shared_ptr(add_ptr && returns_ptr_, returns_) + ", " +
|
||||||
maybe_shared_ptr(add_ptr && returns_ptr, returns2) + " >";
|
maybe_shared_ptr(add_ptr && returns_ptr_, returns2_) + " >";
|
||||||
return str;
|
return str;
|
||||||
} else
|
} else
|
||||||
return maybe_shared_ptr(add_ptr && returns_ptr, (p==arg2)? returns2 : returns);
|
return maybe_shared_ptr(add_ptr && returns_ptr_, (p==arg2)? returns2_ : returns_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Method::matlab_mfile(const string& classPath) {
|
void Method::matlab_mfile(const string& classPath) {
|
||||||
|
|
||||||
// open destination m-file
|
// open destination m-file
|
||||||
string wrapperFile = classPath + "/" + name + ".m";
|
string wrapperFile = classPath + "/" + name_ + ".m";
|
||||||
ofstream ofs(wrapperFile.c_str());
|
ofstream ofs(wrapperFile.c_str());
|
||||||
if(!ofs) throw CantOpenFile(wrapperFile);
|
if(!ofs) throw CantOpenFile(wrapperFile);
|
||||||
if(verbose_) cerr << "generating " << wrapperFile << endl;
|
if(verbose_) cerr << "generating " << wrapperFile << endl;
|
||||||
|
|
||||||
// generate code
|
// generate code
|
||||||
emit_header_comment(ofs, "%");
|
emit_header_comment(ofs, "%");
|
||||||
ofs << "% usage: obj." << name << "(" << args.names() << ")" << endl;
|
ofs << "% usage: obj." << name_ << "(" << args_.names() << ")" << endl;
|
||||||
string returnType = returns_pair? "[first,second]" : "result";
|
string returnType = returns_pair_? "[first,second]" : "result";
|
||||||
ofs << "function " << returnType << " = " << name << "(obj";
|
ofs << "function " << returnType << " = " << name_ << "(obj";
|
||||||
if (args.size()) ofs << "," << args.names();
|
if (args_.size()) ofs << "," << args_.names();
|
||||||
ofs << ")" << endl;
|
ofs << ")" << endl;
|
||||||
ofs << " error('need to compile " << name << ".cpp');" << endl;
|
ofs << " error('need to compile " << name_ << ".cpp');" << endl;
|
||||||
ofs << "end" << endl;
|
ofs << "end" << endl;
|
||||||
|
|
||||||
// close file
|
// close file
|
||||||
|
|
@ -74,7 +74,7 @@ void Method::matlab_wrapper(const string& classPath,
|
||||||
const string& nameSpace)
|
const string& nameSpace)
|
||||||
{
|
{
|
||||||
// open destination wrapperFile
|
// open destination wrapperFile
|
||||||
string wrapperFile = classPath + "/" + name + ".cpp";
|
string wrapperFile = classPath + "/" + name_ + ".cpp";
|
||||||
ofstream ofs(wrapperFile.c_str());
|
ofstream ofs(wrapperFile.c_str());
|
||||||
if(!ofs) throw CantOpenFile(wrapperFile);
|
if(!ofs) throw CantOpenFile(wrapperFile);
|
||||||
if(verbose_) cerr << "generating " << wrapperFile << endl;
|
if(verbose_) cerr << "generating " << wrapperFile << endl;
|
||||||
|
|
@ -95,7 +95,7 @@ void Method::matlab_wrapper(const string& classPath,
|
||||||
// check arguments
|
// check arguments
|
||||||
// extra argument obj -> nargin-1 is passed !
|
// extra argument obj -> nargin-1 is passed !
|
||||||
// example: checkArguments("equals",nargout,nargin-1,2);
|
// example: checkArguments("equals",nargout,nargin-1,2);
|
||||||
ofs << " checkArguments(\"" << name << "\",nargout,nargin-1," << args.size() << ");\n";
|
ofs << " checkArguments(\"" << name_ << "\",nargout,nargin-1," << args_.size() << ");\n";
|
||||||
|
|
||||||
// get class pointer
|
// get class pointer
|
||||||
// example: shared_ptr<Test> = unwrap_shared_ptr< Test >(in[0], "Test");
|
// example: shared_ptr<Test> = unwrap_shared_ptr< Test >(in[0], "Test");
|
||||||
|
|
@ -103,30 +103,30 @@ void Method::matlab_wrapper(const string& classPath,
|
||||||
<< " >(in[0],\"" << className << "\");" << endl;
|
<< " >(in[0],\"" << className << "\");" << endl;
|
||||||
|
|
||||||
// unwrap arguments, see Argument.cpp
|
// unwrap arguments, see Argument.cpp
|
||||||
args.matlab_unwrap(ofs,1);
|
args_.matlab_unwrap(ofs,1);
|
||||||
|
|
||||||
// call method
|
// call method
|
||||||
// example: bool result = self->return_field(t);
|
// example: bool result = self->return_field(t);
|
||||||
ofs << " ";
|
ofs << " ";
|
||||||
if (returns!="void")
|
if (returns_!="void")
|
||||||
ofs << return_type(true,pair) << " result = ";
|
ofs << return_type(true,pair) << " result = ";
|
||||||
ofs << "self->" << name << "(" << args.names() << ");\n";
|
ofs << "self->" << name_ << "(" << args_.names() << ");\n";
|
||||||
|
|
||||||
// wrap result
|
// wrap result
|
||||||
// example: out[0]=wrap<bool>(result);
|
// example: out[0]=wrap<bool>(result);
|
||||||
if (returns_pair) {
|
if (returns_pair_) {
|
||||||
if (returns_ptr)
|
if (returns_ptr_)
|
||||||
ofs << " out[0] = wrap_shared_ptr(result.first,\"" << returns << "\");\n";
|
ofs << " out[0] = wrap_shared_ptr(result.first,\"" << returns_ << "\");\n";
|
||||||
else
|
else
|
||||||
ofs << " out[0] = wrap< " << return_type(true,arg1) << " >(result.first);\n";
|
ofs << " out[0] = wrap< " << return_type(true,arg1) << " >(result.first);\n";
|
||||||
if (returns_ptr2)
|
if (returns_ptr2_)
|
||||||
ofs << " out[1] = wrap_shared_ptr(result.second,\"" << returns2 << "\");\n";
|
ofs << " out[1] = wrap_shared_ptr(result.second,\"" << returns2_ << "\");\n";
|
||||||
else
|
else
|
||||||
ofs << " out[1] = wrap< " << return_type(true,arg2) << " >(result.second);\n";
|
ofs << " out[1] = wrap< " << return_type(true,arg2) << " >(result.second);\n";
|
||||||
}
|
}
|
||||||
else if (returns_ptr)
|
else if (returns_ptr_)
|
||||||
ofs << " out[0] = wrap_shared_ptr(result,\"" << returns << "\");\n";
|
ofs << " out[0] = wrap_shared_ptr(result,\"" << returns_ << "\");\n";
|
||||||
else if (returns!="void")
|
else if (returns_!="void")
|
||||||
ofs << " out[0] = wrap< " << return_type(true,arg1) << " >(result);\n";
|
ofs << " out[0] = wrap< " << return_type(true,arg1) << " >(result);\n";
|
||||||
|
|
||||||
// finish
|
// finish
|
||||||
|
|
|
||||||
|
|
@ -27,15 +27,15 @@ struct Method {
|
||||||
|
|
||||||
/// Constructor creates empty object
|
/// Constructor creates empty object
|
||||||
Method(bool verbose = true) :
|
Method(bool verbose = true) :
|
||||||
returns_ptr(false), returns_ptr2(false), returns_pair(false), verbose_(
|
returns_ptr_(false), returns_ptr2_(false), returns_pair_(false), verbose_(
|
||||||
verbose) {
|
verbose) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then the instance variables are set directly by the Module constructor
|
// Then the instance variables are set directly by the Module constructor
|
||||||
bool is_const;
|
bool is_const_;
|
||||||
ArgumentList args;
|
ArgumentList args_;
|
||||||
std::string returns, returns2, name;
|
std::string returns_, returns2_, name_;
|
||||||
bool returns_ptr, returns_ptr2, returns_pair;
|
bool returns_ptr_, returns_ptr2_, returns_pair_;
|
||||||
bool verbose_;
|
bool verbose_;
|
||||||
|
|
||||||
enum pairing {
|
enum pairing {
|
||||||
|
|
|
||||||
|
|
@ -97,30 +97,30 @@ Module::Module(const string& interfacePath,
|
||||||
[assign_a(constructor,constructor0)];
|
[assign_a(constructor,constructor0)];
|
||||||
|
|
||||||
Rule returnType1_p =
|
Rule returnType1_p =
|
||||||
basisType_p[assign_a(method.returns)] |
|
basisType_p[assign_a(method.returns_)] |
|
||||||
((className_p | "Vector" | "Matrix")[assign_a(method.returns)] >>
|
((className_p | "Vector" | "Matrix")[assign_a(method.returns_)] >>
|
||||||
!ch_p('*') [assign_a(method.returns_ptr,true)]);
|
!ch_p('*') [assign_a(method.returns_ptr_,true)]);
|
||||||
|
|
||||||
Rule returnType2_p =
|
Rule returnType2_p =
|
||||||
basisType_p[assign_a(method.returns2)] |
|
basisType_p[assign_a(method.returns2_)] |
|
||||||
((className_p | "Vector" | "Matrix")[assign_a(method.returns2)] >>
|
((className_p | "Vector" | "Matrix")[assign_a(method.returns2_)] >>
|
||||||
!ch_p('*') [assign_a(method.returns_ptr2,true)]);
|
!ch_p('*') [assign_a(method.returns_ptr2_,true)]);
|
||||||
|
|
||||||
Rule pair_p =
|
Rule pair_p =
|
||||||
(str_p("pair") >> '<' >> returnType1_p >> ',' >> returnType2_p >> '>')
|
(str_p("pair") >> '<' >> returnType1_p >> ',' >> returnType2_p >> '>')
|
||||||
[assign_a(method.returns_pair,true)];
|
[assign_a(method.returns_pair_,true)];
|
||||||
|
|
||||||
Rule void_p = str_p("void")[assign_a(method.returns)];
|
Rule void_p = str_p("void")[assign_a(method.returns_)];
|
||||||
|
|
||||||
Rule returnType_p = void_p | returnType1_p | pair_p;
|
Rule returnType_p = void_p | returnType1_p | pair_p;
|
||||||
|
|
||||||
Rule methodName_p = lexeme_d[lower_p >> *(alnum_p | '_')];
|
Rule methodName_p = lexeme_d[lower_p >> *(alnum_p | '_')];
|
||||||
|
|
||||||
Rule method_p =
|
Rule method_p =
|
||||||
(returnType_p >> methodName_p[assign_a(method.name)] >>
|
(returnType_p >> methodName_p[assign_a(method.name_)] >>
|
||||||
'(' >> argumentList_p >> ')' >>
|
'(' >> argumentList_p >> ')' >>
|
||||||
!str_p("const")[assign_a(method.is_const,true)] >> ';')
|
!str_p("const")[assign_a(method.is_const_,true)] >> ';')
|
||||||
[assign_a(method.args,args)]
|
[assign_a(method.args_,args)]
|
||||||
[assign_a(args,args0)]
|
[assign_a(args,args0)]
|
||||||
[push_back_a(cls.methods, method)]
|
[push_back_a(cls.methods, method)]
|
||||||
[assign_a(method,method0)];
|
[assign_a(method,method0)];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue