CVR-Lib last update 20 Sep 2009

cvrDebug.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1998
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  *
00006  * This file is part of the Computer Vision and Robotics Library (CVR-Lib)
00007  *
00008  * The CVR-Lib is free software; you can redistribute it and/or
00009  * modify it under the terms of the BSD License.
00010  *
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright notice,
00020  *    this list of conditions and the following disclaimer in the documentation
00021  *    and/or other materials provided with the distribution.
00022  *
00023  * 3. Neither the name of the authors nor the names of its contributors may be
00024  *    used to endorse or promote products derived from this software without
00025  *    specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  */
00039 
00040 
00041 /**
00042  * \file   cvrDebug.h
00043  *         Defines many macros used when debugging CVR-Libclasses.
00044  *         The main macros are _cvr_debug* and _cvr_if_debug*,
00045  *         which are active only if the macro symbol _CVR_DEBUG is high enough.
00046  * \author Jochen Wickel
00047  * \author Pablo Alvarado
00048  * \date   24.02.2003
00049  *
00050  * $Id: cvrDebug.h,v 1.3 2005/07/09 04:20:13 alvarado Exp $
00051  */
00052 
00053 #undef _cvr_debug
00054 #undef _cvr_debug1
00055 #undef _cvr_debug2
00056 #undef _cvr_debug3
00057 #undef _cvr_debug4
00058 
00059 #undef _cvr_if_debug
00060 #undef _cvr_if_debug1
00061 #undef _cvr_if_debug2
00062 #undef _cvr_if_debug3
00063 #undef _cvr_if_debug4
00064 
00065 #undef _cvr_enterCTOR
00066 #undef _cvr_leaveCTOR
00067 #undef _cvr_enterDTOR
00068 #undef _cvr_leaveDTOR
00069 
00070 #undef _cvr_showVar
00071 
00072 /**
00073  * \name Debugging Macros
00074  *
00075  * Developers of the CVR-Libuse following macros to activate debugging
00076  * code in their implementations.
00077  *
00078  * To activate them, the macro _CVR_DEBUG must be defined before including
00079  * this file.  The value of _CVR_DEBUG must be an integer value between 1 and 4
00080  * Debug level i+1 includes all information of level i.  This means, you
00081  * should use the macros _cvr_debug and _cvr_debug1 to display critical
00082  * information, that must always be displayed when debugging is activated and
00083  * less critical information with higher levels.
00084  *
00085  * Don't forget to include the "cvrUndebug.h" file at the end of your source
00086  * code, to undefine all the debug macros defined here, especially if it is
00087  * a header file (e.g. _template.h, _inline.h).
00088  *
00089  * The typical use of this file is:
00090  * \code
00091  * // somewhere at the beginning of your source file
00092  * #undef _CVR_DEBUG
00093  * #define _CVR_DEBUG 1 // comment out this line to remove all debug info.
00094  * #include "cvrDebug.h"
00095  *
00096  * // somewhere in your code you can use
00097  * _cvr_debug("I've been here with value" << val);
00098  *
00099  * _cvr_debug4("Only in level 4 this will be displayed");
00100  *
00101  * // at the end of your file you MUST undefine every debugging macro, to
00102  * // avoid confusion if someone includes your file!  Of course this is
00103  * // not necessary if your file is a .cpp file.  This is important for
00104  * // _template.h and _inline.h files.
00105  * #include "cvrUndebug.h"
00106  * \endcode
00107  */
00108 //@{
00109 #ifdef _CVR_DEBUG
00110 #  include <iostream>
00111 
00112   /**
00113    * \def _cvr_debug
00114    * Debug Information Level 0 (always displayed)
00115    */
00116 #  define _cvr_debug(a) std::cerr << a
00117 #  define _cvr_if_debug(a) a
00118 
00119   /**
00120    * \def _cvr_debug1
00121    * Debug Information Level 1 (always displayed)
00122    */
00123 #  define _cvr_debug1(a) std::cerr << a
00124 #  define _cvr_if_debug1(a) a
00125 
00126 #  if _CVR_DEBUG > 1
00127 #    include "cvrClassName.h"
00128      /**
00129       * \def _cvr_debug2
00130       * Debug Information Level 2
00131       */
00132 #    define _cvr_debug2(a) std::cerr << a
00133 #    define _cvr_if_debug2(a) a
00134 
00135 #    if _CVR_DEBUG > 2
00136        /**
00137         * \def _cvr_debug3
00138         * Debug Information Level 3
00139         */
00140 #      define _cvr_debug3(a) std::cerr << a
00141 #      define _cvr_if_debug3(a) a
00142 
00143 #      if _CVR_DEBUG > 3
00144          /**
00145           * \def _cvr_debug4
00146           * Debug Information Level 4
00147           */
00148 #        define _cvr_debug4(a) std::cerr << a
00149 #        define _cvr_if_debug4(a) a
00150 
00151 #      else
00152          /**
00153           * \def _cvr_debug4
00154           * Debug Information Level 4
00155           */
00156 #        define _cvr_debug4(a)
00157 #        define _cvr_if_debug4(a)
00158 
00159 #      endif
00160 #    else
00161        /**
00162         * \def _cvr_debug3
00163         * Debug Information Level 3
00164         */
00165 #      define _cvr_debug3(a)
00166 #      define _cvr_if_debug3(a)
00167 
00168 #    endif
00169 #  else
00170     /**
00171      * \def _cvr_debug2
00172      * Debug Information Level 2
00173      */
00174 #    define _cvr_debug2(a)
00175 #    define _cvr_if_debug2(a)
00176 
00177 #  endif
00178 #endif
00179 
00180 #ifndef _cvr_debug
00181   /**
00182    * \def _cvr_debug
00183    * Debug Information Level 0 (always displayed)
00184    */
00185 #  define _cvr_debug(a)
00186 #  define _cvr_if_debug(a)
00187 
00188 #endif
00189 
00190 #ifndef _cvr_debug1
00191   /**
00192    * \def _cvr_debug1
00193    * Debug Information Level 1 (always displayed)
00194    */
00195 #  define _cvr_debug1(a)
00196 #  define _cvr_if_debug1(a)
00197 #endif
00198 
00199 
00200 #ifndef _cvr_debug2
00201   /**
00202    * \def _cvr_debug2
00203    * Debug Information Level 2
00204    */
00205 #  define _cvr_debug2(a)
00206 #  define _cvr_if_debug2(a)
00207 #endif
00208 
00209 #ifndef _cvr_debug3
00210   /**
00211    * \def _cvr_debug3
00212    * Debug Information Level 3
00213    */
00214 #  define _cvr_debug3(a)
00215 #  define _cvr_if_debug3(a)
00216 #endif
00217 
00218 #ifndef _cvr_debug4
00219   /**
00220    * \def _cvr_debug4
00221    * Debug Information Level 4
00222    */
00223 #  define _cvr_debug4(a)
00224 #  define _cvr_if_debug4(a)
00225 #endif
00226 
00227 /**
00228  * \def _cvr_enterCTOR
00229  * Debug macro to indicate "entering constructor".  It displays the class name
00230  * followed by the string "::ctor(".  It uses debug level 2.
00231  */
00232 #define _cvr_enterCTOR() \
00233   _cvr_debug2(cvr::className::demangle(typeid(*this).name()) << \
00234               "::ctor(" << std::endl)
00235 
00236 /**
00237  * \def _cvr_leaveCTOR
00238  * Debug macro to indicate "leaving constructor".  It displays the class name
00239  * followed by the string "::ctor)".  It uses debug level 2.
00240  */
00241 #define _cvr_leaveCTOR() \
00242   _cvr_debug2(cvr::className::demangle(typeid(*this).name()) << \
00243               "::ctor)" << std::endl)
00244 
00245 /**
00246  * \def _cvr_enterDTOR
00247  * Debug macro to indicate "entering destructor".  It displays the class name
00248  * followed by the string "::dtor(".  It uses debug level 2.
00249  */
00250 #define _cvr_enterDTOR() \
00251   _cvr_debug2(cvr::className::demangle(typeid(*this).name()) << \
00252               "::dtor(" << std::endl)
00253 
00254 /**
00255  * \def _cvr_leaveDTOR
00256  * Debug macro to indicate "leaving destructor".  It displays the class name
00257  * followed by the string "::ctor)".  It uses debug level 2.
00258  */
00259 #define _cvr_leaveDTOR() \
00260   _cvr_debug2(cvr::className::demangle(typeid(*this).name()) << \
00261               "::dtor)" << std::endl)
00262 
00263 /**
00264  * \def _cvr_showVar
00265  * Debug macro to display at debug level 0 the value of a given variable.
00266  * It displays the name of the variable followed by " = " and the contents
00267  * of it.  The type of the variable must be supported by the std::cerr stream.
00268  */
00269 #define _cvr_showVar(a) _cvr_debug(#a " = " << a << "\n")
00270 
00271 //@}

Generated on Sun Sep 20 22:07:59 2009 for CVR-Lib by Doxygen 1.5.8