comparison m-toolbox/classes/+utils/@helper/getDefaultValue.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 % GETDEFAULTVALUE Returns the default value of a class property.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: Returns the default value of a class property if any default
5 % value is defined.
6 %
7 % CALL: dv = getDefaultValue(obj, prop);
8 %
9 % INPUTS: obj: LTPDA object or a class string
10 % prop: Property name of the class
11 %
12 % OUTPUTS: dv: Default value of the property.
13 %
14 % VERSION: $Id: getDefaultValue.m,v 1.1 2011/04/11 19:47:36 ingo Exp $
15 %
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17
18 function dv = getDefaultValue(obj, prop)
19
20 % Get the default value of the property from the meta data
21 if ischar(obj)
22 m = meta.class.fromName('smodel');
23 elseif isa(obj, 'ltpda_obj')
24 m = metaclass(obj);
25 else
26 error('### Unknown input. Please use: getDefaultValue(obj, prop)');
27 end
28
29 p = [m.Properties{:}];
30 idx = strcmp({p(:).Name}, prop) & [p.HasDefault];
31
32 if any(idx)
33 dv = p(idx).DefaultValue;
34 else
35 error('### Can not find any default value for the [%s] property of the [%s] class', prop, m.Name);
36 end
37
38 end