comparison m-toolbox/classes/+utils/@prog/rstruct.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % RSTRUCT recursively converts an object into a structure.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % RSTRUCT recursively converts an object into a structure. This is the same
4 % behaviour as MATLAB's struct(obj) except that it recursively converts all
5 % sub-objects into structures as well.
6 %
7 % >> s = utils.prog.rstruct(obj)
8 %
9 % M Hewitson 02-06-07
10 %
11 % $Id: rstruct.m,v 1.14 2011/05/04 05:03:44 mauro Exp $
12 %
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
15 function varargout = rstruct(varargin)
16
17 s = {};
18 n = 1;
19 for jj = 1:nargin
20 objs = varargin{1};
21 for k = 1:numel(objs)
22 obj = objs(k);
23 if isa(obj, 'ltpda_obj')
24 s{n}.class = class(obj);
25 s{n}.tbxver = strtok(getappdata(0, 'ltpda_version'));
26 names = getFieldnames(obj);
27 for nn=names
28 fname = char(nn);
29 if isa(obj.(fname), 'ltpda_obj')
30 s{n}.(fname) = utils.prog.rstruct(obj.(fname));
31 elseif isobject(obj.(fname))
32 s{n}.(fname) = struct(obj.(fname));
33 else
34 s{n}.(fname) = obj.(fname);
35 end
36 end
37 n = n + 1;
38 end
39 end
40 end
41
42 s = [s{:}];
43
44 % Reshape the struct to the shape of the input objects
45 s = reshape(s, size(objs));
46
47 % Set output
48 varargout{1} = s;
49
50 end
51
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %
54 % FUNCTION: getFieldnames
55 %
56 % DESCRIPTION: Returns the field names which should be stored in a XML file.
57 %
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 function fields = getFieldnames(obj)
60 meta = eval(['?' class(obj)]);
61 metaProp = [meta.Properties{:}];
62 props = {metaProp(:).Name};
63 propGetAccess = strcmpi({metaProp(:).GetAccess}, 'public');
64 propDependent = [metaProp(:).Dependent];
65 fields = props(propGetAccess & ~propDependent);
66 end
67
68