Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@helper/generic_getInfo.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % GENERIC_GETINFO generic version of the getInfo function | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: GENERIC_GETINFO generic version of the getInfo function | |
5 % | |
6 % CALL: ii = generic_getInfo(varargin{:}, 'class_name'); | |
7 % | |
8 % INPUTS: varargin: Function inputs of the class version of getInfo | |
9 % class_name: Class name which calls this function. | |
10 % | |
11 % OUTPUT: minfo-class of the method | |
12 % | |
13 % EXAMPLES: Constructor call to get all sets | |
14 % specwin.getInfo() | |
15 % specwin.getInfo('specwin') | |
16 % specwin.getInfo('specwin', '') | |
17 % | |
18 % Constructor call to get a specified set | |
19 % specwin.getInfo('specwin', 'None') | |
20 % specwin.getInfo('specwin', 'set') | |
21 % | |
22 % Call for the methods in a class | |
23 % specwin.getInfo('char') | |
24 % specwin.getInfo('char', 'None') | |
25 % | |
26 % VERSION: $Id: generic_getInfo.m,v 1.7 2011/03/28 12:45:45 hewitson Exp $ | |
27 % | |
28 % HISTORY: 24-07-2008 Diepholz | |
29 % Creation. | |
30 % | |
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
32 | |
33 function ii = generic_getInfo(varargin) | |
34 | |
35 class_name = varargin{end}; | |
36 | |
37 verout = feval(sprintf('%s.VEROUT', class_name)); | |
38 sets = feval(sprintf('%s.SETS', class_name)); | |
39 | |
40 if nargin == 1 || ... | |
41 (nargin == 2 && strcmp(varargin{1}, class_name)) || ... | |
42 (nargin == 3 && strcmp(varargin{1}, class_name) && isempty(varargin{2})) | |
43 | |
44 %%%%%%%%%% Get the minfo-object for the Constructor | |
45 %%% specwin.getInfo() | |
46 %%% specwin.getInfo('specwin') | |
47 %%% specwin.getInfo('specwin', '') | |
48 if ~isempty(sets) | |
49 pls(1:numel(sets)) = plist(); | |
50 for kk = 1:numel(sets) | |
51 cmd = sprintf('%s.getDefaultPlist', class_name); | |
52 pls(kk) = feval(cmd, sets{kk}); | |
53 end | |
54 else | |
55 pls = plist; | |
56 end | |
57 ii = minfo(class_name, class_name, 'ltpda', 'Constructor', verout, sets, pls); | |
58 ii.setModifier(false); | |
59 ii.setArgsmin(0); | |
60 ii.setArgsmax(-1); | |
61 ii.setOutmin(1); | |
62 ii.setOutmax(1); | |
63 | |
64 elseif nargin == 3 && (strcmp(varargin{1}, class_name)) | |
65 | |
66 %%%%%%%%%% Get the minfo-object for the Constructor with a specified set | |
67 %%% specwin.getInfo('specwin', 'None') | |
68 %%% specwin.getInfo('specwin', 'set') | |
69 if strcmpi(varargin{2}, 'None') | |
70 sets = {}; | |
71 pls = []; | |
72 else | |
73 sets = cellstr(varargin{2}); | |
74 cmd = sprintf('%s.getDefaultPlist', class_name); | |
75 pls = feval(cmd, varargin{2}); | |
76 end | |
77 | |
78 ii = minfo(class_name, class_name, 'ltpda', 'Constructor', verout, sets, pls); | |
79 ii.setModifier(false); | |
80 else | |
81 | |
82 %%%%%%%%%% Get the minfo-object for the class methods | |
83 %%% specwin.getInfo('char') | |
84 %%% specwin.getInfo('char', 'None') | |
85 if nargin == 2 | |
86 sets = ''; | |
87 elseif nargin == 3 | |
88 sets = varargin{2}; | |
89 end | |
90 | |
91 try | |
92 obj = eval([class_name '.initObjectWithSize(0,0)']); | |
93 % obj = feval(class_name); | |
94 catch | |
95 cls = utils.helper.ltpda_classes; | |
96 for jj=1:numel(cls) | |
97 cl = cls{jj}; | |
98 meta = eval(['?', cl]); | |
99 | |
100 scls = getSuperClasses ({}, meta); | |
101 if any(strcmp(class_name, scls)) && ismethod(cl, varargin{1}) | |
102 try | |
103 obj = feval(cl); | |
104 break | |
105 end | |
106 end | |
107 end | |
108 % error('### From the abstract class [%s] it is only possible to get the minfo class from the constructor.', class_name); | |
109 end | |
110 ii = feval(varargin{1}, obj, 'INFO', sets); | |
111 end | |
112 | |
113 % check we got an minfo object | |
114 if ~isa(ii, 'minfo') | |
115 error('### An minfo object was not retrieved.'); | |
116 end | |
117 end | |
118 | |
119 function scls = getSuperClasses (scls, meta) | |
120 | |
121 if ~isempty(meta.SuperClasses) | |
122 | |
123 scl = [meta.SuperClasses{:}]; | |
124 scls = [scls, {scl(:).Name}]; | |
125 | |
126 for ii = 1:numel(meta.SuperClasses) | |
127 scls = getSuperClasses(scls, meta.SuperClasses{1}); | |
128 end | |
129 end | |
130 | |
131 end | |
132 |