Home > atmlab > handy > rqre_alltypes.m

rqre_alltypes

PURPOSE ^

RQRE_ALLTYPES Checks if a variable matches a combination of type checks

SYNOPSIS ^

function rqre_alltypes( a, funchandles, nonstdname )

DESCRIPTION ^

 RQRE_ALLTYPES   Checks if a variable matches a combination of type checks

    The input argument *funchandles* is a cell array of handles to
    functions performing type checking. For example, the following  
    is a check if *a* is a scalar integer number:
       rqre_alltypes( a, {@istensor0,@iswhole} )

    Issues an error if criterion not fulfilled. This error assumes that all
    functions are named as isxxxx, where xxxx is the name of the data type.

    Use *<a href="matlab:help rqre_datatype">rqre_datatype</a>* for check with respect to a single or one of several
    types.

 FORMAT   rqre_alltypes( a, funchandles [,nonstdname] )
        
 IN    a             Variable to check.
       funchandles   Handles to type checking functions.
 OPT   nonstdname    Name of variable to use in error message. Default is
                     to use the function *inputname* to determine the
                     variable name.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

rqre_alltypes.m

SOURCE CODE ^

0001 % RQRE_ALLTYPES   Checks if a variable matches a combination of type checks
0002 %
0003 %    The input argument *funchandles* is a cell array of handles to
0004 %    functions performing type checking. For example, the following
0005 %    is a check if *a* is a scalar integer number:
0006 %       rqre_alltypes( a, {@istensor0,@iswhole} )
0007 %
0008 %    Issues an error if criterion not fulfilled. This error assumes that all
0009 %    functions are named as isxxxx, where xxxx is the name of the data type.
0010 %
0011 %    Use *<a href="matlab:help rqre_datatype">rqre_datatype</a>* for check with respect to a single or one of several
0012 %    types.
0013 %
0014 % FORMAT   rqre_alltypes( a, funchandles [,nonstdname] )
0015 %
0016 % IN    a             Variable to check.
0017 %       funchandles   Handles to type checking functions.
0018 % OPT   nonstdname    Name of variable to use in error message. Default is
0019 %                     to use the function *inputname* to determine the
0020 %                     variable name.
0021 
0022 % 2005-03-16   Created by Patrick Eriksson.
0023 
0024 
0025 function rqre_alltypes( a, funchandles, nonstdname )
0026                                                                             %&%
0027                                                                             %&%
0028 assert( all( cellfun( 'isclass', funchandles, 'function_handle' ) ), ...    %&%
0029       'The argument *funchandles* does not contain function handles.' );    %&%
0030 %                                                                           %&%
0031 if ~isvector( funchandles )                                                 %&%
0032   error( 'The argument *funchandles* must be a vector (row or column).' );  %&%
0033 end                                                                         %&%
0034 %                                                                           %&%
0035 if length( funchandles ) < 2                                                %&%
0036   error( 'Use *rqre_datetype* for match with single data types.' );         %&%
0037 end                                                                         %&%
0038 
0039 
0040 %- Perform check
0041 %
0042 all_ok = true;
0043 %
0044 for i = 1:length(funchandles)
0045   if ~funchandles{i}(a)
0046     all_ok = false;
0047     break                     
0048   end
0049 end
0050 %
0051 if all_ok
0052   return
0053 end
0054 
0055 
0056 %- Error messages
0057 %
0058 if nargin < 3
0059   vname = sprintf( 'The variable *%s*', inputname(1) );
0060 else
0061   assert( ischar( nonstdname )  &&  ~isempty( nonstdname ) );               %&%
0062   vname = nonstdname;
0063 end
0064 %
0065 fprintf('Expected data type combination is\n');
0066 for i = 1:length(funchandles)
0067   s = func2str( funchandles{i} );
0068   fprintf('   %s\n', s(3:end) );
0069 end
0070 error( '%s fails to match one or several of type checks, listed above.', vname );

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005