IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
classmap.m
Go to the documentation of this file.
1 %> @file
2 %>@ingroup introspection
3 %>
5 
6 %> @brief Scans IRootLab directories and build hierarchical class maps
7 classdef classmap < handle
8  properties
9  timestamp;
10  root;
11  end;
12 
13  methods(Static, Access=private)
14  %===============================================================================
15  % Copyright (C) 2003 Guillaume Flandin <Guillaume@artefact.tk>
16  % (extracted from m2html.m)
17  %
18  % changed to get files with "new." in the name
19  function mfiles = getmfiles(mdirs,mfiles,recursive)
20  %- Extract M-files from a list of directories and/or M-files
21 
22  for i=1:length(mdirs)
23  if exist(mdirs{i}) == 2 % M-file
24  mfiles{end+1} = mdirs{i};
25  elseif exist(mdirs{i}) == 7 % Directory
26  w = what(mdirs{i});
27  w = w(1); %- Sometimes an array is returned...
28  names = sort(w.m);
29  for j=1:length(names)
30  % if findstr('new.', w.m{j})
31  % mfiles{end+1} = fullfile(mdirs{i},w.m{j});
32  mfiles{end+1} = names{j};
33  % end;
34  end
35  if recursive
36  d = dir(mdirs{i});
37  d = {d([d.isdir]).name};
38  d = {d{~ismember(d,{'.' '..'})}};
39 % [vals, idxs] = sort(d);
40  d = sort(d);
41  for j=1:length(d)
42  mfiles = classmap.getmfiles(cellstr(fullfile(mdirs{i},d{j})),...
43  mfiles,recursive);
44  end
45  end
46  else
47  fprintf('Warning: Unprocessed file %s.\n',mdirs{i});
48  end
49  end;
50  end;
51 
52 
53  function res = find_item_by_name_(item, name)
54  res = [];
55  if strcmp(item.name, name)
56  res = item;
57  else
58  for i = 1:length(item.descendants)
59  res = classmap.find_item_by_name_(item.descendants(i), name);
60  if ~isempty(res)
61  break;
62  end;
63  end;
64  end;
65  end;
66 
67  end;
68 
69  methods
70  function o = classmap(o)
71  o.root = mapitem();
72  o.root.name = '?';
73  o.root.title = '?';
74  end;
75 
76 
77  % Classname needs be a subdirectory of the IRootLab root folder
78  function o = build(o, classname)
79 
80 
81  o.timestamp = now();
82  list = mapitem.empty;
83 
84 
85  files = classmap.getmfiles({fullfile(get_rootdir(), 'classes', classname)}, {}, 1);
86 
87 
88  cnt = 0;
89  for i = 1:length(files)
90  try
91  ss = textread(files{i}, '%s');
92  catch ME
93  disp('wtfwtfwtfwtfwtfwtfwtfwtfwtfwtfwtfwtfwtfwtfwtfwtfwtfwtfwtf');
94  end;
95  if ismember('classdef', ss)
96  disp([files{i} '...']);
97  try
98  obj = eval(files{i}(1:end-2));
99  % disp(obj);
100 
101 
102  if obj.flag_ui && isa(obj, classname)
103  temp = superclasses(obj);
104  name = class(obj);
105  oo = mapitem();
106  oo.name = name;
107  oo.color = obj.color;
108  oo.title = obj.classtitle;
109  oo.ancestor = temp{1};
110 
111  if isa(obj, 'block')
112  oo.input = obj.inputclass;
113  end;
114 
115 
116 
117  cnt = cnt+1;
118  list(cnt) = oo; % to organize later
119  names{cnt} = name; % to help find the classes
120 
121  if strcmp(list(cnt).name, classname)
122  o.root.descendants(end+1) = list(cnt);
123  end;
124  end;
125  catch ME
126  irverbose(['Failed mapping file ', files{i}(1:end-2), '!!!!!!!!!!!!!!!!!!!!!!'], 3);
127  rethrow(ME);
128  end;
129  end;
130  end;
131 
132 
133  for i = 1:length(list)
134  if ~strcmp(list(i).name, classname)
135  [val, idx] = find(strcmp(names, list(i).ancestor));
136  if (isempty(idx))
137  irerror(sprintf('Ancestor ''%s'' for class ''%s'' not found!', list(i).ancestor, list(i).name));
138  end;
139  % fprintf('********%s %d\n', list(i).ancestor, idx);
140  list(idx).descendants(end+1) = list(i);
141  list(i).parent = list(idx);
142  end;
143  end;
144  end;
145 
146 
147  function item = find_item_by_name(o, name)
148  item = classmap.find_item_by_name_(o.root, name);
149  end;
150  end;
151 end
function irverbose(in s, in level)
function classmap_compile()
function classmap_assert()
function irerror(in s)
Scans IRootLab directories and build hierarchical class maps.
Definition: classmap.m:7
function get_rootdir()
Map item.
Definition: mapitem.m:3