Home > m > helper > generic_class_fcn > generic_set.m

generic_set

PURPOSE ^

SET set a property of a general object.

SYNOPSIS ^

function objs = generic_set(objs, propArgin, DEFAULT_PLIST, VERSION, CATEGORY)

DESCRIPTION ^

 SET set a property of a general object.

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

 DESCRIPTION: SET set a property of a general object.

 CALL:        objs = get(objs, 'prop_name', value);

 VERSION:     $Id: generic_set.html,v 1.7 2008/03/31 10:27:45 hewitson Exp $

 HISTORY:     11-02-2008 Diepholz
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % SET set a property of a general object.
0002 %
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 % DESCRIPTION: SET set a property of a general object.
0006 %
0007 % CALL:        objs = get(objs, 'prop_name', value);
0008 %
0009 % VERSION:     $Id: generic_set.html,v 1.7 2008/03/31 10:27:45 hewitson Exp $
0010 %
0011 % HISTORY:     11-02-2008 Diepholz
0012 %                 Creation
0013 %
0014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0015 function objs = generic_set(objs, propArgin, DEFAULT_PLIST, VERSION, CATEGORY)
0016 
0017 %%% REMARK: The classes
0018 %%%             ao,
0019 %%%             cdata,
0020 %%%             pole,
0021 %%%             time,
0022 %%%             timeformat,
0023 %%%             timespan,
0024 %%%             zero,
0025 %%%         don't use this generic function.
0026 
0027 fields = fieldnames(objs);
0028 
0029 %%% Plausibility check: The default parameter list must contain all fieldnames
0030 if length(fields) ~= nparams(DEFAULT_PLIST)
0031   error('\n### The DEFAULT_PLIST doesn''t contain all field names of the %s-class!', class(objs));
0032 end
0033 
0034 %%% Check if this is a special call: default parameter list, cvs-version, category
0035 if length(propArgin) == 1 && ischar(propArgin{1})
0036   in = propArgin;
0037   if strcmp(in, 'Params')
0038     objs = DEFAULT_PLIST;
0039     return
0040   elseif strcmp(in, 'Version')
0041     objs = VERSION;
0042     return
0043   elseif strcmp(in, 'Category')
0044     objs = CATEGORY;
0045     return
0046   end
0047 end
0048 
0049 if isempty(propArgin)
0050   propArgin = {plist()};
0051 end
0052 
0053 if nargin >= 2 && isa(propArgin{1}, 'plist')
0054   pl        = propArgin{1};
0055   propArgin = {};
0056   for ii = 1:nparams(pl)
0057     %%% The 'key' name of a plist/param is always stored with upper case
0058     %%% characters. To set a ao property with this key we have to lower the
0059     %%% 'key' characters.
0060     propArgin{end+1} = lower(pl.params(ii).key);
0061     propArgin{end+1} =       pl.params(ii).val;
0062   end
0063 end
0064 
0065 while length(propArgin) >= 2
0066 
0067   prop      = propArgin{1};
0068   val       = propArgin{2};
0069   propArgin = propArgin(3:end);
0070 
0071   %%% For all objects
0072   for jj = 1:numel(objs)
0073     try
0074       objs(jj).(prop) = val;
0075     catch
0076       error('### ''%s'' is not a valid %s-object property.', prop, class(objs));
0077     end
0078 
0079   end
0080 end
0081

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003