1 ## Copyright (C) 2011 Carnë Draug <carandraug+dev@gmail.com>
2 ## Copyright (c) 2011 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
3 ## Improvement based on John W. Eaton's idea.
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or
8 ## (at your option) any later version.
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
19 ## @deftypefn {Function File} {} function_name ()
22 function varargout = subsref (obj, idx)
24 persistent __method__ method4field typeNotImplemented
25 if isempty(__method__)
27 __method__ = struct();
29 __method__.plot = @(o,varargin) plot (o, varargin{:});
30 __method__.getpath = @(o,varargin) getpath (o, varargin{:});
31 __method__.pathid = @(o,varargin) pathid(o,varargin{:});
32 __method__.path2polygon = @(o,varargin) path2polygon (o, varargin{:});
33 __method__.normalize = @(o,varargin) normalize (o, varargin{:});
34 __method__.height = @(o,varargin) height(o, varargin{:});
35 __method__.width = @(o,varargin) width(o,varargin{:});
38 method4field = "Class %s has no field %s. Use %s() for the method.";
39 typeNotImplemented = "%s no implemented for class %s.";
43 if ( !strcmp (class (obj), 'svg') )
44 error ("Object must be of the svg class but '%s' was used", class (obj) );
45 elseif ( idx(1).type != '.' )
46 error ("Invalid index for class %s", class (obj) );
50 if ~isfield(__method__, method)
51 error('Unknown method %s.',method);
53 fhandle = __method__.(method);
56 if strcmp(method,'normalize')
57 warning("svg:Devel",["Not returning second output argument of %s" ...
58 " use method(obj) API to get it"],method);
61 if numel (idx) == 1 % can't access properties, only methods
63 error (method4field, class (obj), method, method);
67 if strcmp (idx(2).type, '()')
73 out = fhandle (obj, args{:});
80 error (typeNotImplemented,[method idx(2).type], class (obj));