view m-toolbox/classes/@paramValue/setProperty.m @ 40:977eb37f31cb database-connection-manager

User friendlier errors from utils.mysql.connect
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 18:04:03 +0100
parents f0afece42f48
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