view m-toolbox/classes/@paramValue/setProperty.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
line wrap: on
line source

% SETPROPERTY set a property to a paramValue
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: SETPROPERTY set a property to a paramValue. If the property
%              name exists then replace the value otherwise add this
%              property.
%
% CALL:        obj = obj.setProperty(propertyName, value);
%
% INPUTS:      propertyName: Property name of the paramValue object
%              value:        Value of the property
%
% VERSION:     $Id: setProperty.m,v 1.2 2010/09/28 17:49:27 ingo Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function obj = setProperty(obj, propertyName, value)
  
  if nargin ~= 3
    error('### This method works only with three inputs.');
  end
  
  obj = copy(obj, nargout);

  if isempty(obj.property)
    % ATTENTION: It is necessary for the STRUCT method to use a different
    %            command if the value is a cell.
    if iscell(value)
      obj.property = struct(propertyName, {value});
    else
      obj.property = struct(propertyName, value);
    end
  else
    obj.property.(propertyName) = value;
  end
  
end