Cleanup in wrap
parent
216348622d
commit
6a0da1519a
|
@ -36,6 +36,9 @@
|
||||||
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base.1629258328" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base">
|
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base.1629258328" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base">
|
||||||
<option id="gnu.cpp.compiler.option.include.paths.1552452888" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
|
<option id="gnu.cpp.compiler.option.include.paths.1552452888" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/gtsam}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/gtsam}""/>
|
||||||
|
<listOptionValue builtIn="false" value="/usr/include/c++/4.6.1"/>
|
||||||
|
<listOptionValue builtIn="false" value="/usr/include/c++/4.6"/>
|
||||||
|
<listOptionValue builtIn="false" value="/usr/include/c++/4.6/backward"/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1833545667" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1833545667" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||||
</tool>
|
</tool>
|
||||||
|
|
|
@ -25,9 +25,7 @@ using namespace std;
|
||||||
using namespace wrap;
|
using namespace wrap;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Argument::matlab_unwrap(ofstream& ofs,
|
void Argument::matlab_unwrap(ofstream& ofs, const string& matlabName) const {
|
||||||
const string& matlabName)
|
|
||||||
{
|
|
||||||
ofs << " ";
|
ofs << " ";
|
||||||
|
|
||||||
string cppType = qualifiedType("::");
|
string cppType = qualifiedType("::");
|
||||||
|
@ -53,14 +51,14 @@ void Argument::matlab_unwrap(ofstream& ofs,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
string Argument::qualifiedType(const string& delim) {
|
string Argument::qualifiedType(const string& delim) const {
|
||||||
string result;
|
string result;
|
||||||
BOOST_FOREACH(const string& ns, namespaces) result += ns + delim;
|
BOOST_FOREACH(const string& ns, namespaces) result += ns + delim;
|
||||||
return result + type;
|
return result + type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
string ArgumentList::types() {
|
string ArgumentList::types() const {
|
||||||
string str;
|
string str;
|
||||||
bool first=true;
|
bool first=true;
|
||||||
BOOST_FOREACH(Argument arg, *this) {
|
BOOST_FOREACH(Argument arg, *this) {
|
||||||
|
@ -70,7 +68,7 @@ string ArgumentList::types() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
string ArgumentList::signature() {
|
string ArgumentList::signature() const {
|
||||||
string str;
|
string str;
|
||||||
BOOST_FOREACH(Argument arg, *this)
|
BOOST_FOREACH(Argument arg, *this)
|
||||||
str += arg.type[0];
|
str += arg.type[0];
|
||||||
|
@ -78,7 +76,7 @@ string ArgumentList::signature() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
string ArgumentList::names() {
|
string ArgumentList::names() const {
|
||||||
string str;
|
string str;
|
||||||
bool first=true;
|
bool first=true;
|
||||||
BOOST_FOREACH(Argument arg, *this) {
|
BOOST_FOREACH(Argument arg, *this) {
|
||||||
|
@ -88,7 +86,7 @@ string ArgumentList::names() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void ArgumentList::matlab_unwrap(ofstream& ofs, int start) {
|
void ArgumentList::matlab_unwrap(ofstream& ofs, int start) const {
|
||||||
int index = start;
|
int index = start;
|
||||||
BOOST_FOREACH(Argument arg, *this) {
|
BOOST_FOREACH(Argument arg, *this) {
|
||||||
stringstream buf;
|
stringstream buf;
|
||||||
|
|
|
@ -32,18 +32,18 @@ struct Argument {
|
||||||
is_const(false), is_ref(false), is_ptr(false) {
|
is_const(false), is_ref(false), is_ptr(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string qualifiedType(const std::string& delim = ""); // adds namespaces to type
|
std::string qualifiedType(const std::string& delim = "") const; // adds namespaces to type
|
||||||
|
|
||||||
/// MATLAB code generation, MATLAB to C++
|
/// MATLAB code generation, MATLAB to C++
|
||||||
void matlab_unwrap(std::ofstream& ofs, const std::string& matlabName);
|
void matlab_unwrap(std::ofstream& ofs, const std::string& matlabName) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Argument list
|
/// Argument list
|
||||||
struct ArgumentList: public std::vector<Argument> {
|
struct ArgumentList: public std::vector<Argument> {
|
||||||
std::vector<Argument> args; // why does it contain this?
|
std::vector<Argument> args; // why does it contain this?
|
||||||
std::string types();
|
std::string types() const;
|
||||||
std::string signature();
|
std::string signature() const;
|
||||||
std::string names();
|
std::string names() const;
|
||||||
|
|
||||||
// MATLAB code generation:
|
// MATLAB code generation:
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ struct ArgumentList: public std::vector<Argument> {
|
||||||
* @param ofs output stream
|
* @param ofs output stream
|
||||||
* @param start initial index for input array, set to 1 for method
|
* @param start initial index for input array, set to 1 for method
|
||||||
*/
|
*/
|
||||||
void matlab_unwrap(std::ofstream& ofs, int start = 0); // MATLAB to C++
|
void matlab_unwrap(std::ofstream& ofs, int start = 0) const; // MATLAB to C++
|
||||||
};
|
};
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
|
@ -27,7 +27,7 @@ using namespace std;
|
||||||
using namespace wrap;
|
using namespace wrap;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Class::matlab_proxy(const string& classFile) {
|
void Class::matlab_proxy(const string& classFile) const {
|
||||||
// open destination classFile
|
// open destination classFile
|
||||||
ofstream ofs(classFile.c_str());
|
ofstream ofs(classFile.c_str());
|
||||||
if(!ofs) throw CantOpenFile(classFile);
|
if(!ofs) throw CantOpenFile(classFile);
|
||||||
|
@ -57,7 +57,7 @@ void Class::matlab_proxy(const string& classFile) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Class::matlab_constructors(const string& toolboxPath, const vector<string>& using_namespaces) {
|
void Class::matlab_constructors(const string& toolboxPath, const vector<string>& using_namespaces) const {
|
||||||
BOOST_FOREACH(Constructor c, constructors) {
|
BOOST_FOREACH(Constructor c, constructors) {
|
||||||
c.matlab_mfile (toolboxPath, qualifiedName());
|
c.matlab_mfile (toolboxPath, qualifiedName());
|
||||||
c.matlab_wrapper(toolboxPath, qualifiedName("::"), qualifiedName(), using_namespaces, includes);
|
c.matlab_wrapper(toolboxPath, qualifiedName("::"), qualifiedName(), using_namespaces, includes);
|
||||||
|
@ -65,7 +65,7 @@ void Class::matlab_constructors(const string& toolboxPath, const vector<string>&
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Class::matlab_methods(const string& classPath, const vector<string>& using_namespaces) {
|
void Class::matlab_methods(const string& classPath, const vector<string>& using_namespaces) const {
|
||||||
string matlabName = qualifiedName(), cppName = qualifiedName("::");
|
string matlabName = qualifiedName(), cppName = qualifiedName("::");
|
||||||
BOOST_FOREACH(Method m, methods) {
|
BOOST_FOREACH(Method m, methods) {
|
||||||
m.matlab_mfile (classPath);
|
m.matlab_mfile (classPath);
|
||||||
|
@ -74,9 +74,9 @@ void Class::matlab_methods(const string& classPath, const vector<string>& using_
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Class::matlab_static_methods(const string& toolboxPath, const vector<string>& using_namespaces) {
|
void Class::matlab_static_methods(const string& toolboxPath, const vector<string>& using_namespaces) const {
|
||||||
string matlabName = qualifiedName(), cppName = qualifiedName("::");
|
string matlabName = qualifiedName(), cppName = qualifiedName("::");
|
||||||
BOOST_FOREACH(StaticMethod& m, static_methods) {
|
BOOST_FOREACH(const StaticMethod& m, static_methods) {
|
||||||
m.matlab_mfile (toolboxPath, qualifiedName());
|
m.matlab_mfile (toolboxPath, qualifiedName());
|
||||||
m.matlab_wrapper(toolboxPath, name, matlabName, cppName, using_namespaces, includes);
|
m.matlab_wrapper(toolboxPath, name, matlabName, cppName, using_namespaces, includes);
|
||||||
}
|
}
|
||||||
|
@ -85,8 +85,7 @@ void Class::matlab_static_methods(const string& toolboxPath, const vector<string
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Class::matlab_make_fragment(ofstream& ofs,
|
void Class::matlab_make_fragment(ofstream& ofs,
|
||||||
const string& toolboxPath,
|
const string& toolboxPath,
|
||||||
const string& mexFlags)
|
const string& mexFlags) const {
|
||||||
{
|
|
||||||
string mex = "mex " + mexFlags + " ";
|
string mex = "mex " + mexFlags + " ";
|
||||||
string matlabClassName = qualifiedName();
|
string matlabClassName = qualifiedName();
|
||||||
BOOST_FOREACH(Constructor c, constructors)
|
BOOST_FOREACH(Constructor c, constructors)
|
||||||
|
@ -100,7 +99,7 @@ void Class::matlab_make_fragment(ofstream& ofs,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Class::makefile_fragment(ofstream& ofs) {
|
void Class::makefile_fragment(ofstream& ofs) const {
|
||||||
// new_Point2_.$(MEXENDING): new_Point2_.cpp
|
// new_Point2_.$(MEXENDING): new_Point2_.cpp
|
||||||
// $(MEX) $(mex_flags) new_Point2_.cpp
|
// $(MEX) $(mex_flags) new_Point2_.cpp
|
||||||
// new_Point2_dd.$(MEXENDING): new_Point2_dd.cpp
|
// new_Point2_dd.$(MEXENDING): new_Point2_dd.cpp
|
||||||
|
|
12
wrap/Class.h
12
wrap/Class.h
|
@ -40,17 +40,17 @@ struct Class {
|
||||||
bool verbose_; ///< verbose flag
|
bool verbose_; ///< verbose flag
|
||||||
|
|
||||||
// And finally MATLAB code is emitted, methods below called by Module::matlab_code
|
// And finally MATLAB code is emitted, methods below called by Module::matlab_code
|
||||||
void matlab_proxy(const std::string& classFile); ///< emit proxy class
|
void matlab_proxy(const std::string& classFile) const; ///< emit proxy class
|
||||||
void matlab_constructors(const std::string& toolboxPath,
|
void matlab_constructors(const std::string& toolboxPath,
|
||||||
const std::vector<std::string>& using_namespaces); ///< emit constructor wrappers
|
const std::vector<std::string>& using_namespaces) const; ///< emit constructor wrappers
|
||||||
void matlab_methods(const std::string& classPath,
|
void matlab_methods(const std::string& classPath,
|
||||||
const std::vector<std::string>& using_namespaces); ///< emit method wrappers
|
const std::vector<std::string>& using_namespaces) const; ///< emit method wrappers
|
||||||
void matlab_static_methods(const std::string& classPath,
|
void matlab_static_methods(const std::string& classPath,
|
||||||
const std::vector<std::string>& using_namespaces); ///< emit static method wrappers
|
const std::vector<std::string>& using_namespaces) const; ///< emit static method wrappers
|
||||||
void matlab_make_fragment(std::ofstream& ofs,
|
void matlab_make_fragment(std::ofstream& ofs,
|
||||||
const std::string& toolboxPath,
|
const std::string& toolboxPath,
|
||||||
const std::string& mexFlags); ///< emit make fragment for global make script
|
const std::string& mexFlags) const; ///< emit make fragment for global make script
|
||||||
void makefile_fragment(std::ofstream& ofs); ///< emit makefile fragment
|
void makefile_fragment(std::ofstream& ofs) const; ///< emit makefile fragment
|
||||||
std::string qualifiedName(const std::string& delim = "") const; ///< creates a namespace-qualified name, optional delimiter
|
std::string qualifiedName(const std::string& delim = "") const; ///< creates a namespace-qualified name, optional delimiter
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,13 @@ using namespace std;
|
||||||
using namespace wrap;
|
using namespace wrap;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
string Constructor::matlab_wrapper_name(const string& className) {
|
string Constructor::matlab_wrapper_name(const string& className) const {
|
||||||
string str = "new_" + className + "_" + args.signature();
|
string str = "new_" + className + "_" + args.signature();
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Constructor::matlab_proxy_fragment(ofstream& ofs, const string& className) {
|
void Constructor::matlab_proxy_fragment(ofstream& ofs, const string& className) const {
|
||||||
ofs << " if nargin == " << args.size() << ", obj.self = "
|
ofs << " if nargin == " << args.size() << ", obj.self = "
|
||||||
<< matlab_wrapper_name(className) << "(";
|
<< matlab_wrapper_name(className) << "(";
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
@ -45,7 +45,7 @@ void Constructor::matlab_proxy_fragment(ofstream& ofs, const string& className)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Constructor::matlab_mfile(const string& toolboxPath, const string& qualifiedMatlabName) {
|
void Constructor::matlab_mfile(const string& toolboxPath, const string& qualifiedMatlabName) const {
|
||||||
|
|
||||||
string matlabName = matlab_wrapper_name(qualifiedMatlabName);
|
string matlabName = matlab_wrapper_name(qualifiedMatlabName);
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ void Constructor::matlab_mfile(const string& toolboxPath, const string& qualifie
|
||||||
if(verbose_) cerr << "generating " << wrapperFile << endl;
|
if(verbose_) cerr << "generating " << wrapperFile << endl;
|
||||||
|
|
||||||
// generate code
|
// generate code
|
||||||
emit_header_comment(ofs, "%");
|
generateHeaderComment(ofs, "%");
|
||||||
ofs << "function result = " << matlabName << "(obj";
|
ofs << "function result = " << matlabName << "(obj";
|
||||||
if (args.size()) ofs << "," << args.names();
|
if (args.size()) ofs << "," << args.names();
|
||||||
ofs << ")" << endl;
|
ofs << ")" << endl;
|
||||||
|
@ -71,8 +71,7 @@ void Constructor::matlab_mfile(const string& toolboxPath, const string& qualifie
|
||||||
void Constructor::matlab_wrapper(const string& toolboxPath,
|
void Constructor::matlab_wrapper(const string& toolboxPath,
|
||||||
const string& cppClassName,
|
const string& cppClassName,
|
||||||
const string& matlabClassName,
|
const string& matlabClassName,
|
||||||
const vector<string>& using_namespaces, const vector<string>& includes)
|
const vector<string>& using_namespaces, const vector<string>& includes) const {
|
||||||
{
|
|
||||||
string matlabName = matlab_wrapper_name(matlabClassName);
|
string matlabName = matlab_wrapper_name(matlabClassName);
|
||||||
|
|
||||||
// open destination wrapperFile
|
// open destination wrapperFile
|
||||||
|
@ -82,7 +81,7 @@ void Constructor::matlab_wrapper(const string& toolboxPath,
|
||||||
if(verbose_) cerr << "generating " << wrapperFile << endl;
|
if(verbose_) cerr << "generating " << wrapperFile << endl;
|
||||||
|
|
||||||
// generate code
|
// generate code
|
||||||
emit_header_comment(ofs, "//");
|
generateHeaderComment(ofs, "//");
|
||||||
generateIncludes(ofs, name, includes);
|
generateIncludes(ofs, name, includes);
|
||||||
generateUsingNamespace(ofs, using_namespaces);
|
generateUsingNamespace(ofs, using_namespaces);
|
||||||
|
|
||||||
|
|
|
@ -42,21 +42,21 @@ struct Constructor {
|
||||||
// classFile is class proxy file, e.g., ../matlab/@Point2/Point2.m
|
// classFile is class proxy file, e.g., ../matlab/@Point2/Point2.m
|
||||||
|
|
||||||
/// wrapper name
|
/// wrapper name
|
||||||
std::string matlab_wrapper_name(const std::string& className);
|
std::string matlab_wrapper_name(const std::string& className) const;
|
||||||
|
|
||||||
/// proxy class fragment
|
/// proxy class fragment
|
||||||
void matlab_proxy_fragment(std::ofstream& ofs, const std::string& className);
|
void matlab_proxy_fragment(std::ofstream& ofs, const std::string& className) const;
|
||||||
|
|
||||||
/// m-file
|
/// m-file
|
||||||
void matlab_mfile(const std::string& toolboxPath,
|
void matlab_mfile(const std::string& toolboxPath,
|
||||||
const std::string& qualifiedMatlabName);
|
const std::string& qualifiedMatlabName) const;
|
||||||
|
|
||||||
/// cpp wrapper
|
/// cpp wrapper
|
||||||
void matlab_wrapper(const std::string& toolboxPath,
|
void matlab_wrapper(const std::string& toolboxPath,
|
||||||
const std::string& cppClassName,
|
const std::string& cppClassName,
|
||||||
const std::string& matlabClassName,
|
const std::string& matlabClassName,
|
||||||
const std::vector<std::string>& using_namespaces,
|
const std::vector<std::string>& using_namespaces,
|
||||||
const std::vector<std::string>& includes);
|
const std::vector<std::string>& includes) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
|
@ -26,7 +26,7 @@ using namespace std;
|
||||||
using namespace wrap;
|
using namespace wrap;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Method::matlab_mfile(const string& classPath) {
|
void Method::matlab_mfile(const string& classPath) const {
|
||||||
|
|
||||||
// open destination m-file
|
// open destination m-file
|
||||||
string wrapperFile = classPath + "/" + name + ".m";
|
string wrapperFile = classPath + "/" + name + ".m";
|
||||||
|
@ -52,8 +52,7 @@ void Method::matlab_wrapper(const string& classPath,
|
||||||
const string& className,
|
const string& className,
|
||||||
const string& cppClassName,
|
const string& cppClassName,
|
||||||
const string& matlabClassName,
|
const string& matlabClassName,
|
||||||
const vector<string>& using_namespaces, const std::vector<std::string>& includes)
|
const vector<string>& using_namespaces, const std::vector<std::string>& includes) const {
|
||||||
{
|
|
||||||
// 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());
|
||||||
|
@ -63,7 +62,7 @@ void Method::matlab_wrapper(const string& classPath,
|
||||||
// generate code
|
// generate code
|
||||||
|
|
||||||
// header
|
// header
|
||||||
wrap::emit_header_comment(ofs, "//");
|
generateHeaderComment(ofs, "//");
|
||||||
generateIncludes(ofs, className, includes);
|
generateIncludes(ofs, className, includes);
|
||||||
generateUsingNamespace(ofs, using_namespaces);
|
generateUsingNamespace(ofs, using_namespaces);
|
||||||
|
|
||||||
|
|
|
@ -42,13 +42,13 @@ struct Method {
|
||||||
// MATLAB code generation
|
// MATLAB code generation
|
||||||
// classPath is class directory, e.g., ../matlab/@Point2
|
// classPath is class directory, e.g., ../matlab/@Point2
|
||||||
|
|
||||||
void matlab_mfile(const std::string& classPath); ///< m-file
|
void matlab_mfile(const std::string& classPath) const; ///< m-file
|
||||||
void matlab_wrapper(const std::string& classPath,
|
void matlab_wrapper(const std::string& classPath,
|
||||||
const std::string& className,
|
const std::string& className,
|
||||||
const std::string& cppClassName,
|
const std::string& cppClassName,
|
||||||
const std::string& matlabClassname,
|
const std::string& matlabClassname,
|
||||||
const std::vector<std::string>& using_namespaces,
|
const std::vector<std::string>& using_namespaces,
|
||||||
const std::vector<std::string>& includes); ///< cpp wrapper
|
const std::vector<std::string>& includes) const; ///< cpp wrapper
|
||||||
};
|
};
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
|
@ -232,7 +232,7 @@ void verifyArguments(const vector<string>& validArgs, const vector<T>& vt) {
|
||||||
BOOST_FOREACH(const T& t, vt) {
|
BOOST_FOREACH(const T& t, vt) {
|
||||||
BOOST_FOREACH(Argument arg, t.args) {
|
BOOST_FOREACH(Argument arg, t.args) {
|
||||||
string fullType = arg.qualifiedType("::");
|
string fullType = arg.qualifiedType("::");
|
||||||
if(std::find(validArgs.begin(), validArgs.end(), fullType)
|
if(find(validArgs.begin(), validArgs.end(), fullType)
|
||||||
== validArgs.end())
|
== validArgs.end())
|
||||||
throw DependencyMissing(fullType, t.name);
|
throw DependencyMissing(fullType, t.name);
|
||||||
}
|
}
|
||||||
|
@ -241,9 +241,7 @@ void verifyArguments(const vector<string>& validArgs, const vector<T>& vt) {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Module::matlab_code(const string& toolboxPath,
|
void Module::matlab_code(const string& toolboxPath,
|
||||||
const string& mexExt,
|
const string& mexExt, const string& mexFlags) const {
|
||||||
const string& mexFlags)
|
|
||||||
{
|
|
||||||
string installCmd = "install -d " + toolboxPath;
|
string installCmd = "install -d " + toolboxPath;
|
||||||
system(installCmd.c_str());
|
system(installCmd.c_str());
|
||||||
|
|
||||||
|
@ -258,7 +256,7 @@ void Module::matlab_code(const string& toolboxPath,
|
||||||
if(!make_ofs) throw CantOpenFile(makeFile);
|
if(!make_ofs) throw CantOpenFile(makeFile);
|
||||||
|
|
||||||
if (verbose) cerr << "generating " << matlabMakeFile << endl;
|
if (verbose) cerr << "generating " << matlabMakeFile << endl;
|
||||||
emit_header_comment(ofs,"%");
|
generateHeaderComment(ofs,"%");
|
||||||
ofs << "echo on" << endl << endl;
|
ofs << "echo on" << endl << endl;
|
||||||
ofs << "toolboxpath = mfilename('fullpath');" << endl;
|
ofs << "toolboxpath = mfilename('fullpath');" << endl;
|
||||||
ofs << "delims = find(toolboxpath == '/');" << endl;
|
ofs << "delims = find(toolboxpath == '/');" << endl;
|
||||||
|
@ -267,13 +265,13 @@ void Module::matlab_code(const string& toolboxPath,
|
||||||
ofs << "addpath(toolboxpath);" << endl << endl;
|
ofs << "addpath(toolboxpath);" << endl << endl;
|
||||||
|
|
||||||
if (verbose) cerr << "generating " << makeFile << endl;
|
if (verbose) cerr << "generating " << makeFile << endl;
|
||||||
emit_header_comment(make_ofs,"#");
|
generateHeaderComment(make_ofs,"#");
|
||||||
make_ofs << "\nMEX = mex\n";
|
make_ofs << "\nMEX = mex\n";
|
||||||
make_ofs << "MEXENDING = " << mexExt << "\n";
|
make_ofs << "MEXENDING = " << mexExt << "\n";
|
||||||
make_ofs << "mex_flags = " << mexFlags << "\n\n";
|
make_ofs << "mex_flags = " << mexFlags << "\n\n";
|
||||||
|
|
||||||
//Dependency check list
|
//Dependency check list
|
||||||
std::vector<string> validArgs;
|
vector<string> validArgs;
|
||||||
validArgs.push_back("string");
|
validArgs.push_back("string");
|
||||||
validArgs.push_back("int");
|
validArgs.push_back("int");
|
||||||
validArgs.push_back("bool");
|
validArgs.push_back("bool");
|
||||||
|
|
|
@ -41,7 +41,7 @@ struct Module {
|
||||||
/// MATLAB code generation:
|
/// MATLAB code generation:
|
||||||
void matlab_code(const std::string& path,
|
void matlab_code(const std::string& path,
|
||||||
const std::string& mexExt,
|
const std::string& mexExt,
|
||||||
const std::string& mexFlags);
|
const std::string& mexFlags) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
|
@ -14,7 +14,7 @@ using namespace std;
|
||||||
using namespace wrap;
|
using namespace wrap;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
string ReturnValue::return_type(bool add_ptr, pairing p) {
|
string ReturnValue::return_type(bool add_ptr, pairing p) const {
|
||||||
if (p==pair && isPair) {
|
if (p==pair && isPair) {
|
||||||
string str = "pair< " +
|
string str = "pair< " +
|
||||||
maybe_shared_ptr(add_ptr && isPtr1, qualifiedType1("::")) + ", " +
|
maybe_shared_ptr(add_ptr && isPtr1, qualifiedType1("::")) + ", " +
|
||||||
|
@ -30,21 +30,21 @@ string ReturnValue::matlab_returnType() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
string ReturnValue::qualifiedType1(const string& delim) {
|
string ReturnValue::qualifiedType1(const string& delim) const {
|
||||||
string result;
|
string result;
|
||||||
BOOST_FOREACH(const string& ns, namespaces1) result += ns + delim;
|
BOOST_FOREACH(const string& ns, namespaces1) result += ns + delim;
|
||||||
return result + type1;
|
return result + type1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
string ReturnValue::qualifiedType2(const string& delim) {
|
string ReturnValue::qualifiedType2(const string& delim) const {
|
||||||
string result;
|
string result;
|
||||||
BOOST_FOREACH(const string& ns, namespaces2) result += ns + delim;
|
BOOST_FOREACH(const string& ns, namespaces2) result += ns + delim;
|
||||||
return result + type2;
|
return result + type2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void ReturnValue::wrap_result(std::ostream& ofs) {
|
void ReturnValue::wrap_result(ostream& ofs) const {
|
||||||
string cppType1 = qualifiedType1("::"), matlabType1 = qualifiedType1();
|
string cppType1 = qualifiedType1("::"), matlabType1 = qualifiedType1();
|
||||||
string cppType2 = qualifiedType2("::"), matlabType2 = qualifiedType2();
|
string cppType2 = qualifiedType2("::"), matlabType2 = qualifiedType2();
|
||||||
|
|
||||||
|
|
|
@ -39,14 +39,14 @@ struct ReturnValue {
|
||||||
arg1, arg2, pair
|
arg1, arg2, pair
|
||||||
} pairing;
|
} pairing;
|
||||||
|
|
||||||
std::string return_type(bool add_ptr, pairing p);
|
std::string return_type(bool add_ptr, pairing p) const;
|
||||||
|
|
||||||
std::string qualifiedType1(const std::string& delim = "");
|
std::string qualifiedType1(const std::string& delim = "") const;
|
||||||
std::string qualifiedType2(const std::string& delim = "");
|
std::string qualifiedType2(const std::string& delim = "") const;
|
||||||
|
|
||||||
std::string matlab_returnType() const;
|
std::string matlab_returnType() const;
|
||||||
|
|
||||||
void wrap_result(std::ostream& ofs);
|
void wrap_result(std::ostream& ofs) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ using namespace std;
|
||||||
using namespace wrap;
|
using namespace wrap;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void StaticMethod::matlab_mfile(const string& toolboxPath, const string& className) {
|
void StaticMethod::matlab_mfile(const string& toolboxPath, const string& className) const {
|
||||||
|
|
||||||
// open destination m-file
|
// open destination m-file
|
||||||
string full_name = className + "_" + name;
|
string full_name = className + "_" + name;
|
||||||
|
@ -52,8 +52,7 @@ void StaticMethod::matlab_mfile(const string& toolboxPath, const string& classNa
|
||||||
void StaticMethod::matlab_wrapper(const string& toolboxPath, const string& className,
|
void StaticMethod::matlab_wrapper(const string& toolboxPath, const string& className,
|
||||||
const string& matlabClassName, const string& cppClassName,
|
const string& matlabClassName, const string& cppClassName,
|
||||||
const vector<string>& using_namespaces,
|
const vector<string>& using_namespaces,
|
||||||
const std::vector<std::string>& includes)
|
const vector<string>& includes) const {
|
||||||
{
|
|
||||||
// open destination wrapperFile
|
// open destination wrapperFile
|
||||||
string full_name = matlabClassName + "_" + name;
|
string full_name = matlabClassName + "_" + name;
|
||||||
string wrapperFile = toolboxPath + "/" + full_name + ".cpp";
|
string wrapperFile = toolboxPath + "/" + full_name + ".cpp";
|
||||||
|
@ -64,7 +63,7 @@ void StaticMethod::matlab_wrapper(const string& toolboxPath, const string& class
|
||||||
// generate code
|
// generate code
|
||||||
|
|
||||||
// header
|
// header
|
||||||
wrap::emit_header_comment(ofs, "//");
|
generateHeaderComment(ofs, "//");
|
||||||
generateIncludes(ofs, className, includes);
|
generateIncludes(ofs, className, includes);
|
||||||
generateUsingNamespace(ofs, using_namespaces);
|
generateUsingNamespace(ofs, using_namespaces);
|
||||||
|
|
||||||
|
|
|
@ -44,12 +44,12 @@ struct StaticMethod {
|
||||||
// NOTE: static functions are not inside the class, and
|
// NOTE: static functions are not inside the class, and
|
||||||
// are created with [ClassName]_[FunctionName]() format
|
// are created with [ClassName]_[FunctionName]() format
|
||||||
|
|
||||||
void matlab_mfile(const std::string& toolboxPath, const std::string& className); ///< m-file
|
void matlab_mfile(const std::string& toolboxPath, const std::string& className) const; ///< m-file
|
||||||
void matlab_wrapper(const std::string& toolboxPath,
|
void matlab_wrapper(const std::string& toolboxPath,
|
||||||
const std::string& className, const std::string& matlabClassName,
|
const std::string& className, const std::string& matlabClassName,
|
||||||
const std::string& cppClassName,
|
const std::string& cppClassName,
|
||||||
const std::vector<std::string>& using_namespaces,
|
const std::vector<std::string>& using_namespaces,
|
||||||
const std::vector<std::string>& includes); ///< cpp wrapper
|
const std::vector<std::string>& includes) const; ///< cpp wrapper
|
||||||
};
|
};
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
|
@ -76,7 +76,7 @@ bool files_equal(const string& expected, const string& actual, bool skipheader)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void emit_header_comment(ofstream& ofs, const string& delimiter) {
|
void generateHeaderComment(ofstream& ofs, const string& delimiter) {
|
||||||
date today = day_clock::local_day();
|
date today = day_clock::local_day();
|
||||||
ofs << delimiter << " automatically generated by wrap on " << today << endl;
|
ofs << delimiter << " automatically generated by wrap on " << today << endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ bool assert_equal(const std::string& expected, const std::string& actual);
|
||||||
/**
|
/**
|
||||||
* emit a header at the top of generated files
|
* emit a header at the top of generated files
|
||||||
*/
|
*/
|
||||||
void emit_header_comment(std::ofstream& ofs, const std::string& delimiter);
|
void generateHeaderComment(std::ofstream& ofs, const std::string& delimiter);
|
||||||
|
|
||||||
// auxiliary function to wrap an argument into a shared_ptr template
|
// auxiliary function to wrap an argument into a shared_ptr template
|
||||||
std::string maybe_shared_ptr(bool add, const std::string& type);
|
std::string maybe_shared_ptr(bool add, const std::string& type);
|
||||||
|
|
Loading…
Reference in New Issue