diff --git a/wrap/Class.cpp b/wrap/Class.cpp index 08ce392a0..76554e608 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -60,7 +60,7 @@ void Class::matlab_proxy(const string& classFile) { void Class::matlab_constructors(const string& toolboxPath,const string& nameSpace) { BOOST_FOREACH(Constructor c, constructors) { c.matlab_mfile (toolboxPath, qualifiedName()); - c.matlab_wrapper(toolboxPath, qualifiedName("::"), qualifiedName(), nameSpace); + c.matlab_wrapper(toolboxPath, qualifiedName("::"), qualifiedName(), nameSpace, includes); } } @@ -69,7 +69,7 @@ void Class::matlab_methods(const string& classPath, const string& nameSpace) { string matlabName = qualifiedName(), cppName = qualifiedName("::"); BOOST_FOREACH(Method m, methods) { m.matlab_mfile (classPath); - m.matlab_wrapper(classPath, name, cppName, matlabName, nameSpace); + m.matlab_wrapper(classPath, name, cppName, matlabName, nameSpace, includes); } } @@ -78,7 +78,7 @@ void Class::matlab_static_methods(const string& toolboxPath, const string& nameS string matlabName = qualifiedName(), cppName = qualifiedName("::"); BOOST_FOREACH(StaticMethod& m, static_methods) { m.matlab_mfile (toolboxPath, qualifiedName()); - m.matlab_wrapper(toolboxPath, name, matlabName, cppName, nameSpace); + m.matlab_wrapper(toolboxPath, name, matlabName, cppName, nameSpace, includes); } } diff --git a/wrap/Class.h b/wrap/Class.h index 5938dc578..db9c14c8c 100644 --- a/wrap/Class.h +++ b/wrap/Class.h @@ -31,12 +31,13 @@ struct Class { Class(bool verbose=true) : verbose_(verbose) {} // Then the instance variables are set directly by the Module constructor - std::string name; ///< Class name + std::string name; ///< Class name std::vector constructors; ///< Class constructors std::vector methods; ///< Class methods std::vector static_methods; ///< Static methods - std::vector namespaces; ///< Stack of namespaces - bool verbose_; ///< verbose flag + std::vector namespaces; ///< Stack of namespaces + std::vector includes; ///< header include overrides + bool verbose_; ///< verbose flag // And finally MATLAB code is emitted, methods below called by Module::matlab_code void matlab_proxy(const std::string& classFile); ///< emit proxy class diff --git a/wrap/Constructor.cpp b/wrap/Constructor.cpp index c4458e198..4bc233ca2 100644 --- a/wrap/Constructor.cpp +++ b/wrap/Constructor.cpp @@ -56,7 +56,7 @@ void Constructor::matlab_mfile(const string& toolboxPath, const string& qualifie if(verbose_) cerr << "generating " << wrapperFile << endl; // generate code - wrap::emit_header_comment(ofs, "%"); + emit_header_comment(ofs, "%"); ofs << "function result = " << matlabName << "(obj"; if (args.size()) ofs << "," << args.names(); ofs << ")" << endl; @@ -71,7 +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 string& nameSpace) + const string& nameSpace, const vector& includes) { string matlabName = matlab_wrapper_name(matlabClassName); @@ -83,9 +83,14 @@ void Constructor::matlab_wrapper(const string& toolboxPath, if(verbose_) cerr << "generating " << wrapperFile << endl; // generate code - wrap::emit_header_comment(ofs, "//"); + emit_header_comment(ofs, "//"); ofs << "#include " << endl; - ofs << "#include <" << name << ".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; ofs << "void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])" << endl; ofs << "{" << endl; diff --git a/wrap/Constructor.h b/wrap/Constructor.h index 7ad8cd9d5..08906dbbd 100644 --- a/wrap/Constructor.h +++ b/wrap/Constructor.h @@ -18,7 +18,7 @@ #pragma once #include -#include +#include #include "Argument.h" @@ -51,11 +51,11 @@ struct Constructor { void matlab_mfile(const std::string& toolboxPath, const std::string& qualifiedMatlabName); - /// wrapper + /// cpp wrapper void matlab_wrapper(const std::string& toolboxPath, const std::string& cppClassName, const std::string& matlabClassName, - const std::string& nameSpace); + const std::string& nameSpace, const std::vector& includes); }; } // \namespace wrap diff --git a/wrap/Method.cpp b/wrap/Method.cpp index 8dbc3cb4f..c5f01abcf 100644 --- a/wrap/Method.cpp +++ b/wrap/Method.cpp @@ -52,7 +52,7 @@ void Method::matlab_wrapper(const string& classPath, const string& className, const string& cppClassName, const string& matlabClassName, - const string& nameSpace) + const string& nameSpace, const std::vector& includes) { // open destination wrapperFile string wrapperFile = classPath + "/" + name + ".cpp"; @@ -65,7 +65,12 @@ void Method::matlab_wrapper(const string& classPath, // header wrap::emit_header_comment(ofs, "//"); ofs << "#include \n"; - ofs << "#include <" << className << ".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; // call diff --git a/wrap/Method.h b/wrap/Method.h index c3a9f1e00..95dc83924 100644 --- a/wrap/Method.h +++ b/wrap/Method.h @@ -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); ///< wrapper + const std::string& matlabClassname,const std::string& nameSpace, + const std::vector& includes); ///< cpp wrapper }; } // \namespace wrap diff --git a/wrap/Module.cpp b/wrap/Module.cpp index 24257c96b..9c0feff69 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -169,7 +169,9 @@ Module::Module(const string& interfacePath, [push_back_a(cls.static_methods, static_method)] [assign_a(static_method,static_method0)]; - Rule functions_p = constructor_p | method_p | static_method_p; + Rule includes_p = str_p("#include") >> ch_p('<') >> (*(anychar_p - '>'))[push_back_a(cls.includes)] >> ch_p('>'); + + Rule functions_p = includes_p | constructor_p | method_p | static_method_p; Rule class_p = (str_p("class") >> className_p[assign_a(cls.name)] >> '{' >> *(functions_p | comments_p) >> diff --git a/wrap/StaticMethod.cpp b/wrap/StaticMethod.cpp index 352c9c680..17f3e2a60 100644 --- a/wrap/StaticMethod.cpp +++ b/wrap/StaticMethod.cpp @@ -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 string& nameSpace, + const std::vector& includes) { // open destination wrapperFile string full_name = matlabClassName + "_" + name; @@ -64,7 +65,12 @@ void StaticMethod::matlab_wrapper(const string& toolboxPath, const string& class // header wrap::emit_header_comment(ofs, "//"); ofs << "#include \n"; - ofs << "#include <" << className << ".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; // call diff --git a/wrap/StaticMethod.h b/wrap/StaticMethod.h index c50959d02..4038a398e 100644 --- a/wrap/StaticMethod.h +++ b/wrap/StaticMethod.h @@ -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); ///< cpp wrapper + const std::string& cppClassName, const std::string& nameSpace, + const std::vector& includes); ///< cpp wrapper }; } // \namespace wrap diff --git a/wrap/tests/expected/@Test/arg_EigenConstRef.cpp b/wrap/tests/expected/@Test/arg_EigenConstRef.cpp new file mode 100644 index 000000000..b2b779c9f --- /dev/null +++ b/wrap/tests/expected/@Test/arg_EigenConstRef.cpp @@ -0,0 +1,10 @@ +// automatically generated by wrap on 2011-Dec-08 +#include +#include +void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("arg_EigenConstRef",nargout,nargin-1,1); + shared_ptr self = unwrap_shared_ptr< Test >(in[0],"Test"); + Matrix& value = *unwrap_shared_ptr< Matrix >(in[1], "Matrix"); + self->arg_EigenConstRef(value); +} diff --git a/wrap/tests/expected/@Test/create_MixedPtrs.cpp b/wrap/tests/expected/@Test/create_MixedPtrs.cpp index 6e271486b..19a0eb740 100644 --- a/wrap/tests/expected/@Test/create_MixedPtrs.cpp +++ b/wrap/tests/expected/@Test/create_MixedPtrs.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("create_MixedPtrs",nargout,nargin-1,0); diff --git a/wrap/tests/expected/@Test/create_ptrs.cpp b/wrap/tests/expected/@Test/create_ptrs.cpp index c09be35c1..26e901123 100644 --- a/wrap/tests/expected/@Test/create_ptrs.cpp +++ b/wrap/tests/expected/@Test/create_ptrs.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("create_ptrs",nargout,nargin-1,0); diff --git a/wrap/tests/expected/@Test/print.cpp b/wrap/tests/expected/@Test/print.cpp index 0cdd5d5f1..90e1b0965 100644 --- a/wrap/tests/expected/@Test/print.cpp +++ b/wrap/tests/expected/@Test/print.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("print",nargout,nargin-1,0); diff --git a/wrap/tests/expected/@Test/return_Point2Ptr.cpp b/wrap/tests/expected/@Test/return_Point2Ptr.cpp index 6079eb972..400a0f9df 100644 --- a/wrap/tests/expected/@Test/return_Point2Ptr.cpp +++ b/wrap/tests/expected/@Test/return_Point2Ptr.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_Point2Ptr",nargout,nargin-1,1); diff --git a/wrap/tests/expected/@Test/return_Test.cpp b/wrap/tests/expected/@Test/return_Test.cpp index e14aecb89..c7a91cbe3 100644 --- a/wrap/tests/expected/@Test/return_Test.cpp +++ b/wrap/tests/expected/@Test/return_Test.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_Test",nargout,nargin-1,1); diff --git a/wrap/tests/expected/@Test/return_TestPtr.cpp b/wrap/tests/expected/@Test/return_TestPtr.cpp index ae34da13b..2f2fd7ef4 100644 --- a/wrap/tests/expected/@Test/return_TestPtr.cpp +++ b/wrap/tests/expected/@Test/return_TestPtr.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_TestPtr",nargout,nargin-1,1); diff --git a/wrap/tests/expected/@Test/return_bool.cpp b/wrap/tests/expected/@Test/return_bool.cpp index 5fd50cf3f..6d57ad149 100644 --- a/wrap/tests/expected/@Test/return_bool.cpp +++ b/wrap/tests/expected/@Test/return_bool.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_bool",nargout,nargin-1,1); diff --git a/wrap/tests/expected/@Test/return_double.cpp b/wrap/tests/expected/@Test/return_double.cpp index ef1704b07..adf1847b3 100644 --- a/wrap/tests/expected/@Test/return_double.cpp +++ b/wrap/tests/expected/@Test/return_double.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_double",nargout,nargin-1,1); diff --git a/wrap/tests/expected/@Test/return_field.cpp b/wrap/tests/expected/@Test/return_field.cpp index 593d4b5fe..f4de80c8a 100644 --- a/wrap/tests/expected/@Test/return_field.cpp +++ b/wrap/tests/expected/@Test/return_field.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_field",nargout,nargin-1,1); diff --git a/wrap/tests/expected/@Test/return_int.cpp b/wrap/tests/expected/@Test/return_int.cpp index 429ef73ce..736b9c981 100644 --- a/wrap/tests/expected/@Test/return_int.cpp +++ b/wrap/tests/expected/@Test/return_int.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_int",nargout,nargin-1,1); diff --git a/wrap/tests/expected/@Test/return_matrix1.cpp b/wrap/tests/expected/@Test/return_matrix1.cpp index 0f3966361..9dfc56332 100644 --- a/wrap/tests/expected/@Test/return_matrix1.cpp +++ b/wrap/tests/expected/@Test/return_matrix1.cpp @@ -1,11 +1,11 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_matrix1",nargout,nargin-1,1); shared_ptr self = unwrap_shared_ptr< Test >(in[0],"Test"); Matrix value = unwrap< Matrix >(in[1]); Matrix result = self->return_matrix1(value); - out[0] = wrap_shared_ptr(make_shared< Matrix >(result),"Matrix"); + out[0] = wrap< Matrix >(result); } diff --git a/wrap/tests/expected/@Test/return_matrix2.cpp b/wrap/tests/expected/@Test/return_matrix2.cpp index 1c16e910e..c55b3c56c 100644 --- a/wrap/tests/expected/@Test/return_matrix2.cpp +++ b/wrap/tests/expected/@Test/return_matrix2.cpp @@ -1,11 +1,11 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_matrix2",nargout,nargin-1,1); shared_ptr self = unwrap_shared_ptr< Test >(in[0],"Test"); Matrix value = unwrap< Matrix >(in[1]); Matrix result = self->return_matrix2(value); - out[0] = wrap_shared_ptr(make_shared< Matrix >(result),"Matrix"); + out[0] = wrap< Matrix >(result); } diff --git a/wrap/tests/expected/@Test/return_pair.cpp b/wrap/tests/expected/@Test/return_pair.cpp index 7224f5150..a629cd757 100644 --- a/wrap/tests/expected/@Test/return_pair.cpp +++ b/wrap/tests/expected/@Test/return_pair.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_pair",nargout,nargin-1,2); diff --git a/wrap/tests/expected/@Test/return_ptrs.cpp b/wrap/tests/expected/@Test/return_ptrs.cpp index 59f8d8739..bcd24536d 100644 --- a/wrap/tests/expected/@Test/return_ptrs.cpp +++ b/wrap/tests/expected/@Test/return_ptrs.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_ptrs",nargout,nargin-1,2); diff --git a/wrap/tests/expected/@Test/return_size_t.cpp b/wrap/tests/expected/@Test/return_size_t.cpp index 887addc3f..f0a05cdcc 100644 --- a/wrap/tests/expected/@Test/return_size_t.cpp +++ b/wrap/tests/expected/@Test/return_size_t.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_size_t",nargout,nargin-1,1); diff --git a/wrap/tests/expected/@Test/return_string.cpp b/wrap/tests/expected/@Test/return_string.cpp index 9b6ee320f..28dab1870 100644 --- a/wrap/tests/expected/@Test/return_string.cpp +++ b/wrap/tests/expected/@Test/return_string.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_string",nargout,nargin-1,1); diff --git a/wrap/tests/expected/@Test/return_vector1.cpp b/wrap/tests/expected/@Test/return_vector1.cpp index 4614e660d..38b8f1b0b 100644 --- a/wrap/tests/expected/@Test/return_vector1.cpp +++ b/wrap/tests/expected/@Test/return_vector1.cpp @@ -1,11 +1,11 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_vector1",nargout,nargin-1,1); shared_ptr self = unwrap_shared_ptr< Test >(in[0],"Test"); Vector value = unwrap< Vector >(in[1]); Vector result = self->return_vector1(value); - out[0] = wrap_shared_ptr(make_shared< Vector >(result),"Vector"); + out[0] = wrap< Vector >(result); } diff --git a/wrap/tests/expected/@Test/return_vector2.cpp b/wrap/tests/expected/@Test/return_vector2.cpp index 6fa6f7863..c629d2eb2 100644 --- a/wrap/tests/expected/@Test/return_vector2.cpp +++ b/wrap/tests/expected/@Test/return_vector2.cpp @@ -1,11 +1,11 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("return_vector2",nargout,nargin-1,1); shared_ptr self = unwrap_shared_ptr< Test >(in[0],"Test"); Vector value = unwrap< Vector >(in[1]); Vector result = self->return_vector2(value); - out[0] = wrap_shared_ptr(make_shared< Vector >(result),"Vector"); + out[0] = wrap< Vector >(result); } diff --git a/wrap/tests/expected/new_Test_.cpp b/wrap/tests/expected/new_Test_.cpp index 39898b03c..d3cf0d658 100644 --- a/wrap/tests/expected/new_Test_.cpp +++ b/wrap/tests/expected/new_Test_.cpp @@ -1,6 +1,6 @@ -// automatically generated by wrap on 2011-Dec-06 +// automatically generated by wrap on 2011-Dec-08 #include -#include +#include void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("new_Test_",nargout,nargin,0); diff --git a/wrap/tests/expected/new_Test_dM.cpp b/wrap/tests/expected/new_Test_dM.cpp new file mode 100644 index 000000000..94c473061 --- /dev/null +++ b/wrap/tests/expected/new_Test_dM.cpp @@ -0,0 +1,11 @@ +// automatically generated by wrap on 2011-Dec-08 +#include +#include +void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("new_Test_dM",nargout,nargin,2); + double a = unwrap< double >(in[0]); + Matrix b = unwrap< Matrix >(in[1]); + Test* self = new Test(a,b); + out[0] = wrap_constructed(self,"Test"); +} diff --git a/wrap/tests/geometry.h b/wrap/tests/geometry.h index 2eac86bfe..f4adb8eb6 100644 --- a/wrap/tests/geometry.h +++ b/wrap/tests/geometry.h @@ -27,6 +27,8 @@ class Point3 { */ class Test { +#include + /* a comment! */ // another comment Test(); diff --git a/wrap/tests/testWrap.cpp b/wrap/tests/testWrap.cpp index f9151dba2..d94834aed 100644 --- a/wrap/tests/testWrap.cpp +++ b/wrap/tests/testWrap.cpp @@ -111,6 +111,8 @@ TEST( wrap, parse ) { EXPECT_LONGS_EQUAL(19, testCls.methods.size()); EXPECT_LONGS_EQUAL( 0, testCls.static_methods.size()); EXPECT_LONGS_EQUAL( 0, testCls.namespaces.size()); + EXPECT_LONGS_EQUAL( 1, testCls.includes.size()); + EXPECT(assert_equal("folder/path/to/Test.h", testCls.includes.front())); // function to parse: pair return_pair (Vector v, Matrix A) const; Method m2 = testCls.methods.front();