Changed namespace mechanism in wrap to "using namespace gtsam;" inside gtsam.h

release/4.3a0
Alex Cunningham 2011-12-09 20:29:47 +00:00
parent 4e5a80aa56
commit 06dbc2b650
50 changed files with 170 additions and 92 deletions

View File

@ -47,6 +47,9 @@
* - TODO: Handle Rot3M conversions to quaternions
*/
// Everything is in the gtsam namespace, so we avoid copying everything in
using namespace gtsam;
class Point2 {
Point2();
Point2(double x, double y);

View File

@ -57,28 +57,28 @@ void Class::matlab_proxy(const string& classFile) {
}
/* ************************************************************************* */
void Class::matlab_constructors(const string& toolboxPath,const string& nameSpace) {
void Class::matlab_constructors(const string& toolboxPath, const vector<string>& using_namespaces) {
BOOST_FOREACH(Constructor c, constructors) {
c.matlab_mfile (toolboxPath, qualifiedName());
c.matlab_wrapper(toolboxPath, qualifiedName("::"), qualifiedName(), nameSpace, includes);
c.matlab_wrapper(toolboxPath, qualifiedName("::"), qualifiedName(), using_namespaces, includes);
}
}
/* ************************************************************************* */
void Class::matlab_methods(const string& classPath, const string& nameSpace) {
void Class::matlab_methods(const string& classPath, const vector<string>& using_namespaces) {
string matlabName = qualifiedName(), cppName = qualifiedName("::");
BOOST_FOREACH(Method m, methods) {
m.matlab_mfile (classPath);
m.matlab_wrapper(classPath, name, cppName, matlabName, nameSpace, includes);
m.matlab_wrapper(classPath, name, cppName, matlabName, using_namespaces, includes);
}
}
/* ************************************************************************* */
void Class::matlab_static_methods(const string& toolboxPath, const string& nameSpace) {
void Class::matlab_static_methods(const string& toolboxPath, const vector<string>& using_namespaces) {
string matlabName = qualifiedName(), cppName = qualifiedName("::");
BOOST_FOREACH(StaticMethod& m, static_methods) {
m.matlab_mfile (toolboxPath, qualifiedName());
m.matlab_wrapper(toolboxPath, name, matlabName, cppName, nameSpace, includes);
m.matlab_wrapper(toolboxPath, name, matlabName, cppName, using_namespaces, includes);
}
}

View File

@ -42,11 +42,11 @@ struct Class {
// 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_constructors(const std::string& toolboxPath,
const std::string& nameSpace); ///< emit constructor wrappers
const std::vector<std::string>& using_namespaces); ///< emit constructor wrappers
void matlab_methods(const std::string& classPath,
const std::string& nameSpace); ///< emit method wrappers
const std::vector<std::string>& using_namespaces); ///< emit method wrappers
void matlab_static_methods(const std::string& classPath,
const std::string& nameSpace); ///< emit static method wrappers
const std::vector<std::string>& using_namespaces); ///< 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

View File

@ -71,9 +71,8 @@ void Constructor::matlab_mfile(const string& toolboxPath, const string& qualifie
void Constructor::matlab_wrapper(const string& toolboxPath,
const string& cppClassName,
const string& matlabClassName,
const string& nameSpace, const vector<string>& includes)
const vector<string>& using_namespaces, const vector<string>& includes)
{
string matlabName = matlab_wrapper_name(matlabClassName);
// open destination wrapperFile
@ -84,14 +83,9 @@ void Constructor::matlab_wrapper(const string& toolboxPath,
// generate code
emit_header_comment(ofs, "//");
ofs << "#include <wrap/matlab.h>" << endl;
if (includes.empty()) // add a default include
ofs << "#include <" << name << ".h>" << endl;
else {
BOOST_FOREACH(const string& s, includes)
ofs << "#include <" << s << ">" << endl;
}
if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl;
generateIncludes(ofs, name, includes);
generateUsingNamespace(ofs, using_namespaces);
ofs << "void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])" << endl;
ofs << "{" << endl;
ofs << " checkArguments(\"" << matlabName << "\",nargout,nargin," << args.size() << ");" << endl;

View File

@ -55,7 +55,8 @@ struct Constructor {
void matlab_wrapper(const std::string& toolboxPath,
const std::string& cppClassName,
const std::string& matlabClassName,
const std::string& nameSpace, const std::vector<std::string>& includes);
const std::vector<std::string>& using_namespaces,
const std::vector<std::string>& includes);
};
} // \namespace wrap

View File

@ -57,7 +57,6 @@ LDADD = libwrap.la ../CppUnitLite/libCppUnitLite.a
interfacePath = $(top_srcdir)
moduleName = gtsam
toolboxpath = ../toolbox
nameSpace = "gtsam"
# Set flags to pass to mex
mexFlags =
@ -87,7 +86,7 @@ endif # Linux
all: generate_toolbox
generate_toolbox: $(top_srcdir)/gtsam.h
./wrap ${mexextension} ${interfacePath} ${moduleName} ${toolboxpath} ${nameSpace} ${mexFlags}
./wrap ${mexextension} ${interfacePath} ${moduleName} ${toolboxpath} ${mexFlags}
source_mode = -m 644

View File

@ -52,7 +52,7 @@ void Method::matlab_wrapper(const string& classPath,
const string& className,
const string& cppClassName,
const string& matlabClassName,
const string& nameSpace, const std::vector<std::string>& includes)
const vector<string>& using_namespaces, const std::vector<std::string>& includes)
{
// open destination wrapperFile
string wrapperFile = classPath + "/" + name + ".cpp";
@ -64,14 +64,8 @@ void Method::matlab_wrapper(const string& classPath,
// header
wrap::emit_header_comment(ofs, "//");
ofs << "#include <wrap/matlab.h>\n";
if (includes.empty()) // add a default include
ofs << "#include <" << className << ".h>" << endl;
else {
BOOST_FOREACH(const string& s, includes)
ofs << "#include <" << s << ">" << endl;
}
if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl;
generateIncludes(ofs, className, includes);
generateUsingNamespace(ofs, using_namespaces);
// call
ofs << "void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";

View File

@ -46,7 +46,8 @@ struct Method {
void matlab_wrapper(const std::string& classPath,
const std::string& className,
const std::string& cppClassName,
const std::string& matlabClassname,const std::string& nameSpace,
const std::string& matlabClassname,
const std::vector<std::string>& using_namespaces,
const std::vector<std::string>& includes); ///< cpp wrapper
};

View File

@ -184,7 +184,10 @@ Module::Module(const string& interfacePath,
str_p("}///\\namespace") >> !namespace_name_p // end namespace, avoid confusion with classes
[pop_a(namespaces)];
Rule module_content_p = comments_p | class_p | namespace_def_p ;
Rule using_namespace_p = str_p("using") >> str_p("namespace")
>> namespace_name_p[push_back_a(using_namespaces)] >> ch_p(';');
Rule module_content_p = comments_p | using_namespace_p | class_p | namespace_def_p ;
Rule module_p = *module_content_p >> !end_p;
@ -238,7 +241,6 @@ void verifyArguments(const vector<string>& validArgs, const vector<T>& vt) {
/* ************************************************************************* */
void Module::matlab_code(const string& toolboxPath,
const string& nameSpace,
const string& mexExt,
const string& mexFlags)
{
@ -306,9 +308,9 @@ void Module::matlab_code(const string& toolboxPath,
verifyArguments<Method>(validArgs, cls.methods);
// create constructor and method wrappers
cls.matlab_constructors(toolboxPath,nameSpace);
cls.matlab_static_methods(toolboxPath,nameSpace);
cls.matlab_methods(classPath,nameSpace);
cls.matlab_constructors(toolboxPath,using_namespaces);
cls.matlab_static_methods(toolboxPath,using_namespaces);
cls.matlab_methods(classPath,using_namespaces);
// add lines to make m-file
ofs << "%% " << cls.qualifiedName() << endl;

View File

@ -31,6 +31,7 @@ struct Module {
std::string name; ///< module name
std::vector<Class> classes; ///< list of classes
bool verbose; ///< verbose flag
std::vector<std::string> using_namespaces; ///< all default namespaces
/// constructor that parses interface file
Module(const std::string& interfacePath,
@ -39,7 +40,6 @@ struct Module {
/// MATLAB code generation:
void matlab_code(const std::string& path,
const std::string& nameSpace,
const std::string& mexExt,
const std::string& mexFlags);
};

View File

@ -50,7 +50,8 @@ 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 string& nameSpace,
const string& matlabClassName, const string& cppClassName,
const vector<string>& using_namespaces,
const std::vector<std::string>& includes)
{
// open destination wrapperFile
@ -64,14 +65,8 @@ void StaticMethod::matlab_wrapper(const string& toolboxPath, const string& class
// header
wrap::emit_header_comment(ofs, "//");
ofs << "#include <wrap/matlab.h>\n";
if (includes.empty()) // add a default include
ofs << "#include <" << className << ".h>" << endl;
else {
BOOST_FOREACH(const string& s, includes)
ofs << "#include <" << s << ">" << endl;
}
if (!nameSpace.empty()) ofs << "using namespace " << nameSpace << ";" << endl;
generateIncludes(ofs, className, includes);
generateUsingNamespace(ofs, using_namespaces);
// call
ofs << "void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";

View File

@ -47,7 +47,8 @@ struct StaticMethod {
void matlab_mfile(const std::string& toolboxPath, const std::string& className); ///< m-file
void matlab_wrapper(const std::string& toolboxPath,
const std::string& className, const std::string& matlabClassName,
const std::string& cppClassName, const std::string& nameSpace,
const std::string& cppClassName,
const std::vector<std::string>& using_namespaces,
const std::vector<std::string>& includes); ///< cpp wrapper
};

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-06
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <Point2.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("dim",nargout,nargin-1,0);

View File

@ -0,0 +1,11 @@
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <Point2.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("vectorConfusion",nargout,nargin-1,0);
shared_ptr<Point2> self = unwrap_shared_ptr< Point2 >(in[0],"Point2");
VectorNotEigen result = self->vectorConfusion();
out[0] = wrap_shared_ptr(make_shared< VectorNotEigen >(result),"VectorNotEigen");
}

View File

@ -0,0 +1,4 @@
function result = vectorConfusion(obj)
% usage: obj.vectorConfusion()
error('need to compile vectorConfusion.cpp');
end

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-06
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <Point2.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("x",nargout,nargin-1,0);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-06
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <Point2.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("y",nargout,nargin-1,0);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-06
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <Point3.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("norm",nargout,nargin-1,0);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("arg_EigenConstRef",nargout,nargin-1,1);

View File

@ -0,0 +1,4 @@
function result = arg_EigenConstRef(obj,value)
% usage: obj.arg_EigenConstRef(value)
error('need to compile arg_EigenConstRef.cpp');
end

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("create_MixedPtrs",nargout,nargin-1,0);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("create_ptrs",nargout,nargin-1,0);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("print",nargout,nargin-1,0);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_Point2Ptr",nargout,nargin-1,1);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_Test",nargout,nargin-1,1);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_TestPtr",nargout,nargin-1,1);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_bool",nargout,nargin-1,1);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_double",nargout,nargin-1,1);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_field",nargout,nargin-1,1);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_int",nargout,nargin-1,1);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_matrix1",nargout,nargin-1,1);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_matrix2",nargout,nargin-1,1);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_pair",nargout,nargin-1,2);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_ptrs",nargout,nargin-1,2);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_size_t",nargout,nargin-1,1);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_string",nargout,nargin-1,1);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_vector1",nargout,nargin-1,1);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("return_vector2",nargout,nargin-1,1);

View File

@ -1,9 +1,11 @@
// automatically generated by wrap on 2011-Dec-06
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <Point3.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("Point3_StaticFunctionRet",nargout,nargin,0);
Point3 result = Point3::StaticFunctionRet();
checkArguments("Point3_StaticFunctionRet",nargout,nargin,1);
double z = unwrap< double >(in[0]);
Point3 result = Point3::StaticFunctionRet(z);
out[0] = wrap_shared_ptr(make_shared< Point3 >(result),"Point3");
}

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-06
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <Point3.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("Point3_staticFunction",nargout,nargin,0);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-06
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <Point2.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("new_Point2_",nargout,nargin,0);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-06
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <Point2.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("new_Point2_dd",nargout,nargin,2);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-06
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <Point3.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("new_Point3_ddd",nargout,nargin,3);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("new_Test_",nargout,nargin,0);

View File

@ -1,6 +1,7 @@
// automatically generated by wrap on 2011-Dec-08
// automatically generated by wrap on 2011-Dec-09
#include <wrap/matlab.h>
#include <folder/path/to/Test.h>
using namespace geometry;
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("new_Test_dM",nargout,nargin,2);

View File

@ -1,5 +1,9 @@
// comments!
// set the default namespace
// location of namespace isn't significant
using namespace geometry;
class Point2 {
Point2();
Point2(double x, double y);

View File

@ -56,7 +56,7 @@ TEST( wrap, check_exception ) {
string path = topdir + "/wrap/tests";
Module module(path.c_str(), "testWrap1",enable_verbose);
CHECK_EXCEPTION(module.matlab_code("actual", "", "mexa64", "-O5"), DependencyMissing);
CHECK_EXCEPTION(module.matlab_code("actual", "mexa64", "-O5"), DependencyMissing);
}
/* ************************************************************************* */
@ -65,6 +65,10 @@ TEST( wrap, parse ) {
Module module(header_path.c_str(), "geometry",enable_verbose);
EXPECT_LONGS_EQUAL(3, module.classes.size());
// check using declarations
EXPECT_LONGS_EQUAL(1, module.using_namespaces.size());
EXPECT(assert_equal("geometry", module.using_namespaces.front()));
// check first class, Point2
{
Class cls = module.classes.at(0);
@ -173,7 +177,7 @@ TEST( wrap, matlab_code_namespaces ) {
// emit MATLAB code
string exp_path = path + "/tests/expected_namespaces/";
string act_path = "actual_namespaces/";
module.matlab_code("actual_namespaces", "", "mexa64", "-O5");
module.matlab_code("actual_namespaces", "mexa64", "-O5");
EXPECT(files_equal(exp_path + "make_testNamespaces.m", act_path + "make_testNamespaces.m"));
EXPECT(files_equal(exp_path + "Makefile" , act_path + "Makefile" ));
@ -192,7 +196,7 @@ TEST( wrap, matlab_code ) {
// emit MATLAB code
// make_geometry will not compile, use make testwrap to generate real make
module.matlab_code("actual", "", "mexa64", "-O5");
module.matlab_code("actual", "mexa64", "-O5");
EXPECT(files_equal(path + "/tests/expected/@Point2/Point2.m" , "actual/@Point2/Point2.m" ));
EXPECT(files_equal(path + "/tests/expected/@Point2/x.cpp" , "actual/@Point2/x.cpp" ));

View File

@ -15,8 +15,8 @@
**/
#include <iostream>
#include <fstream>
#include <boost/foreach.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include "utilities.h"
@ -42,12 +42,12 @@ string file_contents(const string& filename, bool skipheader) {
}
/* ************************************************************************* */
bool assert_equal(const std::string& expected, const std::string& actual) {
bool assert_equal(const string& expected, const string& actual) {
if (expected == actual)
return true;
printf("Not equal:\n");
std::cout << "expected: [" << expected << "]\n";
std::cout << "actual: [" << actual << "]" << std::endl;
cout << "expected: [" << expected << "]\n";
cout << "actual: [" << actual << "]" << endl;
return false;
}
@ -82,13 +82,32 @@ void emit_header_comment(ofstream& ofs, const string& delimiter) {
}
/* ************************************************************************* */
std::string maybe_shared_ptr(bool add, const std::string& type) {
string maybe_shared_ptr(bool add, const string& type) {
string str = add? "shared_ptr<" : "";
str += type;
if (add) str += ">";
return str;
}
/* ************************************************************************* */
void generateUsingNamespace(ofstream& ofs, const vector<string>& using_namespaces) {
if (using_namespaces.empty()) return;
BOOST_FOREACH(const string& s, using_namespaces)
ofs << "using namespace " << s << ";" << endl;
}
/* ************************************************************************* */
void generateIncludes(std::ofstream& ofs, const std::string& class_name,
const std::vector<std::string>& includes) {
ofs << "#include <wrap/matlab.h>" << endl;
if (includes.empty()) // add a default include
ofs << "#include <" << class_name << ".h>" << endl;
else {
BOOST_FOREACH(const string& s, includes)
ofs << "#include <" << s << ">" << endl;
}
}
/* ************************************************************************* */
} // \namespace wrap

View File

@ -16,7 +16,9 @@
#pragma once
#include <vector>
#include <exception>
#include <fstream>
#include <sstream>
namespace wrap {
@ -85,4 +87,15 @@ 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);
/**
* Creates the "using namespace [name];" declarations
*/
void generateUsingNamespace(std::ofstream& ofs, const std::vector<std::string>& using_namespaces);
/**
* Creates the #include statements
*/
void generateIncludes(std::ofstream& ofs, const std::string& class_name,
const std::vector<std::string>& includes);
} // \namespace wrap

View File

@ -35,7 +35,6 @@ void generate_matlab_toolbox(const string& mexExt,
const string& interfacePath,
const string& moduleName,
const string& toolboxPath,
const string& nameSpace,
const string& mexFlags)
{
// Parse interface file into class object
@ -43,7 +42,7 @@ void generate_matlab_toolbox(const string& mexExt,
wrap::Module module(interfacePath, moduleName, true);
// Then emit MATLAB code
module.matlab_code(toolboxPath,nameSpace,mexExt,mexFlags);
module.matlab_code(toolboxPath,mexExt,mexFlags);
}
/**
@ -58,10 +57,9 @@ int main(int argc, const char* argv[]) {
cerr << " interfacePath : *absolute* path to directory of module interface file" << endl;
cerr << " moduleName : the name of the module, interface file must be called moduleName.h" << endl;
cerr << " toolboxPath : the directory in which to generate the wrappers" << endl;
cerr << " nameSpace : namespace to use, pass empty string if none" << endl;
cerr << " [mexFlags] : extra flags for the mex command" << endl;
}
else
generate_matlab_toolbox(argv[1],argv[2],argv[3],argv[4],argv[5],argc==6 ? " " : argv[6]);
generate_matlab_toolbox(argv[1],argv[2],argv[3],argv[4],argc==5 ? " " : argv[5]);
return 0;
}