debug.h

Go to the documentation of this file.
00001 // Debugging support implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2003, 2005, 2006
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 2, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // You should have received a copy of the GNU General Public License along
00018 // with this library; see the file COPYING.  If not, write to the Free
00019 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00020 // USA.
00021 
00022 // As a special exception, you may use this file as part of a free software
00023 // library without restriction.  Specifically, if other files instantiate
00024 // templates or use macros or inline functions from this file, or you compile
00025 // this file and link it with other files to produce an executable, this
00026 // file does not by itself cause the resulting executable to be covered by
00027 // the GNU General Public License.  This exception does not however
00028 // invalidate any other reasons why the executable file might be covered by
00029 // the GNU General Public License.
00030 
00031 /** @file debug/debug.h
00032  *  This file is a GNU debug extension to the Standard C++ Library.
00033  */
00034 
00035 #ifndef _GLIBCXX_DEBUG_MACRO_SWITCH_H
00036 #define _GLIBCXX_DEBUG_MACRO_SWITCH_H 1
00037 
00038 /** Macros and namespaces used by the implementation outside of debug
00039  *  wrappers to verify certain properties. The __glibcxx_requires_xxx
00040  *  macros are merely wrappers around the __glibcxx_check_xxx wrappers
00041  *  when we are compiling with debug mode, but disappear when we are
00042  *  in release mode so that there is no checking performed in, e.g.,
00043  *  the standard library algorithms.
00044 */
00045 
00046 // Debug mode namespaces.
00047 namespace std 
00048 { 
00049   namespace __debug { } 
00050 }
00051 
00052 namespace __gnu_cxx
00053 { 
00054   namespace __debug { };
00055 }
00056 
00057 namespace __gnu_debug
00058 {
00059   using namespace std::__debug;
00060   using namespace __gnu_cxx::__debug;
00061 }
00062 
00063 #ifndef _GLIBCXX_DEBUG
00064 
00065 # define _GLIBCXX_DEBUG_ASSERT(_Condition)
00066 # define _GLIBCXX_DEBUG_PEDASSERT(_Condition)
00067 # define _GLIBCXX_DEBUG_ONLY(_Statement) ;
00068 # define __glibcxx_requires_cond(_Cond,_Msg)
00069 # define __glibcxx_requires_valid_range(_First,_Last)
00070 # define __glibcxx_requires_sorted(_First,_Last)
00071 # define __glibcxx_requires_sorted_pred(_First,_Last,_Pred)
00072 # define __glibcxx_requires_partitioned(_First,_Last,_Value)
00073 # define __glibcxx_requires_partitioned_pred(_First,_Last,_Value,_Pred)
00074 # define __glibcxx_requires_heap(_First,_Last)
00075 # define __glibcxx_requires_heap_pred(_First,_Last,_Pred)
00076 # define __glibcxx_requires_nonempty()
00077 # define __glibcxx_requires_string(_String)
00078 # define __glibcxx_requires_string_len(_String,_Len)
00079 # define __glibcxx_requires_subscript(_N)
00080 
00081 #else
00082 
00083 # include <cstdlib>
00084 # include <cstdio>
00085 # include <debug/macros.h>
00086 
00087 namespace std
00088 {
00089   namespace __debug
00090   { 
00091     // Avoid the use of assert, because we're trying to keep the <cassert>
00092     // include out of the mix.
00093     inline void
00094     __replacement_assert(const char* __file, int __line, 
00095              const char* __function, const char* __condition)
00096     {
00097       printf("%s:%d: %s: Assertion '%s' failed.\n", __file, __line,
00098          __function, __condition);
00099       abort();
00100     }
00101   } // namespace __debug
00102 } // namespace std
00103 
00104 #define _GLIBCXX_DEBUG_ASSERT(_Condition)                                   \
00105   do                                        \
00106   {                                     \
00107     if (! (_Condition))                                                     \
00108       std::__debug::__replacement_assert(__FILE__, __LINE__,            \
00109                      __PRETTY_FUNCTION__, #_Condition); \
00110   } while (false)
00111 
00112 #ifdef _GLIBCXX_DEBUG_PEDANTIC
00113 # define _GLIBCXX_DEBUG_PEDASSERT(_Condition) _GLIBCXX_DEBUG_ASSERT(_Condition)
00114 #else
00115 # define _GLIBCXX_DEBUG_PEDASSERT(_Condition)
00116 #endif
00117 # define _GLIBCXX_DEBUG_ONLY(_Statement) _Statement
00118 
00119 # define __glibcxx_requires_cond(_Cond,_Msg) _GLIBCXX_DEBUG_VERIFY(_Cond,_Msg)
00120 # define __glibcxx_requires_valid_range(_First,_Last) \
00121      __glibcxx_check_valid_range(_First,_Last)
00122 # define __glibcxx_requires_sorted(_First,_Last) \
00123      __glibcxx_check_sorted(_First,_Last)
00124 # define __glibcxx_requires_sorted_pred(_First,_Last,_Pred) \
00125      __glibcxx_check_sorted_pred(_First,_Last,_Pred)
00126 # define __glibcxx_requires_partitioned(_First,_Last,_Value)    \
00127      __glibcxx_check_partitioned(_First,_Last,_Value)
00128 # define __glibcxx_requires_partitioned_pred(_First,_Last,_Value,_Pred) \
00129      __glibcxx_check_partitioned_pred(_First,_Last,_Value,_Pred)
00130 # define __glibcxx_requires_heap(_First,_Last) \
00131      __glibcxx_check_heap(_First,_Last)
00132 # define __glibcxx_requires_heap_pred(_First,_Last,_Pred) \
00133      __glibcxx_check_heap_pred(_First,_Last,_Pred)
00134 # define __glibcxx_requires_nonempty() __glibcxx_check_nonempty()
00135 # define __glibcxx_requires_string(_String) __glibcxx_check_string(_String)
00136 # define __glibcxx_requires_string_len(_String,_Len)    \
00137      __glibcxx_check_string_len(_String,_Len)
00138 # define __glibcxx_requires_subscript(_N) __glibcxx_check_subscript(_N)
00139 
00140 # include <debug/functions.h>
00141 # include <debug/formatter.h>
00142 
00143 #endif
00144 
00145 #endif // _GLIBCXX_DEBUG_MACRO_SWITCH_H

Generated on Thu Nov 1 13:11:25 2007 for libstdc++ by  doxygen 1.5.1