Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@helper/isSubclassOf.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 % ISSUBCLASSOF determines if the one class is a subclass of another | |
2 % | |
3 % CALL: | |
4 % res = isSubclassOf('class1', 'class2') | |
5 % res = isSubclassOf(metaObject, 'class2'); | |
6 % res = isSubclassOf(metaObject1, metaObject2); | |
7 % | |
8 % $Id: isSubclassOf.m,v 1.3 2011/04/29 15:02:17 ingo Exp $ | |
9 % | |
10 function res = isSubclassOf(varargin) | |
11 | |
12 if nargin ~= 2 | |
13 help(mfilename); | |
14 error('Incorrect inputs'); | |
15 end | |
16 | |
17 mo1 = getMetaObject(varargin{1}); | |
18 mo2 = getMetaObject(varargin{2}); | |
19 | |
20 if isempty(mo1) || isempty(mo2) | |
21 error('### One of the inputs is not a meta class object/name'); | |
22 end | |
23 | |
24 res = lt(mo1, mo2); | |
25 | |
26 end | |
27 | |
28 function obj = getMetaObject(in) | |
29 if ischar(in) | |
30 obj = meta.class.fromName(in); | |
31 elseif isa(in, 'meta.class') | |
32 obj = in; | |
33 else | |
34 error('Unknown input format for object of class %s', class(in)); | |
35 end | |
36 end | |
37 | |
38 function res = checkIsSubclass(mo1, mo2) | |
39 | |
40 res = false; | |
41 | |
42 % is the super class a user object subclass? | |
43 if strcmp(mo1.Name, mo2.Name) | |
44 res = true; | |
45 else | |
46 for kk=1:numel(mo1.SuperclassList) | |
47 mo = mo1.SuperclassList(kk); | |
48 | |
49 res = checkIsSubclass(mo, mo2); | |
50 if res | |
51 return; | |
52 else | |
53 % keep searching... | |
54 end | |
55 | |
56 end | |
57 end | |
58 end |