KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
object2str.m
Go to the documentation of this file.
1 
2 
3 /* (Autoinserted by mtoc++)
4  * This source code has been filtered by the mtoc++ executable,
5  * which generates code that can be processed by the doxygen documentation tool.
6  *
7  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
8  * Except for the comments, the function bodies of your M-file functions are untouched.
9  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
10  * attached source files that are highly readable by humans.
11  *
12  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
13  * the correct locations in the source code browser.
14  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
15  */
16 
17 function str = object2str(handle obj,integer maxdepth) {
18 
19 
20 if ~isobject(obj)
21  error(" The obj argument has to be a matlab object. ");
22 end
23 if nargin < 2
24  maxdepth = Inf; /* Default: Inf depth */
25 
26 elseif ~isnumeric(maxdepth) || ~isreal(maxdepth)
27  error(" maxdepth has to be a real value/integer. ");
28 end
29 sizelbl = [" G "," M "," k "," b "];
30 [str, bytes] = recursive2str(obj, maxdepth, 0, []);
31 
32  function [str, bytes] = recursive2str(obj, depth, numtabs, done)
33  /* Internal recursion. */
34  str = ;
35  if depth == 0
36  bytes = 0;
37  return;
38  end
39  done[end+1] = obj;
40  mc = metaclass(obj);
41  if isfield(obj," Name ")
42  name = obj.Name;
43  else
44  name = mc.Name;
45  end
46  if ~isempty(str)
47  str = [str " %s: " name " \n "];
48  else
49  str = [name " %s:\n "];
50  end
51  /* get string cell of names and sort alphabetically */
52  names = cellfun(@(mp)mp.Name,mc.Properties," UniformOutput ",false);
53  [~, sortedidx] = sort(names);
54  bytes = 0; subbytes = 0;
55  for n = 1:length(sortedidx)
56  idx = sortedidx(n);
57  p = mc.Properties[idx];
58  addbytes = 0;
59  if strcmp(p.GetAccess," public ")
60  str = [str repmat(" \t ",1,numtabs) " . "]; /* #ok<*AGROW> */
61 
62  pobj = obj.(p.Name);
63  if ~isempty(pobj) && ~any(cellfun(@(el)isequal(pobj,el),done))
64  /* Pre-compute addbytes and only override if pobj is object itself */
65  tmp = whos(" pobj ");
66  addbytes = tmp.bytes;
67  if isobject(pobj)
68  [recstr, addbytes] = recursive2str(pobj, depth-1, numtabs+1, done);
69  subbytes = subbytes + addbytes;
70  str = [str p.Name " - " recstr];
71  elseif isnumeric(pobj)
72  if numel(pobj) > 20
73  sizestr = getSizeStr(addbytes);
74  if ~isempty(sizestr)
75  sizestr = [" ( " sizestr " ) "];
76  end
77  spar = ;
78  if issparse(pobj)
79  spar = " sparse ";
80  end
81  str = [str p.Name " : [ " num2str(size(pobj)) " ] " spar class(pobj) sizestr];
82  else
83  pobj = reshape(pobj,1,[]);
84  str = [str p.Name " : " num2str(pobj)];
85  end
86  elseif isstruct(pobj)
87  if any(size(pobj) > 1)
88  str = [str p.Name " (struct, [ " num2str(size(pobj)) " ]), fields: "];
89  else
90  str = [str p.Name " (struct), fields: "];
91  end
92  fn = fieldnames(pobj);
93  for fnidx = 1:length(fn)
94  str = [str fn[fnidx] " , "];
95  end
96  str = str(1:end-1);
97  elseif isa(pobj," function_handle ")
98  str = [str p.Name " (f-handle): " func2str(pobj)];
99  elseif ischar(pobj)
100  str = [str p.Name " : " pobj];
101  elseif islogical(pobj)
102  if pobj
103  str = [str p.Name " : true "];
104  else
105  str = [str p.Name " : false "];
106  end
107  elseif iscell(pobj)
108  str = [str sprintf(" %s: %dx%d cell<%s> ", p.Name, size(pobj,1),size(pobj,2),class(pobj[1]))];
109  else
110  str = [str p.Name " : ATTENTION. Display for type ' " class(pobj) " ' not implemented yet. "];
111  end
112  else
113  if isequal(obj,pobj)
114  str = [str p.Name " : [self-reference] "];
115  else
116  str = [str p.Name " : empty "];
117  end
118  end
119  str = [str " \n "];
120  end
121  bytes = bytes + addbytes;
122  end
123 
124  /* Take away the last \n for inner recursive calls */
125  if depth < maxdepth
126  str = str(1:end-2);
127  end
128 
129  /* Format!
130  * Add byte information */
131  if subbytes > 0
132  sizestr = sprintf(" (self:%s, childs:%s, total:%s) ",...
133  getSizeStr(bytes-subbytes),getSizeStr(subbytes),getSizeStr(bytes));
134  else
135  sizestr = sprintf(" (%s) ",getSizeStr(bytes));
136  end
137  str = sprintf(str,sizestr);
138 
139  function res = getSizeStr(bytes)
140  hr = bytes ./ [1024^3 1024^2 1024 1];
141  pos = find(hr > 1,1);
142  res = ;
143  if ~isempty(pos)
144  res = sprintf(" %.5g%s ",hr(pos),sizelbl[pos]);
145  end
146  end
147  end
148 end
149 }
An integer value.
Matlab's base handle class (documentation generation substitute)
function str = object2str(handle obj,integer maxdepth)
object2str: Generic matlab object to string converter.
Definition: object2str.m:17