eidors_debug

PURPOSE ^

EIDORS_DEBUG Global managment of debug flags

SYNOPSIS ^

function out = eidors_debug(command, fstr)

DESCRIPTION ^

EIDORS_DEBUG Global managment of debug flags
 eidors_debug('on','function') 
     switches ON the debug flag for string constant 'function'
 eidors_debug('off','function') 
     switches OFF the debug flag for string constant 'function'
 eidors_debug('off','all') 
     switches OFF the debug flag for all functions
 eidors_debug('query','function') 
     returns the current state of the debug flag for 'function'
 
 Note that 'function' can be any string constant (other than 'all'), but 
 it is recommended to be an actual eidors function name. To enable 
 debugging on selected parts of the code, follow this convention:
    eidors_function:part1
    eidors_function:subfunction
    eidors_function:subfunction:part1

 Example use in code (my_function.m):
 if eidors_debug('query','my_function')
     disp(val)
 end

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function out = eidors_debug(command, fstr)
0002 %EIDORS_DEBUG Global managment of debug flags
0003 % eidors_debug('on','function')
0004 %     switches ON the debug flag for string constant 'function'
0005 % eidors_debug('off','function')
0006 %     switches OFF the debug flag for string constant 'function'
0007 % eidors_debug('off','all')
0008 %     switches OFF the debug flag for all functions
0009 % eidors_debug('query','function')
0010 %     returns the current state of the debug flag for 'function'
0011 %
0012 % Note that 'function' can be any string constant (other than 'all'), but
0013 % it is recommended to be an actual eidors function name. To enable
0014 % debugging on selected parts of the code, follow this convention:
0015 %    eidors_function:part1
0016 %    eidors_function:subfunction
0017 %    eidors_function:subfunction:part1
0018 %
0019 % Example use in code (my_function.m):
0020 % if eidors_debug('query','my_function')
0021 %     disp(val)
0022 % end
0023 
0024 % (C) 2013 Bartlomiej Grychtol.
0025 % License: GPL version 2 or 3
0026 % $Id: eidors_debug.m 4924 2015-05-07 23:09:59Z aadler $
0027 
0028 
0029 
0030 if ischar(command) && strcmp(command, 'UNIT_TEST'), do_unit_test;return; end
0031 
0032 global eidors_objects;
0033 
0034 if ~isfield(eidors_objects, 'debug_enabled_on')
0035    eidors_objects.debug_enabled_on = {};
0036 end
0037 
0038 switch command
0039    case 'on'
0040       if ~eidors_debug('query',fstr);
0041          eidors_objects.debug_enabled_on{end+1} = fstr;
0042       end
0043    case 'off'
0044       if nargin==1 || strcmp(fstr, 'all')
0045          eidors_objects.debug_enabled_on = {};
0046       else
0047          idx = strcmp(eidors_objects.debug_enabled_on, fstr);
0048          eidors_objects.debug_enabled_on(idx) = [];
0049       end
0050    case 'query'
0051       idx = strcmp(eidors_objects.debug_enabled_on, fstr);
0052       out = any(idx);
0053    otherwise
0054       error('EIDORS:WrongInput',['First input to eidors_debug must be ', ...
0055          '''on'',''off'' or ''query''.']);
0056 end
0057 
0058 function test
0059 if eidors_debug('query','eidors_debug_test1')
0060    eidors_msg('TEST1',2);
0061 end
0062 
0063 if eidors_debug('query','eidors_debug_test2')
0064    eidors_msg('TEST2',2);
0065 end
0066 
0067 
0068 function do_unit_test
0069 eidors_debug on eidors_debug_test1
0070 eidors_debug on eidors_debug_test2
0071 test
0072 eidors_debug off eidors_debug_test1
0073 test
0074 eidors_debug off all
0075 test
0076 fprintf('expected output:\n[%s]\n[%s]\n[%s]\n',  ...
0077   'TEST1', ...
0078   'TEST2', ...
0079   'TEST2');

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005