www.pudn.com > firev0.01.rar > diag.hpp
/*
This file is part of the FIRE -- Flexible Image Retrieval System
FIRE is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FIRE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FIRE; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __diag_hpp
#define __diag_hpp
//#include "colors.hpp"
/** Library for diagnostic output.
@author Nils Springob ,
Thomas Deselaers
This is a quite efficient and easy way to have some debug messages
in your code. It is possible to disable this while run or while
compile time in as fine steps as you like.
-# while compiletime: to leave all the messages with a debug-level
< x out of the programm compile with -DDEBUG_LEVEL=x
-# while runtime: set the environment variable to the value you
prefer.
-# also it is possible to specify this directly in your code using
the CheckRuntimeDebugLevel function
*/
#ifndef DEBUG_LEVEL
#define DEBUG_LEVEL 0
#endif
#include
///Don't say nothing, say this always
#define DBG_DUMB 0
///Mark results with this, usually you want them on your screen
#define DBG_RESULT 1
///debug level for program start and stop
#define DBG_START 2
///something strange happened
#define DBG_STRANGE 5
///an error occured
#define DBG_ERROR 10
///a message to be printed. 15 is also a common debuglevel if a
///program is running normally
#define DBG_MESSAGE 15
///for first debugging steps
#define DBG_ENTRY_EXIT 40
///important intermediate data
#define DBG_VERBOSE 50
///tell a lot more than what is interesting
#define DBG_TALKATIVE 80
///tell everything you know
#define DBG_EXHIBITIONIST 120
///simple debug-output macro
#define DBGI(level,instruction) \
if(DEBUG_LEVEL>=level && ::diag::CheckRuntimeDebugLevel(level)) instruction
#define DBG(level) \
if(DEBUG_LEVEL>=level && ::diag::CheckRuntimeDebugLevel(level)) ::std::cout << "(" << ((int)(level)) << ") [" << __FILE__<<":"<<__LINE__<<":"<<__FUNCTION__<<"] "
#define BLINK(level) \
if(DEBUG_LEVEL>=level && ::diag::CheckRuntimeDebugLevel(level)) ::std::cout
#define BLINK(level) \
if(DEBUG_LEVEL>=level && ::diag::CheckRuntimeDebugLevel(level)) ::std::cout
///even simpler error-message macro
#define ERR ::std::cerr << "[" << __FILE__<<":"<<__LINE__<<":"<<__FUNCTION__<<"] ERROR: "
namespace diag {
///function to specify and check the desired debug level
bool CheckRuntimeDebugLevel(int level, bool set=false);
/** check if a memory allocation was successful.
*
* This function checks, whether a memory allocation was successful
* or not and aborts, if not.
* @param ptr pointer to the memory which has to be checked
*/
void memtest(void *ptr);
}
#endif