diff --git a/.cproject b/.cproject index 05b53a07a..35f7946a4 100644 --- a/.cproject +++ b/.cproject @@ -36,6 +36,9 @@ diff --git a/wrap/Argument.cpp b/wrap/Argument.cpp index e01da3db3..1610f98aa 100644 --- a/wrap/Argument.cpp +++ b/wrap/Argument.cpp @@ -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; diff --git a/wrap/Argument.h b/wrap/Argument.h index 07c11a5cc..cb5b1b8c8 100644 --- a/wrap/Argument.h +++ b/wrap/Argument.h @@ -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 { std::vector 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 { * @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 diff --git a/wrap/Class.cpp b/wrap/Class.cpp index 82245bd26..47e01f00b 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -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& using_namespaces) { +void Class::matlab_constructors(const string& toolboxPath, const vector& 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& } /* ************************************************************************* */ -void Class::matlab_methods(const string& classPath, const vector& using_namespaces) { +void Class::matlab_methods(const string& classPath, const vector& 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& using_ } /* ************************************************************************* */ -void Class::matlab_static_methods(const string& toolboxPath, const vector& using_namespaces) { +void Class::matlab_static_methods(const string& toolboxPath, const vector& 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& using_namespaces); ///< emit constructor wrappers + const std::vector& using_namespaces) const; ///< emit constructor wrappers void matlab_methods(const std::string& classPath, - const std::vector& using_namespaces); ///< emit method wrappers + const std::vector& using_namespaces) const; ///< emit method wrappers void matlab_static_methods(const std::string& classPath, - const std::vector& using_namespaces); ///< emit static method wrappers + const std::vector& 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 }; diff --git a/wrap/Constructor.cpp b/wrap/Constructor.cpp index 04a873547..a822f722f 100644 --- a/wrap/Constructor.cpp +++ b/wrap/Constructor.cpp @@ -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& using_namespaces, const vector& includes) -{ + const vector& using_namespaces, const vector& 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); diff --git a/wrap/Constructor.h b/wrap/Constructor.h index 5409ed1f6..b9a44e2cc 100644 --- a/wrap/Constructor.h +++ b/wrap/Constructor.h @@ -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& using_namespaces, - const std::vector& includes); + const std::vector& includes) const; }; } // \namespace wrap diff --git a/wrap/Method.cpp b/wrap/Method.cpp index b9f10a9d4..0d9ba98e2 100644 --- a/wrap/Method.cpp +++ b/wrap/Method.cpp @@ -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& using_namespaces, const std::vector& includes) -{ + const vector& using_namespaces, const std::vector& 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); diff --git a/wrap/Method.h b/wrap/Method.h index 57bd1c043..bcfac82e3 100644 --- a/wrap/Method.h +++ b/wrap/Method.h @@ -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& using_namespaces, - const std::vector& includes); ///< cpp wrapper + const std::vector& includes) const; ///< cpp wrapper }; } // \namespace wrap diff --git a/wrap/Module.cpp b/wrap/Module.cpp index 2fd8c9747..120b89f10 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -232,7 +232,7 @@ void verifyArguments(const vector& validArgs, const vector& 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& validArgs, const vector& 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 validArgs; + vector validArgs; validArgs.push_back("string"); validArgs.push_back("int"); validArgs.push_back("bool"); diff --git a/wrap/Module.h b/wrap/Module.h index 3c294f380..ec057b644 100644 --- a/wrap/Module.h +++ b/wrap/Module.h @@ -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 diff --git a/wrap/ReturnValue.cpp b/wrap/ReturnValue.cpp index c10c173d7..38d85d074 100644 --- a/wrap/ReturnValue.cpp +++ b/wrap/ReturnValue.cpp @@ -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(); diff --git a/wrap/ReturnValue.h b/wrap/ReturnValue.h index ba606ad9c..eb2406d80 100644 --- a/wrap/ReturnValue.h +++ b/wrap/ReturnValue.h @@ -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; }; diff --git a/wrap/StaticMethod.cpp b/wrap/StaticMethod.cpp index 02a2aaf76..ff4d31592 100644 --- a/wrap/StaticMethod.cpp +++ b/wrap/StaticMethod.cpp @@ -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& using_namespaces, - const std::vector& includes) -{ + const vector& 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); diff --git a/wrap/StaticMethod.h b/wrap/StaticMethod.h index 429e24183..f9cc14af7 100644 --- a/wrap/StaticMethod.h +++ b/wrap/StaticMethod.h @@ -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& using_namespaces, - const std::vector& includes); ///< cpp wrapper + const std::vector& includes) const; ///< cpp wrapper }; } // \namespace wrap diff --git a/wrap/utilities.cpp b/wrap/utilities.cpp index 6877b29c2..ebf1ad020 100644 --- a/wrap/utilities.cpp +++ b/wrap/utilities.cpp @@ -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; } diff --git a/wrap/utilities.h b/wrap/utilities.h index f31dd7fd3..3837c2b95 100644 --- a/wrap/utilities.h +++ b/wrap/utilities.h @@ -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);