_debug.h

来自「stl的源码」· C头文件 代码 · 共 474 行 · 第 1/2 页

H
474
字号
/* * * Copyright (c) 1997 * Moscow Center for SPARC Technology * * Copyright (c) 1999 * Boris Fomitchev * * This material is provided "as is", with absolutely no warranty expressed * or implied. Any use is at your own risk. * * Permission to use or copy this software for any purpose is hereby granted * without fee, provided the above notices are retained on all copies. * Permission to modify the code and to distribute modified code is granted, * provided the above notices are retained, and a notice that the code was * modified is included with the above copyright notice. * */#ifndef _STLP_DEBUG_H#define _STLP_DEBUG_H#if (defined (_STLP_DEBUG) || defined (_STLP_DEBUG_ALLOC)) && \    !defined (_STLP_ASSERTIONS)#  define _STLP_ASSERTIONS 1#endif#if defined (_STLP_ASSERTIONS)#  if !defined (_STLP_FILE__)#    define _STLP_FILE__ __FILE__#  endif_STLP_BEGIN_NAMESPACE_STLP_MOVE_TO_PRIV_NAMESPACEenum {  //General errors  _StlFormat_ERROR_RETURN,  _StlFormat_ASSERTION_FAILURE,  _StlFormat_VERBOSE_ASSERTION_FAILURE,  _StlMsg_INVALID_ARGUMENT,  //Container/Iterator related errors  _StlMsg_INVALID_CONTAINER,  _StlMsg_EMPTY_CONTAINER,  _StlMsg_ERASE_PAST_THE_END,  _StlMsg_OUT_OF_BOUNDS,  _StlMsg_NOT_OWNER,  _StlMsg_SHOULD_NOT_OWNER,  _StlMsg_INVALID_ITERATOR,  _StlMsg_INVALID_LEFTHAND_ITERATOR,  _StlMsg_INVALID_RIGHTHAND_ITERATOR,  _StlMsg_DIFFERENT_OWNERS     ,  _StlMsg_NOT_DEREFERENCEABLE  ,  _StlMsg_INVALID_RANGE        ,  _StlMsg_NOT_IN_RANGE_1       ,  _StlMsg_NOT_IN_RANGE_2       ,  _StlMsg_INVALID_ADVANCE      ,  _StlMsg_SINGULAR_ITERATOR    ,  //Bad predicate for sorting  _StlMsg_INVALID_STRICT_WEAK_PREDICATE,  _StlMsg_INVALID_EQUIVALENT_PREDICATE,  // debug alloc messages  _StlMsg_DBA_DELETED_TWICE    ,  _StlMsg_DBA_NEVER_ALLOCATED  ,  _StlMsg_DBA_TYPE_MISMATCH    ,  _StlMsg_DBA_SIZE_MISMATCH    ,  _StlMsg_DBA_UNDERRUN         ,  _StlMsg_DBA_OVERRUN          ,  // auto_ptr messages  _StlMsg_AUTO_PTR_NULL    ,  //Memory alignent message  _StlMsg_WRONG_MEMORY_ALIGNMENT,  _StlMsg_UNKNOWN  /* _StlMsg_MAX */};/* have to hardcode that ;() */#  define _StlMsg_MAX 31class __owned_link;class __owned_list;#  if defined (_STLP_DEBUG_MODE_THROWS)#    define _STLP_MESSAGE_NORETURN _STLP_FUNCTION_THROWS#  else#    define _STLP_MESSAGE_NORETURN#  endiftemplate <class _Dummy>class __stl_debug_engine {public:  // Basic routine to report any debug message  // Use _STLP_DEBUG_MESSAGE to override  static void _STLP_MESSAGE_NORETURN _STLP_CALL _Message(const char * format_str, ...);  // Micsellanous function to report indexed error message  static void _STLP_CALL  _IndexedError(int __ind, const char* __f, int __l);  // Basic assertion report mechanism.  // Reports failed assertion via __stl_debug_message and calls _Terminate  // if _STLP_DEBUG_TERMINATE is specified, calls __stl_debug_terminate instead  static void _STLP_CALL  _Assert(const char* __expr, const char* __f, int __l);  // The same, with additional diagnostics  static void _STLP_CALL  _VerboseAssert(const char* __expr, int __error_ind, const char* __f, int __l);  // If exceptions are present, sends unique exception  // If not, calls _STLP_ABORT() to terminate  // Use _STLP_DEBUG_TERMINATE to override  static void _STLP_CALL  _Terminate();#  if defined (_STLP_DEBUG)  // owned_list/link delegate non-inline functions here  static bool _STLP_CALL  _Check_same_owner( const __owned_link& __i1,                                             const __owned_link& __i2);  static bool _STLP_CALL  _Check_same_or_null_owner( const __owned_link& __i1,                                                     const __owned_link& __i2);  static bool _STLP_CALL  _Check_if_owner( const __owned_list*, const __owned_link&);  static bool _STLP_CALL  _Check_if_not_owner( const __owned_list*, const __owned_link&);  static void _STLP_CALL  _Verify(const __owned_list*);  static void _STLP_CALL  _Swap_owners(__owned_list&, __owned_list&);  static void _STLP_CALL  _Invalidate_all(__owned_list*);  static void _STLP_CALL  _Set_owner(__owned_list& /*src*/, __owned_list& /*dst*/);  static void _STLP_CALL  _Stamp_all(__owned_list*, __owned_list*);  static void _STLP_CALL  _M_detach(__owned_list*, __owned_link*);  static void _STLP_CALL  _M_attach(__owned_list*, __owned_link*);  // accessor : check and get pointer to the container  static void* _STLP_CALL  _Get_container_ptr(const __owned_link*);#  endif  // debug messages and formats  static const char* _Message_table[_StlMsg_MAX];};#  undef _STLP_MESSAGE_NORETURN#  if defined (_STLP_USE_TEMPLATE_EXPORT)_STLP_EXPORT_TEMPLATE_CLASS __stl_debug_engine<bool>;#  endiftypedef __stl_debug_engine<bool> __stl_debugger;_STLP_MOVE_TO_STD_NAMESPACE_STLP_END_NAMESPACE#  if !defined (_STLP_ASSERT)#    define _STLP_ASSERT(expr) \       if (!(expr)) { _STLP_PRIV __stl_debugger::_Assert( # expr, _STLP_FILE__, __LINE__); }#  endif#else#  define _STLP_ASSERT(expr)#endif// this section is for _STLP_DEBUG only#if defined (_STLP_DEBUG)#  if !defined (_STLP_VERBOSE_ASSERT)// fbp : new form not requiring ";"#    define _STLP_VERBOSE_ASSERT(expr, __diag_num) \       if (!(expr)) { _STLP_PRIV __stl_debugger::_VerboseAssert\                               ( # expr,  _STLP_PRIV __diag_num, _STLP_FILE__, __LINE__ ); \          }#  endif#  define _STLP_DEBUG_CHECK(expr) _STLP_ASSERT(expr)#  if (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)#    define _STLP_STD_DEBUG_CHECK(expr) _STLP_DEBUG_CHECK(expr)#  else#    define _STLP_STD_DEBUG_CHECK(expr)#  endif#  if !defined (_STLP_VERBOSE_RETURN)#    define _STLP_VERBOSE_RETURN(__expr,__diag_num) if (!(__expr)) { \         _STLP_PRIV __stl_debugger::_IndexedError(__diag_num, _STLP_FILE__ , __LINE__); \         return false; }#  endif#  if !defined (_STLP_VERBOSE_RETURN_0)#    define _STLP_VERBOSE_RETURN_0(__expr,__diag_num) if (!(__expr)) { \         _STLP_PRIV __stl_debugger::_IndexedError(__diag_num, _STLP_FILE__, __LINE__); \         return 0; }#  endif#  ifndef _STLP_INTERNAL_THREADS_H#    include <stl/_threads.h>#  endif#  ifndef _STLP_INTERNAL_ITERATOR_BASE_H#    include <stl/_iterator_base.h>#  endif#  ifndef _STLP_TYPE_TRAITS_H#    include <stl/type_traits.h>#  endif_STLP_BEGIN_NAMESPACE_STLP_MOVE_TO_PRIV_NAMESPACE/* * Special debug iterator traits having an additionnal static member * method _Check. It is used by the slist debug implementation to check * the special before_begin iterator. */template <class _Traits>struct _DbgTraits : _Traits {  typedef _DbgTraits<typename _Traits::_ConstTraits> _ConstTraits;  typedef _DbgTraits<typename _Traits::_NonConstTraits> _NonConstTraits;  template <class _Iterator>  static bool _Check(const _Iterator&) {return true;}};//=============================================================template <class _Iterator>inline bool  _STLP_CALL __valid_range(const _Iterator& __i1 ,const _Iterator& __i2,                                      const random_access_iterator_tag&){ return (__i1 < __i2) || (__i1 == __i2); }template <class _Iterator>inline bool  _STLP_CALL __valid_range(const _Iterator& __i1 ,const _Iterator& __i2,                                      const bidirectional_iterator_tag&) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?