From a8607d284dccc399c7388a74150c511d39f2be02 Mon Sep 17 00:00:00 2001 From: Alex Cunningham Date: Mon, 23 Jan 2012 18:28:11 +0000 Subject: [PATCH] Added wrap support for char as a argument or return value type --- gtsam.h | 2 +- wrap/Module.cpp | 3 ++- wrap/matlab.h | 15 +++++++++++++++ wrap/tests/expected/Makefile | 8 ++++++-- wrap/tests/expected/make_geometry.m | 4 +++- wrap/tests/geometry.h | 2 ++ wrap/tests/testWrap.cpp | 2 +- 7 files changed, 30 insertions(+), 6 deletions(-) diff --git a/gtsam.h b/gtsam.h index 650b81ec6..a8255f667 100644 --- a/gtsam.h +++ b/gtsam.h @@ -9,7 +9,7 @@ * Only one Method/Constructor per line * Methods can return * - Eigen types: Matrix, Vector - * - C/C++ basic types: string, bool, size_t, int, double + * - C/C++ basic types: string, bool, size_t, int, double, char * - void * - Any class with which be copied with boost::make_shared() * - boost::shared_ptr of any object type diff --git a/wrap/Module.cpp b/wrap/Module.cpp index 9a819defb..499be6635 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -73,7 +73,7 @@ Module::Module(const string& interfacePath, // http://www.boost.org/doc/libs/1_37_0/libs/spirit/classic/doc/directives.html Rule basisType_p = - (str_p("string") | "bool" | "size_t" | "int" | "double"); + (str_p("string") | "bool" | "size_t" | "int" | "double" | "char"); Rule keywords_p = (str_p("const") | "static" | "namespace" | basisType_p); @@ -304,6 +304,7 @@ void Module::matlab_code(const string& toolboxPath, validTypes.push_back("string"); validTypes.push_back("int"); validTypes.push_back("bool"); + validTypes.push_back("char"); validTypes.push_back("size_t"); validTypes.push_back("double"); validTypes.push_back("Vector"); diff --git a/wrap/matlab.h b/wrap/matlab.h index 239bba8e5..86dceb3d8 100644 --- a/wrap/matlab.h +++ b/wrap/matlab.h @@ -97,6 +97,14 @@ mxArray* wrap(string& value) { return mxCreateString(value.c_str()); } +// specialization to char +template<> +mxArray* wrap(char& value) { + mxArray *result = scalar(mxUINT32OR64_CLASS); + *(char*)mxGetData(result) = value; + return result; +} + // specialization to bool template<> mxArray* wrap(bool& value) { @@ -204,6 +212,13 @@ bool unwrap(const mxArray* array) { return mxGetScalar(array) != 0.0; } +// specialization to bool +template<> +char unwrap(const mxArray* array) { + checkScalar(array,"unwrap"); + return (char)mxGetScalar(array); +} + // specialization to size_t template<> size_t unwrap(const mxArray* array) { diff --git a/wrap/tests/expected/Makefile b/wrap/tests/expected/Makefile index 6723330a3..662e1586b 100644 --- a/wrap/tests/expected/Makefile +++ b/wrap/tests/expected/Makefile @@ -1,4 +1,4 @@ -# automatically generated by wrap on 2012-Jan-15 +# automatically generated by wrap on 2012-Jan-23 MEX = mex MEXENDING = mexa64 @@ -17,10 +17,14 @@ new_Point2_dd.$(MEXENDING): new_Point2_dd.cpp $(MEX) $(mex_flags) @Point2/y.cpp -output @Point2/y @Point2/dim.$(MEXENDING): @Point2/dim.cpp $(MEX) $(mex_flags) @Point2/dim.cpp -output @Point2/dim +@Point2/returnChar.$(MEXENDING): @Point2/returnChar.cpp + $(MEX) $(mex_flags) @Point2/returnChar.cpp -output @Point2/returnChar +@Point2/argChar.$(MEXENDING): @Point2/argChar.cpp + $(MEX) $(mex_flags) @Point2/argChar.cpp -output @Point2/argChar @Point2/vectorConfusion.$(MEXENDING): @Point2/vectorConfusion.cpp $(MEX) $(mex_flags) @Point2/vectorConfusion.cpp -output @Point2/vectorConfusion -Point2: new_Point2_.$(MEXENDING) new_Point2_dd.$(MEXENDING) @Point2/x.$(MEXENDING) @Point2/y.$(MEXENDING) @Point2/dim.$(MEXENDING) @Point2/vectorConfusion.$(MEXENDING) +Point2: new_Point2_.$(MEXENDING) new_Point2_dd.$(MEXENDING) @Point2/x.$(MEXENDING) @Point2/y.$(MEXENDING) @Point2/dim.$(MEXENDING) @Point2/returnChar.$(MEXENDING) @Point2/argChar.$(MEXENDING) @Point2/vectorConfusion.$(MEXENDING) # Point3 new_Point3_ddd.$(MEXENDING): new_Point3_ddd.cpp diff --git a/wrap/tests/expected/make_geometry.m b/wrap/tests/expected/make_geometry.m index 81ddc186f..1824d8b74 100644 --- a/wrap/tests/expected/make_geometry.m +++ b/wrap/tests/expected/make_geometry.m @@ -1,4 +1,4 @@ -% automatically generated by wrap on 2012-Jan-15 +% automatically generated by wrap on 2012-Jan-23 echo on toolboxpath = mfilename('fullpath'); @@ -16,6 +16,8 @@ cd @Point2 mex -O5 x.cpp mex -O5 y.cpp mex -O5 dim.cpp +mex -O5 returnChar.cpp +mex -O5 argChar.cpp mex -O5 vectorConfusion.cpp %% Point3 diff --git a/wrap/tests/geometry.h b/wrap/tests/geometry.h index 92e23692a..635f0ba39 100644 --- a/wrap/tests/geometry.h +++ b/wrap/tests/geometry.h @@ -12,6 +12,8 @@ class Point2 { double x() const; double y() const; int dim() const; + char returnChar() const; + void argChar(char a) const; VectorNotEigen vectorConfusion(); }; diff --git a/wrap/tests/testWrap.cpp b/wrap/tests/testWrap.cpp index c716b0379..ea320374c 100644 --- a/wrap/tests/testWrap.cpp +++ b/wrap/tests/testWrap.cpp @@ -84,7 +84,7 @@ TEST( wrap, parse ) { Class cls = module.classes.at(0); EXPECT(assert_equal("Point2", cls.name)); EXPECT_LONGS_EQUAL(2, cls.constructors.size()); - EXPECT_LONGS_EQUAL(4, cls.methods.size()); + EXPECT_LONGS_EQUAL(6, cls.methods.size()); EXPECT_LONGS_EQUAL(0, cls.static_methods.size()); EXPECT_LONGS_EQUAL(0, cls.namespaces.size()); }