diff m-toolbox/classes/@param/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 diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/@param/setProperty.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,37 @@
+% SETPROPERTY set a property to a parameter.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% DESCRIPTION: SETPROPERTY set a property to a parameter. If the property
+%              name exists then replace the value otherwise add this
+%              property.
+%
+% CALL:        obj = obj.setProperty(propertyName, val);
+%
+% INPUTS:      propertyName: Property name of the paramValue object
+%              value:        Value of the property
+%
+% VERSION:     $Id: setProperty.m,v 1.2 2011/02/22 15:53:12 hewitson Exp $
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function obj = setProperty(obj, propertyName, value)
+  
+  if nargin ~= 3
+    error('### This method works only with three inputs.');
+  end
+  
+  if ~isempty(obj.val)
+    obj = copy(obj, nargout);
+
+    % if the value is not a paramValue, we need to promote it before
+    % setting the property.
+    if ~isa(obj.val, 'paramValue')
+      obj.val = paramValue(1, {obj.val});
+    end
+    
+    obj.val.setProperty(propertyName, value);
+  else
+    error('### There is no value set! Therefore it is not possible to set for this value a property.')
+  end
+  
+end