Added wrap components to "wrap" namespace, added options for installing wrap program

release/4.3a0
Alex Cunningham 2011-12-02 16:43:15 +00:00
parent 221a6ad877
commit 3050dc2dde
20 changed files with 110 additions and 24 deletions

View File

@ -145,6 +145,25 @@ AC_ARG_WITH([toolbox],
[toolbox=$prefix]) [toolbox=$prefix])
AC_SUBST([toolbox]) 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 \ AC_CONFIG_FILES([CppUnitLite/Makefile \
wrap/Makefile \ wrap/Makefile \
gtsam/3rdparty/Makefile \ gtsam/3rdparty/Makefile \

View File

@ -22,6 +22,7 @@
#include "Argument.h" #include "Argument.h"
using namespace std; using namespace std;
using namespace wrap;
/* ************************************************************************* */ /* ************************************************************************* */
void Argument::matlab_unwrap(ofstream& ofs, void Argument::matlab_unwrap(ofstream& ofs,

View File

@ -20,6 +20,8 @@
#include <string> #include <string>
#include <list> #include <list>
namespace wrap {
/// Argument class /// Argument class
struct Argument { struct Argument {
bool is_const, is_ref, is_ptr; bool is_const, is_ref, is_ptr;
@ -50,3 +52,5 @@ struct ArgumentList: public std::list<Argument> {
void matlab_unwrap(std::ofstream& ofs, int start = 0); // MATLAB to C++ void matlab_unwrap(std::ofstream& ofs, int start = 0); // MATLAB to C++
}; };
} // \namespace wrap

View File

@ -23,6 +23,7 @@
#include "utilities.h" #include "utilities.h"
using namespace std; using namespace std;
using namespace wrap;
/* ************************************************************************* */ /* ************************************************************************* */
void Class::matlab_proxy(const string& classFile) { void Class::matlab_proxy(const string& classFile) {

View File

@ -24,6 +24,8 @@
#include "Method.h" #include "Method.h"
#include "StaticMethod.h" #include "StaticMethod.h"
namespace wrap {
/// Class has name, constructors, methods /// Class has name, constructors, methods
struct Class { struct Class {
/// Constructor creates an empty class /// Constructor creates an empty class
@ -49,3 +51,5 @@ struct Class {
const std::string& mexFlags); ///< emit make fragment for global make script const std::string& mexFlags); ///< emit make fragment for global make script
}; };
} // \namespace wrap

View File

@ -23,6 +23,7 @@
#include "Constructor.h" #include "Constructor.h"
using namespace std; using namespace std;
using namespace wrap;
/* ************************************************************************* */ /* ************************************************************************* */
string Constructor::matlab_wrapper_name(const string& className) { 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; if(verbose_) cerr << "generating " << wrapperFile << endl;
// generate code // generate code
emit_header_comment(ofs, "%"); wrap::emit_header_comment(ofs, "%");
ofs << "function result = " << name << "(obj"; ofs << "function result = " << name << "(obj";
if (args.size()) ofs << "," << args.names(); if (args.size()) ofs << "," << args.names();
ofs << ")" << endl; ofs << ")" << endl;
@ -81,7 +82,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, "//"); wrap::emit_header_comment(ofs, "//");
ofs << "#include <wrap/matlab.h>" << endl; ofs << "#include <wrap/matlab.h>" << endl;
ofs << "#include <" << className << ".h>" << endl; ofs << "#include <" << className << ".h>" << endl;
if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl; if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl;

View File

@ -22,6 +22,8 @@
#include "Argument.h" #include "Argument.h"
namespace wrap {
// Constructor class // Constructor class
struct Constructor { struct Constructor {
@ -53,3 +55,5 @@ struct Constructor {
const std::string& className, const std::string& nameSpace); const std::string& className, const std::string& nameSpace);
}; };
} // \namespace wrap

View File

@ -9,15 +9,22 @@ AM_DEFAULT_SOURCE_EXT = .cpp
headers = headers =
sources = sources =
check_PROGRAMS = check_PROGRAMS =
noinst_PROGRAMS =
wrap_PROGRAMS =
wrapdir = $(pkgincludedir)/wrap
# disable all of matlab toolbox build by default # disable all of matlab toolbox build by default
if ENABLE_BUILD_TOOLBOX if ENABLE_BUILD_TOOLBOX
# Build a library from the core sources # Build a library from the core sources
sources += utilities.cpp Argument.cpp ReturnValue.cpp Constructor.cpp Method.cpp StaticMethod.cpp Class.cpp Module.cpp sources += utilities.cpp Argument.cpp ReturnValue.cpp Constructor.cpp Method.cpp StaticMethod.cpp Class.cpp Module.cpp
check_PROGRAMS += tests/testSpirit tests/testWrap check_PROGRAMS += tests/testSpirit tests/testWrap
noinst_PROGRAMS = wrap if ENABLE_INSTALL_WRAP
wrap_PROGRAMS += wrap
else
noinst_PROGRAMS += wrap
endif
#---------------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------------
# Create a libtool library that is not installed # 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 # Only install the header necessary for wrap interfaces to build with mex
headers += matlab.h headers += matlab.h
wrapdir = $(pkgincludedir)/wrap
wrap_HEADERS = $(headers) wrap_HEADERS = $(headers)
noinst_LTLIBRARIES = libwrap.la noinst_LTLIBRARIES = libwrap.la
libwrap_la_SOURCES = $(sources) 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" 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: all:
./wrap ${interfacePath} ${moduleName} ${toolboxpath} ${nameSpace} ${mexFlags} ./wrap ${interfacePath} ${moduleName} ${toolboxpath} ${nameSpace} ${mexFlags}
# install the headers and matlab toolbox wrap-install-bin: all
if ENABLE_INSTALL_MATLAB_TESTS install -d ${wrap} && \
install-exec-hook: all install ./wrap ${wrap}
install -d ${toolbox}/gtsam && \
cp -rf ../toolbox/* ${toolbox}/gtsam && \ wrap-install-matlab-tests: all
mkdir -p ${toolbox}/gtsam/tests && \ install -d ${toolbox}/gtsam/tests && \
cp -rf ../../tests/matlab/*.m ${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 else
install-exec-hook: all install-exec-hook: all
install -d ${toolbox}/gtsam && \ install -d ${toolbox}/gtsam && \
cp -rf ../toolbox/* ${toolbox}/gtsam/tests cp -rf ../toolbox/* ${toolbox}/gtsam/tests
endif endif
endif
# clean local toolbox dir # clean local toolbox dir
clean: clean:

View File

@ -23,6 +23,7 @@
#include "utilities.h" #include "utilities.h"
using namespace std; using namespace std;
using namespace wrap;
/* ************************************************************************* */ /* ************************************************************************* */
void Method::matlab_mfile(const string& classPath) { void Method::matlab_mfile(const string& classPath) {
@ -60,7 +61,7 @@ void Method::matlab_wrapper(const string& classPath,
// generate code // generate code
// header // header
emit_header_comment(ofs, "//"); wrap::emit_header_comment(ofs, "//");
ofs << "#include <wrap/matlab.h>\n"; ofs << "#include <wrap/matlab.h>\n";
ofs << "#include <" << className << ".h>\n"; ofs << "#include <" << className << ".h>\n";
if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl; if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl;

View File

@ -23,6 +23,8 @@
#include "Argument.h" #include "Argument.h"
#include "ReturnValue.h" #include "ReturnValue.h"
namespace wrap {
/// Method class /// Method class
struct Method { struct Method {
@ -47,3 +49,5 @@ struct Method {
const std::string& className, const std::string& nameSpace); ///< wrapper const std::string& className, const std::string& nameSpace); ///< wrapper
}; };
} // \namespace wrap

View File

@ -26,6 +26,7 @@
#include <fstream> #include <fstream>
using namespace std; using namespace std;
using namespace wrap;
using namespace BOOST_SPIRIT_CLASSIC_NS; using namespace BOOST_SPIRIT_CLASSIC_NS;
typedef rule<BOOST_SPIRIT_CLASSIC_NS::phrase_scanner_t> Rule; typedef rule<BOOST_SPIRIT_CLASSIC_NS::phrase_scanner_t> Rule;
@ -186,7 +187,7 @@ Module::Module(const string& interfacePath,
// read interface file // read interface file
string interfaceFile = interfacePath + "/" + moduleName + ".h"; string interfaceFile = interfacePath + "/" + moduleName + ".h";
string contents = file_contents(interfaceFile); string contents = wrap::file_contents(interfaceFile);
// and parse contents // and parse contents
parse_info<const char*> info = parse(contents.c_str(), module_p, space_p); parse_info<const char*> 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(!ofs) throw CantOpenFile(makeFile);
if (verbose_) cerr << "generating " << makeFile << endl; if (verbose_) cerr << "generating " << makeFile << endl;
emit_header_comment(ofs,"%"); wrap::emit_header_comment(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;

View File

@ -22,6 +22,8 @@
#include "Class.h" #include "Class.h"
namespace wrap {
/** /**
* A module just has a name and a list of classes * A module just has a name and a list of classes
*/ */
@ -41,3 +43,4 @@ struct Module {
const std::string& mexFlags); const std::string& mexFlags);
}; };
} // \namespace wrap

View File

@ -9,16 +9,17 @@
#include "utilities.h" #include "utilities.h"
using namespace std; using namespace std;
using namespace wrap;
/* ************************************************************************* */ /* ************************************************************************* */
string ReturnValue::return_type(bool add_ptr, pairing p) { string ReturnValue::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_) + ", " + wrap::maybe_shared_ptr(add_ptr && returns_ptr_, returns_) + ", " +
maybe_shared_ptr(add_ptr && returns_ptr_, returns2_) + " >"; wrap::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 wrap::maybe_shared_ptr(add_ptr && returns_ptr_, (p==arg2)? returns2_ : returns_);
} }
/* ************************************************************************* */ /* ************************************************************************* */

View File

@ -11,6 +11,8 @@
#pragma once #pragma once
namespace wrap {
struct ReturnValue { struct ReturnValue {
ReturnValue(bool verbose = true) ReturnValue(bool verbose = true)
@ -32,3 +34,5 @@ struct ReturnValue {
void wrap_result(std::ostream& ofs); void wrap_result(std::ostream& ofs);
}; };
} // \namespace wrap

View File

@ -23,6 +23,7 @@
#include "utilities.h" #include "utilities.h"
using namespace std; 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) {
@ -61,7 +62,7 @@ void StaticMethod::matlab_wrapper(const string& toolboxPath,
// generate code // generate code
// header // header
emit_header_comment(ofs, "//"); wrap::emit_header_comment(ofs, "//");
ofs << "#include <wrap/matlab.h>\n"; ofs << "#include <wrap/matlab.h>\n";
ofs << "#include <" << className << ".h>\n"; ofs << "#include <" << className << ".h>\n";
if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl; if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl;

View File

@ -24,6 +24,8 @@
#include "Argument.h" #include "Argument.h"
#include "ReturnValue.h" #include "ReturnValue.h"
namespace wrap {
/// StaticMethod class /// StaticMethod class
struct StaticMethod { struct StaticMethod {
@ -47,3 +49,5 @@ struct StaticMethod {
const std::string& className, const std::string& nameSpace); ///< wrapper const std::string& className, const std::string& nameSpace); ///< wrapper
}; };
} // \namespace wrap

View File

@ -24,6 +24,7 @@
#include <wrap/Module.h> #include <wrap/Module.h>
using namespace std; using namespace std;
using namespace wrap;
static bool verbose = false; static bool verbose = false;
#ifdef TOPSRCDIR #ifdef TOPSRCDIR
static string topdir = TOPSRCDIR; static string topdir = TOPSRCDIR;

View File

@ -21,6 +21,8 @@
#include "utilities.h" #include "utilities.h"
namespace wrap {
using namespace std; using namespace std;
using namespace boost::gregorian; 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) { bool files_equal(const string& expected, const string& actual, bool skipheader) {
try { try {
string expected_contents = file_contents(expected, skipheader); string expected_contents = wrap::file_contents(expected, skipheader);
string actual_contents = file_contents(actual, skipheader); string actual_contents = wrap::file_contents(actual, skipheader);
bool equal = actual_contents == expected_contents; bool equal = actual_contents == expected_contents;
if (!equal) { if (!equal) {
stringstream command; stringstream command;
@ -84,3 +86,5 @@ std::string maybe_shared_ptr(bool add, const std::string& type) {
} }
/* ************************************************************************* */ /* ************************************************************************* */
} // \namespace wrap

View File

@ -19,6 +19,8 @@
#include <exception> #include <exception>
#include <sstream> #include <sstream>
namespace wrap {
class CantOpenFile : public std::exception { class CantOpenFile : public std::exception {
private: private:
std::string filename_; 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 // 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);
} // \namespace wrap

View File

@ -10,7 +10,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
/** /**
* @file wrap.ccp * @file wrap.cpp
* @brief wraps functions * @brief wraps functions
* @author Frank Dellaert * @author Frank Dellaert
**/ **/
@ -38,7 +38,7 @@ void generate_matlab_toolbox(const string& interfacePath,
{ {
// Parse interface file into class object // Parse interface file into class object
// This recursively creates Class objects, Method objects, etc... // This recursively creates Class objects, Method objects, etc...
Module module(interfacePath, moduleName, true); wrap::Module module(interfacePath, moduleName, true);
// Then emit MATLAB code // Then emit MATLAB code
module.matlab_code(toolboxPath,nameSpace,mexFlags); module.matlab_code(toolboxPath,nameSpace,mexFlags);