From 3050dc2dde47473153a0760e5cf05fd05ae47eaf Mon Sep 17 00:00:00 2001 From: Alex Cunningham Date: Fri, 2 Dec 2011 16:43:15 +0000 Subject: [PATCH] Added wrap components to "wrap" namespace, added options for installing wrap program --- configure.ac | 19 +++++++++++++++++ wrap/Argument.cpp | 1 + wrap/Argument.h | 4 ++++ wrap/Class.cpp | 1 + wrap/Class.h | 4 ++++ wrap/Constructor.cpp | 5 +++-- wrap/Constructor.h | 4 ++++ wrap/Makefile.am | 46 +++++++++++++++++++++++++++++++---------- wrap/Method.cpp | 3 ++- wrap/Method.h | 4 ++++ wrap/Module.cpp | 5 +++-- wrap/Module.h | 3 +++ wrap/ReturnValue.cpp | 7 ++++--- wrap/ReturnValue.h | 4 ++++ wrap/StaticMethod.cpp | 3 ++- wrap/StaticMethod.h | 4 ++++ wrap/tests/testWrap.cpp | 1 + wrap/utilities.cpp | 8 +++++-- wrap/utilities.h | 4 ++++ wrap/wrap.cpp | 4 ++-- 20 files changed, 110 insertions(+), 24 deletions(-) diff --git a/configure.ac b/configure.ac index b1dc2fc06..fecc7f5f9 100644 --- a/configure.ac +++ b/configure.ac @@ -145,6 +145,25 @@ AC_ARG_WITH([toolbox], [toolbox=$prefix]) AC_SUBST([toolbox]) +# enable installation of the wrap utility +AC_ARG_ENABLE([install_wrap], + [ --enable-install-wrap Enable installation of the wrap tool for generating matlab interfaces], + [case "${enableval}" in + yes) install_wrap=true ;; + no) install_wrap=false ;; + *) AC_MSG_ERROR([bad value ${enableval} for --enable-install-wrap]) ;; + esac],[install_wrap=false]) + +AM_CONDITIONAL([ENABLE_INSTALL_WRAP], [test x$install_wrap = xtrue]) + +# wrap install path: optional flag to change location of wrap, defaults to install prefix/bin +AC_ARG_WITH([wrap], + [AS_HELP_STRING([--with-wrap], + [specify the wrap directory for installation])], + [wrap=$withval], + [wrap=$prefix/bin]) +AC_SUBST([wrap]) + AC_CONFIG_FILES([CppUnitLite/Makefile \ wrap/Makefile \ gtsam/3rdparty/Makefile \ diff --git a/wrap/Argument.cpp b/wrap/Argument.cpp index e0d01ab63..c196212ef 100644 --- a/wrap/Argument.cpp +++ b/wrap/Argument.cpp @@ -22,6 +22,7 @@ #include "Argument.h" using namespace std; +using namespace wrap; /* ************************************************************************* */ void Argument::matlab_unwrap(ofstream& ofs, diff --git a/wrap/Argument.h b/wrap/Argument.h index 2248e1790..3ebfa505e 100644 --- a/wrap/Argument.h +++ b/wrap/Argument.h @@ -20,6 +20,8 @@ #include #include +namespace wrap { + /// Argument class struct Argument { bool is_const, is_ref, is_ptr; @@ -50,3 +52,5 @@ struct ArgumentList: public std::list { void matlab_unwrap(std::ofstream& ofs, int start = 0); // MATLAB to C++ }; +} // \namespace wrap + diff --git a/wrap/Class.cpp b/wrap/Class.cpp index 628e0ea83..580d898c4 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -23,6 +23,7 @@ #include "utilities.h" using namespace std; +using namespace wrap; /* ************************************************************************* */ void Class::matlab_proxy(const string& classFile) { diff --git a/wrap/Class.h b/wrap/Class.h index 68ff4e1ca..226872748 100644 --- a/wrap/Class.h +++ b/wrap/Class.h @@ -24,6 +24,8 @@ #include "Method.h" #include "StaticMethod.h" +namespace wrap { + /// Class has name, constructors, methods struct Class { /// Constructor creates an empty class @@ -49,3 +51,5 @@ struct Class { const std::string& mexFlags); ///< emit make fragment for global make script }; +} // \namespace wrap + diff --git a/wrap/Constructor.cpp b/wrap/Constructor.cpp index 9caf4793f..346fc45da 100644 --- a/wrap/Constructor.cpp +++ b/wrap/Constructor.cpp @@ -23,6 +23,7 @@ #include "Constructor.h" using namespace std; +using namespace wrap; /* ************************************************************************* */ string Constructor::matlab_wrapper_name(const string& className) { @@ -55,7 +56,7 @@ void Constructor::matlab_mfile(const string& toolboxPath, const string& classNam if(verbose_) cerr << "generating " << wrapperFile << endl; // generate code - emit_header_comment(ofs, "%"); + wrap::emit_header_comment(ofs, "%"); ofs << "function result = " << name << "(obj"; if (args.size()) ofs << "," << args.names(); ofs << ")" << endl; @@ -81,7 +82,7 @@ void Constructor::matlab_wrapper(const string& toolboxPath, if(verbose_) cerr << "generating " << wrapperFile << endl; // generate code - emit_header_comment(ofs, "//"); + wrap::emit_header_comment(ofs, "//"); ofs << "#include " << endl; ofs << "#include <" << className << ".h>" << endl; if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl; diff --git a/wrap/Constructor.h b/wrap/Constructor.h index 340ac0fd2..93f9b145b 100644 --- a/wrap/Constructor.h +++ b/wrap/Constructor.h @@ -22,6 +22,8 @@ #include "Argument.h" +namespace wrap { + // Constructor class struct Constructor { @@ -53,3 +55,5 @@ struct Constructor { const std::string& className, const std::string& nameSpace); }; +} // \namespace wrap + diff --git a/wrap/Makefile.am b/wrap/Makefile.am index 43573033c..5783ec433 100644 --- a/wrap/Makefile.am +++ b/wrap/Makefile.am @@ -9,15 +9,22 @@ AM_DEFAULT_SOURCE_EXT = .cpp headers = sources = -check_PROGRAMS = +check_PROGRAMS = +noinst_PROGRAMS = +wrap_PROGRAMS = +wrapdir = $(pkgincludedir)/wrap # disable all of matlab toolbox build by default if ENABLE_BUILD_TOOLBOX # Build a library from the core sources sources += utilities.cpp Argument.cpp ReturnValue.cpp Constructor.cpp Method.cpp StaticMethod.cpp Class.cpp Module.cpp -check_PROGRAMS += tests/testSpirit tests/testWrap -noinst_PROGRAMS = wrap +check_PROGRAMS += tests/testSpirit tests/testWrap +if ENABLE_INSTALL_WRAP +wrap_PROGRAMS += wrap +else +noinst_PROGRAMS += wrap +endif #---------------------------------------------------------------------------------------------------- # Create a libtool library that is not installed @@ -25,7 +32,6 @@ noinst_PROGRAMS = wrap #---------------------------------------------------------------------------------------------------- # Only install the header necessary for wrap interfaces to build with mex headers += matlab.h -wrapdir = $(pkgincludedir)/wrap wrap_HEADERS = $(headers) noinst_LTLIBRARIES = libwrap.la libwrap_la_SOURCES = $(sources) @@ -55,19 +61,37 @@ nameSpace = "gtsam" mexFlags = "${BOOST_CPPFLAGS} -DUNSAFE_WRAP -I${prefix}/include -I${prefix}/include/gtsam -I${prefix}/include/gtsam/base -I${prefix}/include/gtsam/geometry -I${prefix}/include/gtsam/linear -I${prefix}/include/gtsam/nonlinear -I${prefix}/include/gtsam/slam -L${exec_prefix}/lib -lgtsam" all: ./wrap ${interfacePath} ${moduleName} ${toolboxpath} ${nameSpace} ${mexFlags} - -# install the headers and matlab toolbox -if ENABLE_INSTALL_MATLAB_TESTS -install-exec-hook: all - install -d ${toolbox}/gtsam && \ - cp -rf ../toolbox/* ${toolbox}/gtsam && \ - mkdir -p ${toolbox}/gtsam/tests && \ + +wrap-install-bin: all + install -d ${wrap} && \ + install ./wrap ${wrap} + +wrap-install-matlab-tests: all + install -d ${toolbox}/gtsam/tests && \ cp -rf ../../tests/matlab/*.m ${toolbox}/gtsam/tests + +# install the headers and matlab toolbox +if ENABLE_INSTALL_WRAP +if ENABLE_INSTALL_MATLAB_TESTS +install-exec-hook: wrap-install-bin wrap-install-matlab-tests + install -d ${toolbox}/gtsam && \ + cp -rf ../toolbox/* ${toolbox}/gtsam +else +install-exec-hook: wrap-install-bin + install -d ${toolbox}/gtsam && \ + cp -rf ../toolbox/* ${toolbox}/gtsam/tests +endif +else +if ENABLE_INSTALL_MATLAB_TESTS +install-exec-hook: wrap-install-matlab-tests + install -d ${toolbox}/gtsam && \ + cp -rf ../toolbox/* ${toolbox}/gtsam else install-exec-hook: all install -d ${toolbox}/gtsam && \ cp -rf ../toolbox/* ${toolbox}/gtsam/tests endif +endif # clean local toolbox dir clean: diff --git a/wrap/Method.cpp b/wrap/Method.cpp index 0b3833437..9319f1036 100644 --- a/wrap/Method.cpp +++ b/wrap/Method.cpp @@ -23,6 +23,7 @@ #include "utilities.h" using namespace std; +using namespace wrap; /* ************************************************************************* */ void Method::matlab_mfile(const string& classPath) { @@ -60,7 +61,7 @@ void Method::matlab_wrapper(const string& classPath, // generate code // header - emit_header_comment(ofs, "//"); + wrap::emit_header_comment(ofs, "//"); ofs << "#include \n"; ofs << "#include <" << className << ".h>\n"; if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl; diff --git a/wrap/Method.h b/wrap/Method.h index edf98d717..9d3860ff1 100644 --- a/wrap/Method.h +++ b/wrap/Method.h @@ -23,6 +23,8 @@ #include "Argument.h" #include "ReturnValue.h" +namespace wrap { + /// Method class struct Method { @@ -47,3 +49,5 @@ struct Method { const std::string& className, const std::string& nameSpace); ///< wrapper }; +} // \namespace wrap + diff --git a/wrap/Module.cpp b/wrap/Module.cpp index 47a1b0b50..230453979 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -26,6 +26,7 @@ #include using namespace std; +using namespace wrap; using namespace BOOST_SPIRIT_CLASSIC_NS; typedef rule Rule; @@ -186,7 +187,7 @@ Module::Module(const string& interfacePath, // read interface file string interfaceFile = interfacePath + "/" + moduleName + ".h"; - string contents = file_contents(interfaceFile); + string contents = wrap::file_contents(interfaceFile); // and parse contents parse_info info = parse(contents.c_str(), module_p, space_p); @@ -211,7 +212,7 @@ void Module::matlab_code(const string& toolboxPath, if(!ofs) throw CantOpenFile(makeFile); if (verbose_) cerr << "generating " << makeFile << endl; - emit_header_comment(ofs,"%"); + wrap::emit_header_comment(ofs,"%"); ofs << "echo on" << endl << endl; ofs << "toolboxpath = mfilename('fullpath');" << endl; ofs << "delims = find(toolboxpath == '/');" << endl; diff --git a/wrap/Module.h b/wrap/Module.h index 0227e86d9..8175bf719 100644 --- a/wrap/Module.h +++ b/wrap/Module.h @@ -22,6 +22,8 @@ #include "Class.h" +namespace wrap { + /** * A module just has a name and a list of classes */ @@ -41,3 +43,4 @@ struct Module { const std::string& mexFlags); }; +} // \namespace wrap diff --git a/wrap/ReturnValue.cpp b/wrap/ReturnValue.cpp index f6307954e..7ffd3b372 100644 --- a/wrap/ReturnValue.cpp +++ b/wrap/ReturnValue.cpp @@ -9,16 +9,17 @@ #include "utilities.h" using namespace std; +using namespace wrap; /* ************************************************************************* */ string ReturnValue::return_type(bool add_ptr, pairing p) { if (p==pair && returns_pair_) { string str = "pair< " + - maybe_shared_ptr(add_ptr && returns_ptr_, returns_) + ", " + - maybe_shared_ptr(add_ptr && returns_ptr_, returns2_) + " >"; + wrap::maybe_shared_ptr(add_ptr && returns_ptr_, returns_) + ", " + + wrap::maybe_shared_ptr(add_ptr && returns_ptr_, returns2_) + " >"; return str; } else - return maybe_shared_ptr(add_ptr && returns_ptr_, (p==arg2)? returns2_ : returns_); + return wrap::maybe_shared_ptr(add_ptr && returns_ptr_, (p==arg2)? returns2_ : returns_); } /* ************************************************************************* */ diff --git a/wrap/ReturnValue.h b/wrap/ReturnValue.h index 336a415ac..02382aebb 100644 --- a/wrap/ReturnValue.h +++ b/wrap/ReturnValue.h @@ -11,6 +11,8 @@ #pragma once +namespace wrap { + struct ReturnValue { ReturnValue(bool verbose = true) @@ -32,3 +34,5 @@ struct ReturnValue { void wrap_result(std::ostream& ofs); }; + +} // \namespace wrap diff --git a/wrap/StaticMethod.cpp b/wrap/StaticMethod.cpp index 0a712219e..3d380c1da 100644 --- a/wrap/StaticMethod.cpp +++ b/wrap/StaticMethod.cpp @@ -23,6 +23,7 @@ #include "utilities.h" using namespace std; +using namespace wrap; /* ************************************************************************* */ void StaticMethod::matlab_mfile(const string& toolboxPath, const string& className) { @@ -61,7 +62,7 @@ void StaticMethod::matlab_wrapper(const string& toolboxPath, // generate code // header - emit_header_comment(ofs, "//"); + wrap::emit_header_comment(ofs, "//"); ofs << "#include \n"; ofs << "#include <" << className << ".h>\n"; if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl; diff --git a/wrap/StaticMethod.h b/wrap/StaticMethod.h index 11caa2eb0..0366b64ef 100644 --- a/wrap/StaticMethod.h +++ b/wrap/StaticMethod.h @@ -24,6 +24,8 @@ #include "Argument.h" #include "ReturnValue.h" +namespace wrap { + /// StaticMethod class struct StaticMethod { @@ -47,3 +49,5 @@ struct StaticMethod { const std::string& className, const std::string& nameSpace); ///< wrapper }; +} // \namespace wrap + diff --git a/wrap/tests/testWrap.cpp b/wrap/tests/testWrap.cpp index 6ff90a8c1..98af93425 100644 --- a/wrap/tests/testWrap.cpp +++ b/wrap/tests/testWrap.cpp @@ -24,6 +24,7 @@ #include using namespace std; +using namespace wrap; static bool verbose = false; #ifdef TOPSRCDIR static string topdir = TOPSRCDIR; diff --git a/wrap/utilities.cpp b/wrap/utilities.cpp index e00956536..8a30ed3bc 100644 --- a/wrap/utilities.cpp +++ b/wrap/utilities.cpp @@ -21,6 +21,8 @@ #include "utilities.h" +namespace wrap { + using namespace std; using namespace boost::gregorian; @@ -52,8 +54,8 @@ bool assert_equal(const std::string& expected, const std::string& actual) { /* ************************************************************************* */ bool files_equal(const string& expected, const string& actual, bool skipheader) { try { - string expected_contents = file_contents(expected, skipheader); - string actual_contents = file_contents(actual, skipheader); + string expected_contents = wrap::file_contents(expected, skipheader); + string actual_contents = wrap::file_contents(actual, skipheader); bool equal = actual_contents == expected_contents; if (!equal) { stringstream command; @@ -84,3 +86,5 @@ std::string maybe_shared_ptr(bool add, const std::string& type) { } /* ************************************************************************* */ + +} // \namespace wrap diff --git a/wrap/utilities.h b/wrap/utilities.h index eba80c57b..ee636b58c 100644 --- a/wrap/utilities.h +++ b/wrap/utilities.h @@ -19,6 +19,8 @@ #include #include +namespace wrap { + class CantOpenFile : public std::exception { private: std::string filename_; @@ -66,3 +68,5 @@ void emit_header_comment(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); + +} // \namespace wrap diff --git a/wrap/wrap.cpp b/wrap/wrap.cpp index 51ba636c3..27dbd9237 100644 --- a/wrap/wrap.cpp +++ b/wrap/wrap.cpp @@ -10,7 +10,7 @@ * -------------------------------------------------------------------------- */ /** - * @file wrap.ccp + * @file wrap.cpp * @brief wraps functions * @author Frank Dellaert **/ @@ -38,7 +38,7 @@ void generate_matlab_toolbox(const string& interfacePath, { // Parse interface file into class object // This recursively creates Class objects, Method objects, etc... - Module module(interfacePath, moduleName, true); + wrap::Module module(interfacePath, moduleName, true); // Then emit MATLAB code module.matlab_code(toolboxPath,nameSpace,mexFlags);