summaryrefslogtreecommitdiff
path: root/matlab/lib/+IceInternal/WrapperObject.m
blob: 81f762bc51afd3b56f3f171eda831751c9632521 (plain)
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
50
51
52
53
54
55
%{
**********************************************************************

Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.

This copy of Ice is licensed to you under the terms described in the
ICE_LICENSE file included in this distribution.

**********************************************************************
%}

classdef (Abstract) WrapperObject < handle
    methods
        function obj = WrapperObject(impl, type)
            %
            % If no type was supplied, we convert the class name into the prefix that we'll use for invoking
            % external C functions.
            %
            if nargin == 1
                type = strrep(class(obj), '.', '_'); % E.g., Ice.Communicator -> Ice_Communicator
            end
            obj.impl_ = impl;
            obj.type_ = type;
        end
    end
    methods(Hidden)
        function delete(obj)
            if ~isempty(obj.impl_)
                obj.iceCall('unref');
            end
        end
        function iceCall(obj, fn, varargin)
            name = strcat(obj.type_, '_', fn);
            ex = calllib('icematlab', name, obj.impl_, varargin{:});
            if ~isempty(ex)
                ex.throwAsCaller();
            end
        end
        function r = iceCallWithResult(obj, fn, varargin)
            name = strcat(obj.type_, '_', fn);
            result = calllib('icematlab', name, obj.impl_, varargin{:});
            if isempty(result)
                r = result;
            elseif ~isempty(result.exception)
                result.exception.throwAsCaller();
            else
                r = result.result;
            end
        end
    end
    properties(Hidden,SetAccess=protected)
        impl_
        type_
    end
end