macros.h

Go to the documentation of this file.
00001 // Debugging support implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2003, 2005
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 #ifndef _GLIBCXX_DEBUG_MACROS_H
00032 #define _GLIBCXX_DEBUG_MACROS_H 1
00033 
00043 #define _GLIBCXX_DEBUG_VERIFY(_Condition,_ErrorMessage)             \
00044   do {                                  \
00045     if (! (_Condition))                         \
00046       ::__gnu_debug::_Error_formatter::_M_at(__FILE__, __LINE__)    \
00047       ._ErrorMessage._M_error();                    \
00048   } while (false)
00049 
00050 // Verify that [_First, _Last) forms a valid iterator range.
00051 #define __glibcxx_check_valid_range(_First,_Last)           \
00052 _GLIBCXX_DEBUG_VERIFY(::__gnu_debug::__valid_range(_First, _Last),  \
00053               _M_message(::__gnu_debug::__msg_valid_range)  \
00054               ._M_iterator(_First, #_First)         \
00055               ._M_iterator(_Last, #_Last))
00056 
00064 #define __glibcxx_check_insert(_Position)               \
00065 _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(),             \
00066               _M_message(::__gnu_debug::__msg_insert_singular) \
00067               ._M_sequence(*this, "this")           \
00068               ._M_iterator(_Position, #_Position));     \
00069 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),           \
00070               _M_message(::__gnu_debug::__msg_insert_different) \
00071               ._M_sequence(*this, "this")           \
00072               ._M_iterator(_Position, #_Position))
00073 
00087 #define __glibcxx_check_insert_range(_Position,_First,_Last)        \
00088 __glibcxx_check_valid_range(_First,_Last);              \
00089 _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(),             \
00090               _M_message(::__gnu_debug::__msg_insert_singular) \
00091                       ._M_sequence(*this, "this")           \
00092               ._M_iterator(_Position, #_Position));     \
00093 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),           \
00094               _M_message(::__gnu_debug::__msg_insert_different) \
00095               ._M_sequence(*this, "this")           \
00096               ._M_iterator(_Position, #_Position))
00097 
00102 #define __glibcxx_check_erase(_Position)                \
00103 _GLIBCXX_DEBUG_VERIFY(_Position._M_dereferenceable(),           \
00104               _M_message(::__gnu_debug::__msg_erase_bad)    \
00105                       ._M_sequence(*this, "this")           \
00106               ._M_iterator(_Position, #_Position));     \
00107 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),           \
00108               _M_message(::__gnu_debug::__msg_erase_different) \
00109               ._M_sequence(*this, "this")           \
00110               ._M_iterator(_Position, #_Position))
00111 
00116 #define __glibcxx_check_erase_range(_First,_Last)           \
00117 __glibcxx_check_valid_range(_First,_Last);              \
00118 _GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this),          \
00119               _M_message(::__gnu_debug::__msg_erase_different) \
00120                       ._M_sequence(*this, "this")           \
00121               ._M_iterator(_First, #_First)         \
00122               ._M_iterator(_Last, #_Last))
00123 
00124 // Verify that the subscript _N is less than the container's size.
00125 #define __glibcxx_check_subscript(_N)                   \
00126 _GLIBCXX_DEBUG_VERIFY(_N < this->size(),                \
00127               _M_message(::__gnu_debug::__msg_subscript_oob) \
00128                       ._M_sequence(*this, "this")           \
00129               ._M_integer(_N, #_N)              \
00130               ._M_integer(this->size(), "size"))
00131 
00132 // Verify that the container is nonempty
00133 #define __glibcxx_check_nonempty()                  \
00134 _GLIBCXX_DEBUG_VERIFY(! this->empty(),                  \
00135               _M_message(::__gnu_debug::__msg_empty)    \
00136                       ._M_sequence(*this, "this"))
00137 
00138 // Verify that the < operator for elements in the sequence is a
00139 // StrictWeakOrdering by checking that it is irreflexive.
00140 #define __glibcxx_check_strict_weak_ordering(_First,_Last)  \
00141 _GLIBCXX_DEBUG_ASSERT(_First == _Last || !(*_First < *_First))
00142 
00143 // Verify that the predicate is StrictWeakOrdering by checking that it
00144 // is irreflexive.
00145 #define __glibcxx_check_strict_weak_ordering_pred(_First,_Last,_Pred)   \
00146 _GLIBCXX_DEBUG_ASSERT(_First == _Last || !_Pred(*_First, *_First))
00147 
00148 
00149 // Verify that the iterator range [_First, _Last) is sorted
00150 #define __glibcxx_check_sorted(_First,_Last)                \
00151 __glibcxx_check_valid_range(_First,_Last);              \
00152 __glibcxx_check_strict_weak_ordering(_First,_Last);         \
00153 _GLIBCXX_DEBUG_VERIFY(::__gnu_debug::__check_sorted(_First, _Last), \
00154               _M_message(::__gnu_debug::__msg_unsorted) \
00155                       ._M_iterator(_First, #_First)         \
00156               ._M_iterator(_Last, #_Last))
00157 
00160 #define __glibcxx_check_sorted_pred(_First,_Last,_Pred)         \
00161 __glibcxx_check_valid_range(_First,_Last);              \
00162 __glibcxx_check_strict_weak_ordering_pred(_First,_Last,_Pred);          \
00163 _GLIBCXX_DEBUG_VERIFY(::__gnu_debug::__check_sorted(_First, _Last, _Pred), \
00164               _M_message(::__gnu_debug::__msg_unsorted_pred) \
00165                       ._M_iterator(_First, #_First)         \
00166               ._M_iterator(_Last, #_Last)           \
00167               ._M_string(#_Pred))
00168 
00171 #define __glibcxx_check_partitioned(_First,_Last,_Value)        \
00172 __glibcxx_check_valid_range(_First,_Last);              \
00173 _GLIBCXX_DEBUG_VERIFY(::__gnu_debug::__check_partitioned(_First, _Last, \
00174                              _Value),   \
00175               _M_message(::__gnu_debug::__msg_unpartitioned) \
00176               ._M_iterator(_First, #_First)         \
00177               ._M_iterator(_Last, #_Last)           \
00178               ._M_string(#_Value))
00179 
00182 #define __glibcxx_check_partitioned_pred(_First,_Last,_Value,_Pred) \
00183 __glibcxx_check_valid_range(_First,_Last);              \
00184 _GLIBCXX_DEBUG_VERIFY(::__gnu_debug::__check_partitioned(_First, _Last, \
00185                              _Value, _Pred), \
00186               _M_message(::__gnu_debug::__msg_unpartitioned_pred) \
00187               ._M_iterator(_First, #_First)         \
00188               ._M_iterator(_Last, #_Last)           \
00189               ._M_string(#_Pred)                \
00190                       ._M_string(#_Value))
00191 
00192 // Verify that the iterator range [_First, _Last) is a heap
00193 #define __glibcxx_check_heap(_First,_Last)              \
00194 __glibcxx_check_valid_range(_First,_Last);              \
00195 _GLIBCXX_DEBUG_VERIFY(::std::__is_heap(_First, _Last),      \
00196               _M_message(::__gnu_debug::__msg_not_heap) \
00197               ._M_iterator(_First, #_First)         \
00198               ._M_iterator(_Last, #_Last))
00199 
00202 #define __glibcxx_check_heap_pred(_First,_Last,_Pred)           \
00203 __glibcxx_check_valid_range(_First,_Last);              \
00204 _GLIBCXX_DEBUG_VERIFY(::std::__is_heap(_First, _Last, _Pred),       \
00205               _M_message(::__gnu_debug::__msg_not_heap_pred) \
00206                       ._M_iterator(_First, #_First)         \
00207               ._M_iterator(_Last, #_Last)           \
00208               ._M_string(#_Pred))
00209 
00210 #ifdef _GLIBCXX_DEBUG_PEDANTIC
00211 #  define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_ASSERT(_String != 0)
00212 #  define __glibcxx_check_string_len(_String,_Len) \
00213        _GLIBCXX_DEBUG_ASSERT(_String != 0 || _Len == 0)
00214 #else
00215 #  define __glibcxx_check_string(_String)
00216 #  define __glibcxx_check_string_len(_String,_Len)
00217 #endif
00218 
00219 #endif

Generated on Tue Feb 2 16:56:13 2010 for GNU C++ STL by  doxygen 1.4.7