IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
code_props.m
Go to the documentation of this file.
1 %> @file
2 %> @ingroup codegen
3 %> @brief Generates code containing values of certain object properties
4 %>
5 %> Property names cna be specified with dots. In this case, properties will be
6 %> accessed within objects that are properties themselves.
7 %
8 %> @param obj Object
9 %> @param props Cell of property names with optional comments
10 %> @arg Format 1: {'property name', 'comment; ...}
11 %> @arg Format 2: {'property name', ...}
12 %> @param flag_alt=0 Alternative format to just paste on the properties section of code file
13 function s = code_props(obj, props, flag_alt)
14 
15 if nargin < 3
16  flag_alt = 0;
17 end;
18 
19 n = length(props);
20 flag_comments = n ~= numel(props);
21 
22 s_indent = iif(flag_alt, ' ', '');
23 s_comment = iif(flag_alt, '%>', '%');
24 s_o = iif(flag_alt, '', 'o.');
25 
26 s = '';
27 for i = 1:n
28  if flag_comments
29  s = cat(2, s, s_indent, s_comment, ' ', props{i, 2}, 10);
30  end;
31  s_p = iif(flag_comments, props{i, 1}, props{i});
32  ss = regexp(s_p, '\.', 'split');
33  p = obj;
34  for j = 1:numel(ss)
35  p = p.(ss{j});
36  end;
37  s = cat(2, s, s_indent, s_o, s_p, ' = ', convert_to_str(p), ';', 10);
38 end;
39