Home > classes > @plist > plist.m

plist

PURPOSE ^

PLIST Plist class object constructor.

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 PLIST Plist class object constructor.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: PLIST Parameter-List Object class object constructor.
              Create a plist object.

 SUPER CLASSES: ltpda_uo < ltpda_obj

 PROPERTIES:

     Inherit Properties (read only)
       name     - name of object
       created  - creation time (time-object)
       prov     - contains a instance of the provenance class.
       hist     - history of the object (history object)
       version  - cvs-version string.

     Protected Properties (read only)
       params   - list of param-objects

 PLIST METHODS:

     Defined Abstract methods:
       char          - returns one character string which represents the object
       copy          - copies an object
       display       - displays an object
       string        - converts an object to a command string which will
                       recreate the plist object.
       update_struct - updates a object structure to the current tbx-version

     Public methods:
       append   - append a param-object, plist-object or a key/value pair to
                  the parameter list.
       combine  - combine multiple parameter lists (plist objects) into a
                  single plist.
       find     - Returns the value corresponding to the first parameters in
                  the list with search-key.
       isparam  - look for a given key in the parameter lists.
       nparams  - returns the number of param objects in the list.
       pset     - set or add a key/value pairor a param-object into
                  the parameter list.
       pzmresp  - shadow function for the pzmodel/resp.
       remove   - remove a parameter from the parameter list.
       resp     - shadows miir/iirResp and pzmodel/resp.

 CONSTRUCTORS:

       pl = plist()                  - create an empty plist object.
       pl = plist(p)                 - create a plist with elements p
                                       where p is an array of param objects.
       pl = plist('key', val)        - create a plist with the key/value pair
       pl = plist('key1',  val1, ... - create a plist with more key/value pairs
                  'key2', 'val2')
       pl = plist('file.xml')        - load a plist-object from xml-file
       pl = plist('file.mat')        - load a plist-object from mat-file
       pl = plist(pl)                - copies the input plist.

 PARAMETERS:

  If no recognised parameters are found in the input plist, the input
  plist is simply returned. This is the copy constructor.

  'Hostname' - construct a plist by retrieving it from an LTPDA repository
               specified by the given hostname. Only those objects which
               are plists are returned.
               Additional parameters:
               'Database'   - The database name [default: 'ltpda']
               'ID'         - A vector of object IDs.
               'CID'        - Retrieve all plists from a particular
                              collection.

 M-FILE INFO:  The following call returns an minfo object that contains
               information about the plist constructor:
                    >> info = plist.getInfo
               or   >> info = plist.getInfo('plist')

               You can get information about class methods by calling:
                    >> info = plist.getInfo(method)
               e.g. >> info = plist.getInfo('eq')

               You can also restrict the sets of parameters contained in
               the minfo object by calling:
                    >> info = plist.getInfo(method, set)
               e.g. >> info = plist.getInfo('plist', 'Default')

 VERSION:      $Id: plist.m,v 1.51 2008/09/07 18:15:26 hewitson Exp $

 HISTORY:      30-01-07 M Hewitson
                  Creation

 SEE ALSO:     ltpda_obj, ltpda_uo, param

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % PLIST Plist class object constructor.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: PLIST Parameter-List Object class object constructor.
0005 %              Create a plist object.
0006 %
0007 % SUPER CLASSES: ltpda_uo < ltpda_obj
0008 %
0009 % PROPERTIES:
0010 %
0011 %     Inherit Properties (read only)
0012 %       name     - name of object
0013 %       created  - creation time (time-object)
0014 %       prov     - contains a instance of the provenance class.
0015 %       hist     - history of the object (history object)
0016 %       version  - cvs-version string.
0017 %
0018 %     Protected Properties (read only)
0019 %       params   - list of param-objects
0020 %
0021 % PLIST METHODS:
0022 %
0023 %     Defined Abstract methods:
0024 %       char          - returns one character string which represents the object
0025 %       copy          - copies an object
0026 %       display       - displays an object
0027 %       string        - converts an object to a command string which will
0028 %                       recreate the plist object.
0029 %       update_struct - updates a object structure to the current tbx-version
0030 %
0031 %     Public methods:
0032 %       append   - append a param-object, plist-object or a key/value pair to
0033 %                  the parameter list.
0034 %       combine  - combine multiple parameter lists (plist objects) into a
0035 %                  single plist.
0036 %       find     - Returns the value corresponding to the first parameters in
0037 %                  the list with search-key.
0038 %       isparam  - look for a given key in the parameter lists.
0039 %       nparams  - returns the number of param objects in the list.
0040 %       pset     - set or add a key/value pairor a param-object into
0041 %                  the parameter list.
0042 %       pzmresp  - shadow function for the pzmodel/resp.
0043 %       remove   - remove a parameter from the parameter list.
0044 %       resp     - shadows miir/iirResp and pzmodel/resp.
0045 %
0046 % CONSTRUCTORS:
0047 %
0048 %       pl = plist()                  - create an empty plist object.
0049 %       pl = plist(p)                 - create a plist with elements p
0050 %                                       where p is an array of param objects.
0051 %       pl = plist('key', val)        - create a plist with the key/value pair
0052 %       pl = plist('key1',  val1, ... - create a plist with more key/value pairs
0053 %                  'key2', 'val2')
0054 %       pl = plist('file.xml')        - load a plist-object from xml-file
0055 %       pl = plist('file.mat')        - load a plist-object from mat-file
0056 %       pl = plist(pl)                - copies the input plist.
0057 %
0058 % PARAMETERS:
0059 %
0060 %  If no recognised parameters are found in the input plist, the input
0061 %  plist is simply returned. This is the copy constructor.
0062 %
0063 %  'Hostname' - construct a plist by retrieving it from an LTPDA repository
0064 %               specified by the given hostname. Only those objects which
0065 %               are plists are returned.
0066 %               Additional parameters:
0067 %               'Database'   - The database name [default: 'ltpda']
0068 %               'ID'         - A vector of object IDs.
0069 %               'CID'        - Retrieve all plists from a particular
0070 %                              collection.
0071 %
0072 % M-FILE INFO:  The following call returns an minfo object that contains
0073 %               information about the plist constructor:
0074 %                    >> info = plist.getInfo
0075 %               or   >> info = plist.getInfo('plist')
0076 %
0077 %               You can get information about class methods by calling:
0078 %                    >> info = plist.getInfo(method)
0079 %               e.g. >> info = plist.getInfo('eq')
0080 %
0081 %               You can also restrict the sets of parameters contained in
0082 %               the minfo object by calling:
0083 %                    >> info = plist.getInfo(method, set)
0084 %               e.g. >> info = plist.getInfo('plist', 'Default')
0085 %
0086 % VERSION:      $Id: plist.m,v 1.51 2008/09/07 18:15:26 hewitson Exp $
0087 %
0088 % HISTORY:      30-01-07 M Hewitson
0089 %                  Creation
0090 %
0091 % SEE ALSO:     ltpda_obj, ltpda_uo, param
0092 %
0093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0094 
0095 classdef plist < ltpda_uo
0096 
0097   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0098   %                            Property definition                            %
0099   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0100 
0101   %---------- Public (read/write) Properties  ----------
0102   properties
0103   end
0104 
0105   %---------- Protected read-only Properties ----------
0106   properties (SetAccess = protected)
0107     params   = [];
0108   end
0109 
0110   %---------- Protected Properties ----------
0111   properties (SetAccess = protected)
0112     version = '$Id: plist.m,v 1.51 2008/09/07 18:15:26 hewitson Exp $';
0113   end
0114 
0115   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0116   %                          Check property setting                           %
0117   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0118 
0119 
0120   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0121   %                                Constructor                                %
0122   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0123 
0124   methods
0125     function pl = plist(varargin)
0126 
0127       import utils.const.*
0128       utils.helper.msg(msg.OMNAME, 'running %s/%s', mfilename('class'), mfilename);
0129 
0130       %%% Call superclass
0131       pl = pl@ltpda_uo(varargin{:});
0132 
0133       %%%%%%%%%%   Set dafault values   %%%%%%%%%%
0134 
0135       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0136       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%   no input   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0137       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0138 
0139       %%%%%%%%%%   pl = plist()   %%%%%%%%%%
0140       % create default parameter list object
0141       if nargin == 0
0142         utils.helper.msg(msg.OPROC1, 'empty constructor');
0143       elseif nargin == 1
0144 
0145         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0146         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%   one input   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0147         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0148 
0149         %%%%%%%%%%  p = param(plist)   %%%%%%%%%%
0150         if isa(varargin{1}, 'plist')
0151           pli = varargin{1};
0152 
0153           %%% if the plist is empty then return an empty plist object
0154           if isempty(varargin{1}.params)
0155           else
0156 
0157             % Retrieve from repository?
0158             hostname = find(pli, 'hostname');
0159             if ~isempty(hostname)
0160               utils.helper.msg(msg.OPROC1, 'retrieving from repository %s', hostname);
0161               pl = pl.fromRepository(pli);
0162             else
0163               utils.helper.msg(msg.OPROC1, 'copying from %s', varargin{1}.name);
0164               pl = copy(varargin{1}, 1);
0165             end
0166           end
0167 
0168           %%%%%%%%%%% From file %%%%%%%%%%%%%%%%%%%%%%%%
0169         elseif ischar(varargin{1})
0170 
0171           filename = varargin{1};
0172           utils.helper.msg(msg.OPROC1, 'constructing from file %s', filename);
0173           pl = fromFile(pl, filename);
0174               
0175 %           [path, name, ext] = fileparts(filename);
0176 %           switch ext
0177 %             case '.mat'
0178 %               pl = load(filename);
0179 %               pl = pl.a;
0180 %             case '.xml'
0181 %               root_node = xmlread(filename);
0182 %               pl = utils.helper.xmlread(root_node, 'plist');
0183 %             otherwise
0184 %               error('### Unknown file type.');
0185 %           end
0186 
0187           %%%%%%%%%%   pl = plist(struct)   %%%%%%%%%%
0188         elseif isstruct(varargin{1})
0189 
0190           utils.helper.msg(msg.OPROC1, 'constructing from struct');
0191           %%% Set properties which are declared in this class
0192           pl.params = utils.helper.struct2obj(varargin{1}.params, 'param');
0193 
0194           %%%%%%%%%%   pl = plist(param)   %%%%%%%%%%
0195         elseif isa(varargin{1}, 'param')
0196 
0197           utils.helper.msg(msg.OPROC1, 'constructing from param');
0198           %%% Use only upper case characters for the 'key'
0199           param_list = varargin{1};
0200           for kk = 1:length(param_list)
0201             param_list(kk) = param_list(kk).setKey(upper(param_list(kk).key));
0202           end
0203 
0204           pl.params = param_list;
0205 
0206         else
0207           error ('### unknown arguments to construct a parameter list')
0208         end
0209 
0210       elseif nargin == 2
0211 
0212         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0213         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%   two inputs   %%%%%%%%%%%%%%%%%%%%%%%%%%%%
0214         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0215 
0216         %%%%%%%%%%%   From DATABASE   %%%%%%%%%%%
0217         if isa(varargin{1}, 'database')
0218 
0219           utils.helper.msg(msg.OPROC1, 'constructing from database object');
0220           pl = retrieve(varargin{1}, varargin{2:end});
0221 
0222           %%%%%%%%%%   pl = plist('key1', val1)   %%%%%%%%%%
0223         else
0224           utils.helper.msg(msg.OPROC1, 'constructing from key/value pair');
0225           pl.params = param(upper(varargin{1}), varargin{2});
0226         end
0227 
0228       elseif nargin > 2
0229 
0230         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0231         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%   more inputs   %%%%%%%%%%%%%%%%%%%%%%%%%%%
0232         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0233 
0234         utils.helper.msg(msg.OPROC1, 'constructing from key/value pairs');
0235 
0236         %%%%%%%%%%   pl = plist('key1, val1, 'key2', 'val2' , ...)   %%%%%%%%%%
0237         param_list = [];
0238         argin  = varargin;
0239         while length(argin) >= 2
0240           key = upper(argin{1});
0241           val =       argin{2};
0242           argin = argin(3:end);
0243 
0244           if ~isempty(pl.params)
0245             found = any(strcmpi(key, {pl.params(:).key}));
0246             if found
0247               error('### Do not use the same key [%s] twice.\n### REMARK: The key is not case sensitive.', key);
0248             end
0249           end
0250           % add to list
0251           param_list = [param_list param(key, val)];
0252         end
0253         pl.params  = param_list;
0254       else
0255         error('### Unknown number of constructor arguments.');
0256       end
0257 
0258     end % End constructor
0259   end
0260 
0261   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0262   %                              Methods (public)                             %
0263   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0264 
0265   methods
0266     %%% Define Abstract methods
0267     varargout = char(varargin);
0268     varargout = copy(varargin)
0269     varargout = display(varargin);
0270     varargout = string(varargin);
0271 
0272     %%% Define other methods
0273     varargout = append(varargin);
0274     varargout = combine(varargin);
0275     varargout = find(varargin);
0276     varargout = isparam(varargin);
0277     varargout = nparams(varargin);
0278     varargout = pset(varargin);
0279     %     varargout = pzmresp(varargin);
0280     varargout = remove(varargin)
0281     varargout = resp(varargin);
0282   end
0283 
0284   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0285   %                              Methods (protected)                          %
0286   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0287 
0288   methods (Access = protected)
0289     varargout = fromRepository(varargin)
0290   end
0291 
0292   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0293   %                          Methods (Static, Public)                         %
0294   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0295 
0296   methods (Static = true)
0297 
0298     varargout = update_struct(varargin);
0299 
0300     function out = VEROUT()
0301       out = '$Id: plist.m,v 1.51 2008/09/07 18:15:26 hewitson Exp $';
0302     end
0303 
0304     function ii = getInfo(varargin)
0305       ii = utils.helper.generic_getInfo(varargin{:}, 'plist');
0306     end
0307 
0308     function out = SETS()
0309       out = {'Default', 'From Repository', 'From MAT File'};
0310     end
0311 
0312     function out = getDefaultPlist(set)
0313       switch set
0314         case 'Default'
0315           out = plist();
0316         case 'From Repository'
0317           out = plist('hostname', 'localhost', 'database', 'ltpda', 'ID', []);
0318         case 'From MAT File'
0319           out = plist('filename', '');
0320         otherwise
0321           error('### Unknown set [%s] to get the default plist.', set);
0322       end
0323     end
0324 
0325   end
0326 
0327   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0328   %                          Methods (Static, Private)                        %
0329   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0330 
0331   methods (Static = true, Access = private)
0332   end
0333 
0334 end % Class
0335 
0336

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003