comparison m-toolbox/classes/@ltpda_uoh/string.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 % STRING writes a command string that can be used to recreate the input object(s).
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: STRING writes a command string that can be used to recreate the
5 % input object(s).
6 %
7 % CALL: cmd = string(objs)
8 %
9 % <a href="matlab:utils.helper.displayMethodInfo('ltpda_uoh', 'string')">Parameters Description</a>
10 %
11 % VERSION: $Id: string.m,v 1.10 2011/04/08 08:56:30 hewitson Exp $
12 %
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
15 function varargout = string(varargin)
16
17 % Check if this is a call for parameters
18 if utils.helper.isinfocall(varargin{:})
19 varargout{1} = getInfo(varargin{3});
20 return
21 end
22
23 import utils.const.*
24 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
25
26 % Collect input variable names
27 in_names = cell(size(varargin));
28 for ii = 1:nargin,in_names{ii} = inputname(ii);end
29
30 % Collect all LTPDA_UOH objects and plists
31 objs = utils.helper.collect_objects(varargin(:), 'ltpda_uoh', in_names);
32
33 % Loop over LTPDAUOH objects
34 cmd = '[';
35 for j=1:numel(objs)
36 if isempty(objs(j).hist)
37 cmd = sprintf('%s%s(), ', cmd, class(objs(j)));
38 else
39 if isempty(objs(j).hist.plistUsed)
40 error('### this %s was not created with a plist. Can''t convert to string.', class(objs(j)));
41 end
42 if ~isempty(objs(j).hist.inhists)
43 error('### Can not run string on an object containing history. Use type() instead to rebuild objects with history.');
44 end
45 plstr = string(objs(j).hist.plistUsed);
46 cmd = sprintf('%s%s(%s), ', cmd, class(objs(j)), plstr);
47 end
48 end
49 cmd = [cmd(1:end-2) ']'];
50 if strcmp(cmd, '[]')
51 cmd = '';
52 end
53
54 % Set output
55 varargout{1} = cmd;
56 end
57
58 %--------------------------------------------------------------------------
59 % Get Info Object
60 %--------------------------------------------------------------------------
61 function ii = getInfo(varargin)
62 if nargin == 1 && strcmpi(varargin{1}, 'None')
63 sets = {};
64 pl = [];
65 else
66 sets = {'Default'};
67 pl = getDefaultPlist;
68 end
69 % Build info object
70 ii = minfo(mfilename, 'ltpda_uoh', 'ltpda', utils.const.categories.internal, '$Id: string.m,v 1.10 2011/04/08 08:56:30 hewitson Exp $', sets, pl);
71 ii.setModifier(false);
72 end
73
74 %--------------------------------------------------------------------------
75 % Get Default Plist
76 %--------------------------------------------------------------------------
77 function plout = getDefaultPlist()
78 persistent pl;
79 if exist('pl', 'var')==0 || isempty(pl)
80 pl = buildplist();
81 end
82 plout = pl;
83 end
84
85 function pl = buildplist()
86 pl = plist.EMPTY_PLIST;
87 end
88 % END
89