Added wrap components to "wrap" namespace, added options for installing wrap program
parent
221a6ad877
commit
3050dc2dde
19
configure.ac
19
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 \
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "Argument.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace wrap;
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Argument::matlab_unwrap(ofstream& ofs,
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include <string>
|
||||
#include <list>
|
||||
|
||||
namespace wrap {
|
||||
|
||||
/// Argument class
|
||||
struct Argument {
|
||||
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++
|
||||
};
|
||||
|
||||
} // \namespace wrap
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "utilities.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace wrap;
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Class::matlab_proxy(const string& classFile) {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 <wrap/matlab.h>" << endl;
|
||||
ofs << "#include <" << className << ".h>" << endl;
|
||||
if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 <wrap/matlab.h>\n";
|
||||
ofs << "#include <" << className << ".h>\n";
|
||||
if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
using namespace wrap;
|
||||
using namespace BOOST_SPIRIT_CLASSIC_NS;
|
||||
|
||||
typedef rule<BOOST_SPIRIT_CLASSIC_NS::phrase_scanner_t> 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<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 (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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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_);
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <wrap/matlab.h>\n";
|
||||
ofs << "#include <" << className << ".h>\n";
|
||||
if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <wrap/Module.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace wrap;
|
||||
static bool verbose = false;
|
||||
#ifdef TOPSRCDIR
|
||||
static string topdir = TOPSRCDIR;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include <exception>
|
||||
#include <sstream>
|
||||
|
||||
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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue