Home > classes > @ssm > copy.m

copy

PURPOSE ^

COPY Make copy of ssm objects depending of the second input

SYNOPSIS ^

function varargout = copy(varargin)

DESCRIPTION ^

 COPY Make copy of ssm objects depending of the second input
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: COPY Make copy of ssm objects depending of the second input

 CALL:        objs = copy(objs, [1,0]);
              objs = copy(objs); Second input is assumed to be 1

 VERSION:     $Id: copy.m,v 1.9 2008/08/21 19:47:36 adrien Exp $

 HISTORY:     07-08-2008 Grynagier - made second input facultative
              11-07-2008 Diepholz
                 Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % COPY Make copy of ssm objects depending of the second input
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: COPY Make copy of ssm objects depending of the second input
0005 %
0006 % CALL:        objs = copy(objs, [1,0]);
0007 %              objs = copy(objs); Second input is assumed to be 1
0008 %
0009 % VERSION:     $Id: copy.m,v 1.9 2008/08/21 19:47:36 adrien Exp $
0010 %
0011 % HISTORY:     07-08-2008 Grynagier - made second input facultative
0012 %              11-07-2008 Diepholz
0013 %                 Creation
0014 %
0015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0016 
0017 function varargout = copy(varargin)
0018   %% starting initial checks
0019 %   display(['--- starting ' mfilename ' ' num2str(varargin{2}) ' ---']);
0020 
0021   % Check if this is a call for parameters
0022   if utils.helper.isinfocall(varargin{:})
0023     varargout{1} = getInfo(varargin{3});
0024     return
0025   end
0026 
0027   % checking number of inputs work data
0028   if ~(nargin==1||nargin==2), error('wrong number of inputs!'), end
0029 
0030   if ~isequal(class(varargin{1}),'ssm'), error(['argument is not a ssm but a ', class(varargin{1})]),end
0031 
0032   %% begin function body
0033 
0034   % Collect all ssm objects
0035   old = utils.helper.collect_objects(varargin(:), 'ssm');
0036   deepcopy = varargin{end};
0037 
0038   if deepcopy
0039     prov = provenance;
0040     t0   = time;
0041     ps = properties('ssm');
0042     s = size(old);
0043     obj(s(1),s(2)) = ssm;
0044     for kk=1:numel(old)
0045       utils.helper.msg(utils.const.msg.OPROC2, 'copying %s', old(kk).name);
0046       for jj=1:length(ps)
0047         obj(kk).(ps{jj}) = old(kk).(ps{jj});
0048       end
0049       % These should be reset on copy
0050       obj(kk).created  = t0;
0051       obj(kk).creator  = prov;
0052       obj(kk).version  = ssm.VEROUT;
0053     end
0054   else
0055     obj = old;
0056   end
0057   varargout{1} = obj;
0058 
0059 end
0060 
0061 
0062 function ii = getInfo(varargin)
0063   if nargin == 1 && strcmpi(varargin{1}, 'None')
0064     sets = {};
0065     pls   = [];
0066   elseif nargin == 1 && ~isempty(varargin{1}) && ischar(varargin{1})
0067     sets{1} = varargin{1};
0068     pls = getDefaultPlist(sets{1});
0069   else
0070     sets = {'Default'};
0071     pls = [];
0072     for kk=1:numel(sets)
0073       pls = [pls getDefaultPlist(sets{kk})];
0074     end
0075   end
0076   % Build info object
0077   ii = minfo(mfilename, 'ssm', '', 'Internal', '$Id: copy.m,v 1.9 2008/08/21 19:47:36 adrien Exp $', sets, pls);
0078 end
0079 
0080 function out = getDefaultPlist(set)
0081   switch set
0082     case 'Default'
0083       out = plist;
0084     otherwise
0085       error('### Unknown set [%s] to get the default plist.', set);
0086   end
0087 end

Generated on Mon 25-Aug-2008 22:39:29 by m2html © 2003