Cleanup in wrap

release/4.3a0
Alex Cunningham 2011-12-11 21:09:07 +00:00
parent 216348622d
commit 6a0da1519a
17 changed files with 64 additions and 69 deletions

View File

@ -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">
<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="&quot;${workspace_loc:/gtsam}&quot;"/>
<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>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1833545667" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>

View File

@ -25,9 +25,7 @@ using namespace std;
using namespace wrap;
/* ************************************************************************* */
void Argument::matlab_unwrap(ofstream& ofs,
const string& matlabName)
{
void Argument::matlab_unwrap(ofstream& ofs, const string& matlabName) const {
ofs << " ";
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;
BOOST_FOREACH(const string& ns, namespaces) result += ns + delim;
return result + type;
}
/* ************************************************************************* */
string ArgumentList::types() {
string ArgumentList::types() const {
string str;
bool first=true;
BOOST_FOREACH(Argument arg, *this) {
@ -70,7 +68,7 @@ string ArgumentList::types() {
}
/* ************************************************************************* */
string ArgumentList::signature() {
string ArgumentList::signature() const {
string str;
BOOST_FOREACH(Argument arg, *this)
str += arg.type[0];
@ -78,7 +76,7 @@ string ArgumentList::signature() {
}
/* ************************************************************************* */
string ArgumentList::names() {
string ArgumentList::names() const {
string str;
bool first=true;
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;
BOOST_FOREACH(Argument arg, *this) {
stringstream buf;

View File

@ -32,18 +32,18 @@ struct Argument {
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++
void matlab_unwrap(std::ofstream& ofs, const std::string& matlabName);
void matlab_unwrap(std::ofstream& ofs, const std::string& matlabName) const;
};
/// Argument list
struct ArgumentList: public std::vector<Argument> {
std::vector<Argument> args; // why does it contain this?
std::string types();
std::string signature();
std::string names();
std::string types() const;
std::string signature() const;
std::string names() const;
// MATLAB code generation:
@ -52,7 +52,7 @@ struct ArgumentList: public std::vector<Argument> {
* @param ofs output stream
* @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

View File

@ -27,7 +27,7 @@ using namespace std;
using namespace wrap;
/* ************************************************************************* */
void Class::matlab_proxy(const string& classFile) {
void Class::matlab_proxy(const string& classFile) const {
// open destination classFile
ofstream ofs(classFile.c_str());
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) {
c.matlab_mfile (toolboxPath, qualifiedName());
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("::");
BOOST_FOREACH(Method m, methods) {
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("::");
BOOST_FOREACH(StaticMethod& m, static_methods) {
BOOST_FOREACH(const StaticMethod& m, static_methods) {
m.matlab_mfile (toolboxPath, qualifiedName());
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,
const string& toolboxPath,
const string& mexFlags)
{
const string& mexFlags) const {
string mex = "mex " + mexFlags + " ";
string matlabClassName = qualifiedName();
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
// $(MEX) $(mex_flags) new_Point2_.cpp
// new_Point2_dd.$(MEXENDING): new_Point2_dd.cpp

View File

@ -40,17 +40,17 @@ struct Class {
bool verbose_; ///< verbose flag
// 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,
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,
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,
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,
const std::string& toolboxPath,
const std::string& mexFlags); ///< emit make fragment for global make script
void makefile_fragment(std::ofstream& ofs); ///< emit makefile fragment
const std::string& mexFlags) const; ///< emit make fragment for global make script
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
};

View File

@ -26,13 +26,13 @@ using namespace std;
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();
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 = "
<< matlab_wrapper_name(className) << "(";
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);
@ -56,7 +56,7 @@ void Constructor::matlab_mfile(const string& toolboxPath, const string& qualifie
if(verbose_) cerr << "generating " << wrapperFile << endl;
// generate code
emit_header_comment(ofs, "%");
generateHeaderComment(ofs, "%");
ofs << "function result = " << matlabName << "(obj";
if (args.size()) ofs << "," << args.names();
ofs << ")" << endl;
@ -71,8 +71,7 @@ void Constructor::matlab_mfile(const string& toolboxPath, const string& qualifie
void Constructor::matlab_wrapper(const string& toolboxPath,
const string& cppClassName,
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);
// open destination wrapperFile
@ -82,7 +81,7 @@ void Constructor::matlab_wrapper(const string& toolboxPath,
if(verbose_) cerr << "generating " << wrapperFile << endl;
// generate code
emit_header_comment(ofs, "//");
generateHeaderComment(ofs, "//");
generateIncludes(ofs, name, includes);
generateUsingNamespace(ofs, using_namespaces);

View File

@ -42,21 +42,21 @@ struct Constructor {
// classFile is class proxy file, e.g., ../matlab/@Point2/Point2.m
/// wrapper name
std::string matlab_wrapper_name(const std::string& className);
std::string matlab_wrapper_name(const std::string& className) const;
/// 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
void matlab_mfile(const std::string& toolboxPath,
const std::string& qualifiedMatlabName);
const std::string& qualifiedMatlabName) const;
/// cpp wrapper
void matlab_wrapper(const std::string& toolboxPath,
const std::string& cppClassName,
const std::string& matlabClassName,
const std::vector<std::string>& using_namespaces,
const std::vector<std::string>& includes);
const std::vector<std::string>& includes) const;
};
} // \namespace wrap

View File

@ -26,7 +26,7 @@ using namespace std;
using namespace wrap;
/* ************************************************************************* */
void Method::matlab_mfile(const string& classPath) {
void Method::matlab_mfile(const string& classPath) const {
// open destination m-file
string wrapperFile = classPath + "/" + name + ".m";
@ -52,8 +52,7 @@ void Method::matlab_wrapper(const string& classPath,
const string& className,
const string& cppClassName,
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
string wrapperFile = classPath + "/" + name + ".cpp";
ofstream ofs(wrapperFile.c_str());
@ -63,7 +62,7 @@ void Method::matlab_wrapper(const string& classPath,
// generate code
// header
wrap::emit_header_comment(ofs, "//");
generateHeaderComment(ofs, "//");
generateIncludes(ofs, className, includes);
generateUsingNamespace(ofs, using_namespaces);

View File

@ -42,13 +42,13 @@ struct Method {
// MATLAB code generation
// 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,
const std::string& className,
const std::string& cppClassName,
const std::string& matlabClassname,
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

View File

@ -232,7 +232,7 @@ void verifyArguments(const vector<string>& validArgs, const vector<T>& vt) {
BOOST_FOREACH(const T& t, vt) {
BOOST_FOREACH(Argument arg, t.args) {
string fullType = arg.qualifiedType("::");
if(std::find(validArgs.begin(), validArgs.end(), fullType)
if(find(validArgs.begin(), validArgs.end(), fullType)
== validArgs.end())
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,
const string& mexExt,
const string& mexFlags)
{
const string& mexExt, const string& mexFlags) const {
string installCmd = "install -d " + toolboxPath;
system(installCmd.c_str());
@ -258,7 +256,7 @@ void Module::matlab_code(const string& toolboxPath,
if(!make_ofs) throw CantOpenFile(makeFile);
if (verbose) cerr << "generating " << matlabMakeFile << endl;
emit_header_comment(ofs,"%");
generateHeaderComment(ofs,"%");
ofs << "echo on" << endl << endl;
ofs << "toolboxpath = mfilename('fullpath');" << endl;
ofs << "delims = find(toolboxpath == '/');" << endl;
@ -267,13 +265,13 @@ void Module::matlab_code(const string& toolboxPath,
ofs << "addpath(toolboxpath);" << endl << endl;
if (verbose) cerr << "generating " << makeFile << endl;
emit_header_comment(make_ofs,"#");
generateHeaderComment(make_ofs,"#");
make_ofs << "\nMEX = mex\n";
make_ofs << "MEXENDING = " << mexExt << "\n";
make_ofs << "mex_flags = " << mexFlags << "\n\n";
//Dependency check list
std::vector<string> validArgs;
vector<string> validArgs;
validArgs.push_back("string");
validArgs.push_back("int");
validArgs.push_back("bool");

View File

@ -41,7 +41,7 @@ struct Module {
/// MATLAB code generation:
void matlab_code(const std::string& path,
const std::string& mexExt,
const std::string& mexFlags);
const std::string& mexFlags) const;
};
} // \namespace wrap

View File

@ -14,7 +14,7 @@ using namespace std;
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) {
string str = "pair< " +
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;
BOOST_FOREACH(const string& ns, namespaces1) result += ns + delim;
return result + type1;
}
/* ************************************************************************* */
string ReturnValue::qualifiedType2(const string& delim) {
string ReturnValue::qualifiedType2(const string& delim) const {
string result;
BOOST_FOREACH(const string& ns, namespaces2) result += ns + delim;
return result + type2;
}
/* ************************************************************************* */
void ReturnValue::wrap_result(std::ostream& ofs) {
void ReturnValue::wrap_result(ostream& ofs) const {
string cppType1 = qualifiedType1("::"), matlabType1 = qualifiedType1();
string cppType2 = qualifiedType2("::"), matlabType2 = qualifiedType2();

View File

@ -39,14 +39,14 @@ struct ReturnValue {
arg1, arg2, pair
} 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 qualifiedType2(const std::string& delim = "");
std::string qualifiedType1(const std::string& delim = "") const;
std::string qualifiedType2(const std::string& delim = "") const;
std::string matlab_returnType() const;
void wrap_result(std::ostream& ofs);
void wrap_result(std::ostream& ofs) const;
};

View File

@ -26,7 +26,7 @@ using namespace std;
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
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,
const string& matlabClassName, const string& cppClassName,
const vector<string>& using_namespaces,
const std::vector<std::string>& includes)
{
const vector<string>& includes) const {
// open destination wrapperFile
string full_name = matlabClassName + "_" + name;
string wrapperFile = toolboxPath + "/" + full_name + ".cpp";
@ -64,7 +63,7 @@ void StaticMethod::matlab_wrapper(const string& toolboxPath, const string& class
// generate code
// header
wrap::emit_header_comment(ofs, "//");
generateHeaderComment(ofs, "//");
generateIncludes(ofs, className, includes);
generateUsingNamespace(ofs, using_namespaces);

View File

@ -44,12 +44,12 @@ struct StaticMethod {
// NOTE: static functions are not inside the class, and
// 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,
const std::string& className, const std::string& matlabClassName,
const std::string& cppClassName,
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

View File

@ -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();
ofs << delimiter << " automatically generated by wrap on " << today << endl;
}

View File

@ -82,7 +82,7 @@ bool assert_equal(const std::string& expected, const std::string& actual);
/**
* 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
std::string maybe_shared_ptr(bool add, const std::string& type);