Home > dal > propertylist2struct.m

propertylist2struct

PURPOSE ^

PROPERTYLIST2STRUCT - Make options structure from parameter/value list

SYNOPSIS ^

function opt = propertylist2struct(varargin)

DESCRIPTION ^

 PROPERTYLIST2STRUCT - Make options structure from parameter/value list

   OPT = PROPERTYLIST2STRUCT('param1', VALUE1, 'param2', VALUE2, ...)
   Generate a structure OPT with fields 'param1' set to value VALUE1, field
   'param2' set to value VALUE2, and so forth.

   OPT has an additional field 'isPropertyStruct' that is meant to identify
   OPT is a structure containing options data. Only in the case of missing
   input arguments, no such identification field is written, that is,
   PROPERTYLIST2STRUCT() returns [].

   OPT2 = PROPERTYLIST2STRUCT(OPT1, 'param', VALUE, ...) takes the options
   structure OPT1 and adds new fields 'param' with according VALUE.

   See also SET_DEFAULTS

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function opt = propertylist2struct(varargin)
0002 % PROPERTYLIST2STRUCT - Make options structure from parameter/value list
0003 %
0004 %   OPT = PROPERTYLIST2STRUCT('param1', VALUE1, 'param2', VALUE2, ...)
0005 %   Generate a structure OPT with fields 'param1' set to value VALUE1, field
0006 %   'param2' set to value VALUE2, and so forth.
0007 %
0008 %   OPT has an additional field 'isPropertyStruct' that is meant to identify
0009 %   OPT is a structure containing options data. Only in the case of missing
0010 %   input arguments, no such identification field is written, that is,
0011 %   PROPERTYLIST2STRUCT() returns [].
0012 %
0013 %   OPT2 = PROPERTYLIST2STRUCT(OPT1, 'param', VALUE, ...) takes the options
0014 %   structure OPT1 and adds new fields 'param' with according VALUE.
0015 %
0016 %   See also SET_DEFAULTS
0017 %
0018 
0019 % Copyright Fraunhofer FIRST.IDA (2004)
0020 
0021 if nargin==0,
0022   % Return an empty struct without identification tag
0023   opt= [];
0024   return;
0025 end
0026 
0027 if isstruct(varargin{1}) | isempty(varargin{1}),
0028   % First input argument is already a structure: Start with that, write
0029   % the additional fields
0030   opt= varargin{1};
0031   iListOffset= 1;
0032 else
0033   % First argument is not a structure: Assume this is the start of the
0034   % parameter/value list
0035   opt = [];
0036   iListOffset = 0;
0037 end
0038 % Write the identification field. ID field contains a 'version number' of
0039 % how parameters are passed.
0040 opt.isPropertyStruct = 1;
0041 
0042 nFields= (nargin-iListOffset)/2;
0043 if nFields~=round(nFields),
0044   error('Invalid parameter/value list');
0045 end
0046 
0047 for ff= 1:nFields,
0048   fld = varargin{iListOffset+2*ff-1};
0049   if ~ischar(fld),
0050     error(sprintf('String required on position %i of the parameter/value list', ...
0051                   iListOffset+2*ff-1));
0052   end
0053   prp= varargin{iListOffset+2*ff};
0054   opt= setfield(opt, fld, prp);
0055 end
0056 
0057 
0058 
0059

Generated on Sat 22-Aug-2009 22:15:36 by m2html © 2003