view m-toolbox/classes/@timespan/fromStruct.m @ 44:409a22968d5e default

Add unit tests
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 06 Dec 2011 18:42:11 +0100
parents f0afece42f48
children
line wrap: on
line source

% FROMSTRUCT creates from a structure a TIMESPAN object.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FUNCTION:    fromStruct
%
% DESCRIPTION: Creates from a structure a TIMESPAN object.
%
% CALL:        obj = fromStruct(obj, struct)
%
% VERSION:     $Id: fromStruct.m,v 1.7 2011/03/28 17:02:29 ingo Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function objs = fromStruct(objs, obj_struct)
  
  % Get the class name of the object.
  cn = class(objs);
  
  % Define function name for updating the structure
  fcnName = ([cn '.update_struct']);
  
  % Initialize output objects
  objs = feval([cn '.initObjectWithSize'], size(obj_struct, 1), size(obj_struct, 2));
  
  % Update structure (if necessary)
  for kk = 1:numel(obj_struct)
    
    % Get structure version
    if isfield(obj_struct, 'tbxver')
      tbxVer = obj_struct(kk).tbxver;
    else
      tbxVer = '1.0';
    end
    % Update structure
    up_struct = feval(fcnName, obj_struct(kk), tbxVer);
    
    % Call super-class
    objs(kk) = fromStruct@ltpda_uoh(objs(kk), up_struct);
    
    % Set 'startT' object
    if isfield(up_struct, 'startT')
      objs(kk).startT = utils.helper.getObjectFromStruct(up_struct.startT);
    end
    
    % Set 'endT' object
    if isfield(up_struct, 'endT')
      objs(kk).endT = utils.helper.getObjectFromStruct(up_struct.endT);
    end
    
    % Set 'interval' object
    if isfield(up_struct, 'interval')
      objs(kk).interval = up_struct.interval;
    end
    
  end
  
end