forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrakeMexPointer.m
49 lines (43 loc) · 1.29 KB
/
DrakeMexPointer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
classdef DrakeMexPointer < handle
% My attempt to clean-up the mex-matlab sharing pointer interface
%
% mex_ptr = myMexFunction(...); // the mex function calls createDrakeMexPointer
% myMexFunctions(mex_ptr,other_data); // these call getDrakeMexPointer
properties (SetAccess=private,GetAccess=public)
name = '';
ptr
delete_fcn='';
delete_fcn_additional_inputs={};
end
methods
function obj = DrakeMexPointer(ptr, delete_fcn, name, varargin)
obj.ptr = ptr;
if (nargin>1) obj.delete_fcn = delete_fcn; end
if (nargin>2) obj.name = name; end
if (nargin>3)
obj.delete_fcn_additional_inputs=varargin;
end
end
function delete(obj)
if 0 %~isempty(obj.delete_fcn) % useful for debugging
fprintf(1,'Calling %s(',obj.delete_fcn);
celldisp(obj.delete_fcn_additional_inputs);
fprintf(1,') to delete ');
if isempty(obj.name)
fprintf(1,'unnamed drake mex pointer\n');
else
fprintf(1,'drake mex pointer %s\n',obj.name);
end
end
if ~isempty(obj.delete_fcn)
feval(obj.delete_fcn,obj.delete_fcn_additional_inputs{:},obj);
end
end
end
methods (Static)
function obj = loadobj(obj)
obj.delete_fcn = '';
obj = 0;
end
end
end