Added tests for doubly templated class and typedef

release/4.3a0
dellaert 2014-11-11 23:09:20 +01:00
parent 8ab83a7cff
commit 2ab5e17cd8
6 changed files with 111 additions and 11 deletions

View File

@ -0,0 +1,36 @@
%class MyFactorPosePoint2, see Doxygen page for details
%at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
%
%-------Constructors-------
%MyFactorPosePoint2(size_t key1, size_t key2, double measured, Base noiseModel)
%
classdef MyFactorPosePoint2 < handle
properties
ptr_MyFactorPosePoint2 = 0
end
methods
function obj = MyFactorPosePoint2(varargin)
if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682)
my_ptr = varargin{2};
geometry_wrapper(53, my_ptr);
elseif nargin == 4 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') && isa(varargin{3},'double') && isa(varargin{4},'gtsam.noiseModel.Base')
my_ptr = geometry_wrapper(54, varargin{1}, varargin{2}, varargin{3}, varargin{4});
else
error('Arguments do not match any overload of MyFactorPosePoint2 constructor');
end
obj.ptr_MyFactorPosePoint2 = my_ptr;
end
function delete(obj)
geometry_wrapper(55, obj.ptr_MyFactorPosePoint2);
end
function display(obj), obj.print(''); end
%DISPLAY Calls print on the object
function disp(obj), obj.display; end
%DISP Calls print on the object
end
methods(Static = true)
end
end

View File

@ -1,6 +1,6 @@
function varargout = aGlobalFunction(varargin) function varargout = aGlobalFunction(varargin)
if length(varargin) == 0 if length(varargin) == 0
varargout{1} = geometry_wrapper(53, varargin{:}); varargout{1} = geometry_wrapper(56, varargin{:});
else else
error('Arguments do not match any overload of function aGlobalFunction'); error('Arguments do not match any overload of function aGlobalFunction');
end end

View File

@ -6,6 +6,7 @@
typedef MyTemplate<Point2> MyTemplatePoint2; typedef MyTemplate<Point2> MyTemplatePoint2;
typedef MyTemplate<Point3> MyTemplatePoint3; typedef MyTemplate<Point3> MyTemplatePoint3;
typedef MyFactor<gtsam::Pose2, gtsam::Point2> MyFactorPosePoint2;
typedef std::set<boost::shared_ptr<Point2>*> Collector_Point2; typedef std::set<boost::shared_ptr<Point2>*> Collector_Point2;
static Collector_Point2 collector_Point2; static Collector_Point2 collector_Point2;
@ -19,6 +20,8 @@ typedef std::set<boost::shared_ptr<MyTemplatePoint2>*> Collector_MyTemplatePoint
static Collector_MyTemplatePoint2 collector_MyTemplatePoint2; static Collector_MyTemplatePoint2 collector_MyTemplatePoint2;
typedef std::set<boost::shared_ptr<MyTemplatePoint3>*> Collector_MyTemplatePoint3; typedef std::set<boost::shared_ptr<MyTemplatePoint3>*> Collector_MyTemplatePoint3;
static Collector_MyTemplatePoint3 collector_MyTemplatePoint3; static Collector_MyTemplatePoint3 collector_MyTemplatePoint3;
typedef std::set<boost::shared_ptr<MyFactorPosePoint2>*> Collector_MyFactorPosePoint2;
static Collector_MyFactorPosePoint2 collector_MyFactorPosePoint2;
void _deleteAllObjects() void _deleteAllObjects()
{ {
@ -62,6 +65,12 @@ void _deleteAllObjects()
collector_MyTemplatePoint3.erase(iter++); collector_MyTemplatePoint3.erase(iter++);
anyDeleted = true; anyDeleted = true;
} } } }
{ for(Collector_MyFactorPosePoint2::iterator iter = collector_MyFactorPosePoint2.begin();
iter != collector_MyFactorPosePoint2.end(); ) {
delete *iter;
collector_MyFactorPosePoint2.erase(iter++);
anyDeleted = true;
} }
if(anyDeleted) if(anyDeleted)
cout << cout <<
"WARNING: Wrap modules with variables in the workspace have been reloaded due to\n" "WARNING: Wrap modules with variables in the workspace have been reloaded due to\n"
@ -647,18 +656,55 @@ void MyTemplatePoint3_templatedMethod_52(int nargout, mxArray *out[], int nargin
obj->templatedMethod(t); obj->templatedMethod(t);
} }
void aGlobalFunction_53(int nargout, mxArray *out[], int nargin, const mxArray *in[]) void MyFactorPosePoint2_collectorInsertAndMakeBase_53(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
mexAtExit(&_deleteAllObjects);
typedef boost::shared_ptr<MyFactorPosePoint2> Shared;
Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
collector_MyFactorPosePoint2.insert(self);
}
void MyFactorPosePoint2_constructor_54(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
mexAtExit(&_deleteAllObjects);
typedef boost::shared_ptr<MyFactorPosePoint2> Shared;
size_t key1 = unwrap< size_t >(in[0]);
size_t key2 = unwrap< size_t >(in[1]);
double measured = unwrap< double >(in[2]);
boost::shared_ptr<gtsam::noiseModel::Base> noiseModel = unwrap_shared_ptr< gtsam::noiseModel::Base >(in[3], "ptr_gtsamnoiseModelBase");
Shared *self = new Shared(new MyFactorPosePoint2(key1,key2,measured,noiseModel));
collector_MyFactorPosePoint2.insert(self);
out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL);
*reinterpret_cast<Shared**> (mxGetData(out[0])) = self;
}
void MyFactorPosePoint2_deconstructor_55(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
typedef boost::shared_ptr<MyFactorPosePoint2> Shared;
checkArguments("delete_MyFactorPosePoint2",nargout,nargin,1);
Shared *self = *reinterpret_cast<Shared**>(mxGetData(in[0]));
Collector_MyFactorPosePoint2::iterator item;
item = collector_MyFactorPosePoint2.find(self);
if(item != collector_MyFactorPosePoint2.end()) {
delete self;
collector_MyFactorPosePoint2.erase(item);
}
}
void aGlobalFunction_56(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{ {
checkArguments("aGlobalFunction",nargout,nargin,0); checkArguments("aGlobalFunction",nargout,nargin,0);
out[0] = wrap< Vector >(aGlobalFunction()); out[0] = wrap< Vector >(aGlobalFunction());
} }
void overloadedGlobalFunction_54(int nargout, mxArray *out[], int nargin, const mxArray *in[]) void overloadedGlobalFunction_57(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{ {
checkArguments("overloadedGlobalFunction",nargout,nargin,1); checkArguments("overloadedGlobalFunction",nargout,nargin,1);
int a = unwrap< int >(in[0]); int a = unwrap< int >(in[0]);
out[0] = wrap< Vector >(overloadedGlobalFunction(a)); out[0] = wrap< Vector >(overloadedGlobalFunction(a));
} }
void overloadedGlobalFunction_55(int nargout, mxArray *out[], int nargin, const mxArray *in[]) void overloadedGlobalFunction_58(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{ {
checkArguments("overloadedGlobalFunction",nargout,nargin,2); checkArguments("overloadedGlobalFunction",nargout,nargin,2);
int a = unwrap< int >(in[0]); int a = unwrap< int >(in[0]);
@ -837,13 +883,22 @@ void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
MyTemplatePoint3_templatedMethod_52(nargout, out, nargin-1, in+1); MyTemplatePoint3_templatedMethod_52(nargout, out, nargin-1, in+1);
break; break;
case 53: case 53:
aGlobalFunction_53(nargout, out, nargin-1, in+1); MyFactorPosePoint2_collectorInsertAndMakeBase_53(nargout, out, nargin-1, in+1);
break; break;
case 54: case 54:
overloadedGlobalFunction_54(nargout, out, nargin-1, in+1); MyFactorPosePoint2_constructor_54(nargout, out, nargin-1, in+1);
break; break;
case 55: case 55:
overloadedGlobalFunction_55(nargout, out, nargin-1, in+1); MyFactorPosePoint2_deconstructor_55(nargout, out, nargin-1, in+1);
break;
case 56:
aGlobalFunction_56(nargout, out, nargin-1, in+1);
break;
case 57:
overloadedGlobalFunction_57(nargout, out, nargin-1, in+1);
break;
case 58:
overloadedGlobalFunction_58(nargout, out, nargin-1, in+1);
break; break;
} }
} catch(const std::exception& e) { } catch(const std::exception& e) {

View File

@ -1,8 +1,8 @@
function varargout = overloadedGlobalFunction(varargin) function varargout = overloadedGlobalFunction(varargin)
if length(varargin) == 1 && isa(varargin{1},'numeric') if length(varargin) == 1 && isa(varargin{1},'numeric')
varargout{1} = geometry_wrapper(54, varargin{:}); varargout{1} = geometry_wrapper(57, varargin{:});
elseif length(varargin) == 2 && isa(varargin{1},'numeric') && isa(varargin{2},'double') elseif length(varargin) == 2 && isa(varargin{1},'numeric') && isa(varargin{2},'double')
varargout{1} = geometry_wrapper(55, varargin{:}); varargout{1} = geometry_wrapper(58, varargin{:});
else else
error('Arguments do not match any overload of function overloadedGlobalFunction'); error('Arguments do not match any overload of function overloadedGlobalFunction');
end end

View File

@ -105,6 +105,14 @@ virtual class MyTemplate : MyBase {
void templatedMethod(const Test& t); void templatedMethod(const Test& t);
}; };
// A doubly templated class
template<POSE, POINT>
class MyFactor {
MyFactor(size_t key1, size_t key2, double measured, const gtsam::noiseModel::Base* noiseModel);
};
// and a typedef specializing it
typedef MyFactor<gtsam::Pose2, gtsam::Point2> MyFactorPosePoint2;
// comments at the end! // comments at the end!

View File

@ -153,7 +153,7 @@ TEST( wrap, small_parse ) {
TEST( wrap, parse_geometry ) { TEST( wrap, parse_geometry ) {
string markup_header_path = topdir + "/wrap/tests"; string markup_header_path = topdir + "/wrap/tests";
Module module(markup_header_path.c_str(), "geometry",enable_verbose); Module module(markup_header_path.c_str(), "geometry",enable_verbose);
EXPECT_LONGS_EQUAL(6, module.classes.size()); EXPECT_LONGS_EQUAL(7, module.classes.size());
// forward declarations // forward declarations
LONGS_EQUAL(2, module.forward_declarations.size()); LONGS_EQUAL(2, module.forward_declarations.size());
@ -164,7 +164,7 @@ TEST( wrap, parse_geometry ) {
strvec exp_includes; exp_includes += "folder/path/to/Test.h"; strvec exp_includes; exp_includes += "folder/path/to/Test.h";
EXPECT(assert_equal(exp_includes, module.includes)); EXPECT(assert_equal(exp_includes, module.includes));
LONGS_EQUAL(6, module.classes.size()); LONGS_EQUAL(7, module.classes.size());
// Key for ReturnValue::return_category // Key for ReturnValue::return_category
// CLASS = 1, // CLASS = 1,
@ -461,6 +461,7 @@ TEST( wrap, matlab_code_geometry ) {
EXPECT(files_equal(epath + "MyBase.m" , apath + "MyBase.m" )); EXPECT(files_equal(epath + "MyBase.m" , apath + "MyBase.m" ));
EXPECT(files_equal(epath + "MyTemplatePoint2.m" , apath + "MyTemplatePoint2.m" )); EXPECT(files_equal(epath + "MyTemplatePoint2.m" , apath + "MyTemplatePoint2.m" ));
EXPECT(files_equal(epath + "MyTemplatePoint3.m" , apath + "MyTemplatePoint3.m" )); EXPECT(files_equal(epath + "MyTemplatePoint3.m" , apath + "MyTemplatePoint3.m" ));
EXPECT(files_equal(epath + "MyFactorPosePoint2.m" , apath + "MyFactorPosePoint2.m"));
EXPECT(files_equal(epath + "aGlobalFunction.m" , apath + "aGlobalFunction.m" )); EXPECT(files_equal(epath + "aGlobalFunction.m" , apath + "aGlobalFunction.m" ));
EXPECT(files_equal(epath + "overloadedGlobalFunction.m" , apath + "overloadedGlobalFunction.m" )); EXPECT(files_equal(epath + "overloadedGlobalFunction.m" , apath + "overloadedGlobalFunction.m" ));
} }