-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodelLogicalParameter.m
69 lines (61 loc) · 2.23 KB
/
modelLogicalParameter.m
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
56
57
58
59
60
61
62
63
64
65
66
67
classdef modelLogicalParameter < modelParameter
%modelLogicalParameter A value which controls a model option in an on/off fashion.
% Logical inputs are accepted more flexibly than the other types, with
% integer 1, logical 1, or true for true and integer 0, logical 0, or
% false for false. The true and false options should be specified as
% such, not as strings in quotes. Unlike in general MATLAB logic,
% other nonzero numerical values are not accepted.
properties
default logical
minimum logical
maximum logical
value logical
end
methods
function p = modelLogicalParameter(cat, n, type, def)
%modelParameter Construct an instance of this class
% Detailed explanation goes here
if nargin < 4
error('Logical parameters must be defined with a category, name, type, and default.');
end
% The two parameters sent to the superclass are mostly
% handled there.
p@modelParameter(cat, n, type);
if ~strcmp(type, 'logical')
error('Integer parameters must be specified by name as integers.');
end
if islogical(def)
p.default = def;
elseif isinteger(def)
if def == 0
p.default = false;
elseif def == 1
p.default = true;
else
error('Logical inputs in numerical form must be 0 or 1.');
end
else
error('Default must be numeric or a MATLAB logical.')
end
p.value = p.default;
end
function obj = set(obj, v)
if islogical(v)
obj.value = v;
else
error('%s can only be set to a logical value!', obj.name);
end
end
function [v] = get(obj)
v = obj.value;
% fprintf('mLP returning %s %d\n', v, v);
end
function vs = asString(obj)
if obj.value
vs = 'true';
else
vs = 'false';
end
end
end
end