IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
mapitem.m
Go to the documentation of this file.
1 %> @ingroup introspection
2 %> @brief Map item
3 classdef mapitem < handle
4  properties
5  %> (String) Item corresponding class name
6  name;
7  %> (3-element vector) Item's color
8  color;
9  %> (String) Class title (classtitle property of corresponding class)
10  title;
11  %> (String) Input class (inputclass property of correspondign class)
12  input;
13  %> Array of mapitem objects
14  descendants = mapitem.empty;
15  %> (String) Name of ancestor class
16  ancestor;
17  %> Parent object
18  parent;
19 
20  %> Level of item in the class map tree it belongs to
21  level;
22  %> Whether the item is a leaf in the map tree it belongs to
23  flag_final = 0;
24 
25  %> Used when item is converted to list
26  index;
27  %> Used when item is converted to list
28  parentindex;
29 
30 
31  end;
32 
33 
34  methods(Static, Access=private)
35  function [l, flag, index] = to_list_(item, inputobj, level, index, parentindex)
36  flag = 0;
37  no_desc = length(item.descendants);
38  if no_desc == 0
39  flag = isempty(inputobj);
40  if ~flag
41  if ~iscell(item.input)
42  flag = isa(inputobj, item.input);
43  else
44  for i = 1:length(item.input)
45  if isa(inputobj, item.input{i});
46  flag = 1;
47  break;
48  end;
49  end;
50  end;
51  end;
52 
53  if flag
54  temp = copy_obj(item);
55  temp.flag_final = 1;
56  temp.level = level;
57  temp.index = index;
58  temp.parentindex = parentindex;
59  index = index+1;
60 
61  l = temp;
62  else
63  l = mapitem.empty;
64  end;
65  else
66  l = mapitem.empty;
67  for i = 1:no_desc
68  if ~flag
69  index_temp = index+1; % Reserves 1 for current item
70  parentindex_temp = index;
71  else
72  index_temp = index;
73  parentindex_temp = indexpow;
74  end;
75 
76  [ltemp, flag_temp, index_] = mapitem.to_list_(item.descendants(i), inputobj, level+1, index_temp, parentindex_temp);
77  if flag_temp
78  if ~flag % first descendant
79  temp = copy_obj(item);
80  temp.flag_final = 0;
81  temp.level = level;
82  temp.index = index;
83  indexpow = index;
84  temp.parentindex = parentindex;
85  l = [l temp];
86  flag = 1;
87  end;
88 
89  index = index_;
90  l = [l, ltemp];
91  end;
92  end;
93 
94  if flag
95  end;
96  end;
97  end;
98 
99  end;
100 
101  methods
102  %> @brief Builds an array containing only the items that accept the inputclass
103  %> @return Array of mapitem objects
104  function l = to_list(o, inputclass)
105  if ~exist('inputclass', 'var') || isempty(inputclass)
106  inputobj = [];
107  else
108  % Instantializes object of inputclass to have access to its superclasses
109  inputobj = eval([inputclass, ';']);
110  end;
111  [l, flag] = mapitem.to_list_(o, inputobj, 1, 1, 0);
112  end;
113 
114 
115  %> @brief generates tree in HTML
116  %>
117  %> @param inputclass Same case as in @ref to_list()
118  function s = to_html(o, inputclass)
119  if ~exist('inputclass', 'var') || isempty(inputclass)
120  inputobj = [];
121  else
122  % Instantializes object of inputclass to have access to its superclasses
123  inputobj = eval([inputclass, ';']);
124  end;
125  [l, flag] = mapitem.to_list_(o, inputobj, 1, 1, 0);
126  l = l(2:end);
127 
128  s = ['<table><tr>', 10, ...
129  '<td style="text-align: centre">Class Name</td>', 10, ...
130  '<td style="text-align: centre">Class Title</td>', 10, ...
131  '<td style="text-align: centre">Complete descent</td>', 10, ...
132  '</tr>', 10];
133 
134 
135  function ss = close(n)
136  ss = '';
137  for j = 1:n
138  ss = cat(2, ss, '</ul>');
139  end;
140  ss = cat(2, ss, 10);
141  end
142 
143  function ss = open(n)
144  ss = '';
145  for j = 1:n
146  ss = cat(2, ss, '<ul>');
147  end;
148  ss = cat(2, ss, 10);
149  end
150 
151 
152  i_level = 0;
153  for i = 1:numel(l)
154  if (l(i).level > i_level)
155 % s = cat(2, s, open(1));
156  elseif (l(i).level < i_level)
157 % s = cat(2, s, close(i_level-l(i).level));
158  end;
159  indent = [repmat('&nbsp;', 1, (l(i).level-1)*3), '<span style="background-color: #', color2hex(l(i).color), '">&nbsp;&nbsp;&nbsp;</span>&nbsp;'];
160  try
161  obj = eval([l(i).name, '();']);
162  catch ME
163  irverbose(sprintf('Error creating instance of class "%s"', l(i).name));
164  rethrow(ME);
165  end;
166  s = cat(2, s, '<tr><td>', indent, l(i).name, '</td><td>', indent, l(i).title, '</td>', ...
167  '<td>', obj.get_ancestry(1), '</td>', '</tr>', 10);
168  i_level = l(i).level;
169  end;
170  s = cat(2, s, '</table>');
171 % s = cat(2, s, close(i_level));
172  end;
173  end;
174 end
Map item.
Definition: mapitem.m:3