-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperations.m
128 lines (107 loc) · 3.14 KB
/
Operations.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
classdef Operations
% One-line description here, please.
%
% Enumeration Operations
%
% Example
% % Retrieve an Operation from its name
% op = Operations.fromName('FirstOp');
% op =
% Operations enumeration
% FirstOp
%
% % Retrieve an Operation from its label
% op = Operations.fromLabel('User-defined Operation')
% op =
% Operations enumeration
% UserOp
%
% See also
% newEnum
% ------
% Author: David Legland
% e-mail: [email protected]
% Created: 2020-12-11, using Matlab 9.8.0.1323502 (R2020a)
% Copyright 2020 INRAE - BIA-BIBS.
%% Enumerates the different cases
enumeration
FirstOp('First Operation');
SecondOp('Second Operation');
UserOp('User-Defined Operation');
end % end properties
%% Static methods
methods (Static)
function res = allNames()
% Returns a cell list with all enumeration names.
mc = ?Operations;
itemList = mc.EnumerationMemberList;
nItems = length(itemList);
res = cell(1, nItems);
for i = 1:nItems
% retrieve current enumeration item
mitem = itemList(i);
res{i} = mitem.Name;
end
end
function res = fromName(name)
% Identifies a Operations from its name.
if nargin == 0 || ~ischar(name)
error('requires a character array as input argument');
end
mc = ?Operations;
itemList = mc.EnumerationMemberList;
for i = 1:length(itemList)
% retrieve current enumeration item
mitem = itemList(i);
item = Operations.(mitem.Name);
if strcmpi(name, char(item))
res = item;
return;
end
end
error('Unrecognized Operations name: %s', name);
end
function res = allLabels()
% Returns a cell list with all enumeration names.
mc = ?Operations;
itemList = mc.EnumerationMemberList;
nItems = length(itemList);
res = cell(1, nItems);
for i = 1:nItems
% retrieve current enumeration item
mitem = itemList(i);
item = Operations.(mitem.Name);
res{i} = item.Label;
end
end
function res = fromLabel(label)
% Identifies a Operations from its label.
if nargin == 0 || ~ischar(label)
error('requires a character array as input argument');
end
mc = ?Operations;
itemList = mc.EnumerationMemberList;
for i = 1:length(itemList)
% retrieve current enumeration item
mitem = itemList(i);
item = Operations.(mitem.Name);
if strcmpi(label, item.Label)
res = item;
return;
end
end
error('Unrecognized Operations label: %s', label);
end
end % end methods
%% Constructor
methods
function obj = Operations(label, varargin)
% Constructor for Operations class.
obj.Label = label;
end
end % end constructors
%% Properties
properties
Label;
end % end properties
end % end classdef