epoc32/include/tools/stlport/stl/debug/_debug.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2  *
     3  * Copyright (c) 1997
     4  * Moscow Center for SPARC Technology
     5  *
     6  * Copyright (c) 1999
     7  * Boris Fomitchev
     8  *
     9  * This material is provided "as is", with absolutely no warranty expressed
    10  * or implied. Any use is at your own risk.
    11  *
    12  * Permission to use or copy this software for any purpose is hereby granted
    13  * without fee, provided the above notices are retained on all copies.
    14  * Permission to modify the code and to distribute modified code is granted,
    15  * provided the above notices are retained, and a notice that the code was
    16  * modified is included with the above copyright notice.
    17  *
    18  */
    19 
    20 #ifndef _STLP_DEBUG_H
    21 #define _STLP_DEBUG_H
    22 
    23 #if defined (_STLP_ASSERTIONS) || defined (_STLP_DEBUG)
    24 
    25 #  ifndef _STLP_TYPE_TRAITS_H
    26 #    include <stl/type_traits.h>
    27 #  endif
    28 
    29 #  if !defined (_STLP_EXTRA_OPERATORS_FOR_DEBUG) && \
    30       (defined (_STLP_BASE_MATCH_BUG) || (defined (_STLP_MSVC) && _STLP_MSVC < 1100))
    31 #    define _STLP_EXTRA_OPERATORS_FOR_DEBUG
    32 #  endif
    33 
    34 #  if !defined (_STLP_FILE__)
    35 #    define _STLP_FILE__ __FILE__
    36 #  endif
    37 
    38 _STLP_BEGIN_NAMESPACE
    39 
    40 _STLP_MOVE_TO_PRIV_NAMESPACE
    41 
    42 enum {
    43   //General errors
    44   _StlFormat_ERROR_RETURN,
    45   _StlFormat_ASSERTION_FAILURE,
    46   _StlFormat_VERBOSE_ASSERTION_FAILURE,
    47   _StlMsg_INVALID_ARGUMENT,
    48   //Container/Iterator related errors
    49   _StlMsg_INVALID_CONTAINER,
    50   _StlMsg_EMPTY_CONTAINER,
    51   _StlMsg_ERASE_PAST_THE_END,
    52   _StlMsg_OUT_OF_BOUNDS,
    53   _StlMsg_NOT_OWNER,
    54   _StlMsg_SHOULD_NOT_OWNER,
    55   _StlMsg_INVALID_ITERATOR,
    56   _StlMsg_INVALID_LEFTHAND_ITERATOR,
    57   _StlMsg_INVALID_RIGHTHAND_ITERATOR,
    58   _StlMsg_DIFFERENT_OWNERS     ,
    59   _StlMsg_NOT_DEREFERENCEABLE  ,
    60   _StlMsg_INVALID_RANGE        ,
    61   _StlMsg_NOT_IN_RANGE_1       ,
    62   _StlMsg_NOT_IN_RANGE_2       ,
    63   _StlMsg_INVALID_ADVANCE      ,
    64   _StlMsg_SINGULAR_ITERATOR    ,
    65   //Bad predicate for sorting
    66   _StlMsg_INVALID_STRICT_WEAK_PREDICATE,
    67   _StlMsg_INVALID_EQUIVALENT_PREDICATE,
    68   // debug alloc messages
    69   _StlMsg_DBA_DELETED_TWICE    ,
    70   _StlMsg_DBA_NEVER_ALLOCATED  ,
    71   _StlMsg_DBA_TYPE_MISMATCH    ,
    72   _StlMsg_DBA_SIZE_MISMATCH    ,
    73   _StlMsg_DBA_UNDERRUN         ,
    74   _StlMsg_DBA_OVERRUN          ,
    75   // auto_ptr messages
    76   _StlMsg_AUTO_PTR_NULL    ,
    77   //Memory alignent message
    78   _StlMsg_WRONG_MEMORY_ALIGNMENT,
    79   _StlMsg_UNKNOWN
    80   /* _StlMsg_MAX */
    81 };
    82 
    83 /* have to hardcode that ;() */
    84 #  define _StlMsg_MAX 31
    85 
    86 // This class is unique (not inherited from exception),
    87 // to disallow catch in anything but (...)
    88 struct __stl_debug_exception {
    89   // no members
    90 };
    91 
    92 class _STLP_CLASS_DECLSPEC __owned_link;
    93 class _STLP_CLASS_DECLSPEC __owned_list;
    94 
    95 #if defined (_STLP_DEBUG_MODE_THROWS)
    96 #  define _STLP_MESSAGE_NORETURN _STLP_FUNCTION_THROWS
    97 #else
    98 #  define _STLP_MESSAGE_NORETURN
    99 #endif
   100 
   101 template <class _Dummy>
   102 struct __stl_debug_engine {
   103 
   104   // Basic routine to report any debug message
   105   // Use _STLP_DEBUG_MESSAGE to override
   106   static void _STLP_MESSAGE_NORETURN _STLP_CALL _Message(const char * format_str, ...);
   107 
   108   // Micsellanous function to report indexed error message
   109   static void _STLP_CALL  _IndexedError(int __ind, const char* __f, int __l);
   110 
   111   // Basic assertion report mechanism.
   112   // Reports failed assertion via __stl_debug_message and calls _Terminate
   113   // if _STLP_DEBUG_TERMINATE is specified, calls __stl_debug_terminate instead
   114   static void _STLP_CALL  _Assert(const char* __expr, const char* __f, int __l);
   115 
   116   // The same, with additional diagnostics
   117   static void _STLP_CALL  _VerboseAssert(const char* __expr, int __error_ind, const char* __f, int __l);
   118 
   119   // If exceptions are present, sends unique exception
   120   // If not, calls _STLP_ABORT() to terminate
   121   // Use _STLP_DEBUG_TERMINATE to override
   122   static void _STLP_CALL  _Terminate();
   123 
   124 #  if defined (_STLP_DEBUG)
   125   // owned_list/link delegate non-inline functions here
   126 
   127   static bool _STLP_CALL  _Check_same_owner( const __owned_link& __i1,
   128                                              const __owned_link& __i2);
   129   static bool _STLP_CALL  _Check_same_or_null_owner( const __owned_link& __i1,
   130                                                      const __owned_link& __i2);
   131   static bool _STLP_CALL  _Check_if_owner( const __owned_list*, const __owned_link&);
   132 
   133   static bool _STLP_CALL  _Check_if_not_owner( const __owned_list*, const __owned_link&);
   134 
   135   static void _STLP_CALL  _Verify(const __owned_list*);
   136 
   137   static void _STLP_CALL  _Swap_owners(__owned_list&, __owned_list&);
   138 
   139   static void _STLP_CALL  _Invalidate_all(__owned_list*);
   140 
   141   static void _STLP_CALL  _Set_owner(__owned_list& /*src*/, __owned_list& /*dst*/);
   142 
   143   static void _STLP_CALL  _Stamp_all(__owned_list*, __owned_list*);
   144 
   145   static void _STLP_CALL  _M_detach(__owned_list*, __owned_link*);
   146 
   147   static void _STLP_CALL  _M_attach(__owned_list*, __owned_link*);
   148 
   149   // accessor : check and get pointer to the container
   150   static void* _STLP_CALL  _Get_container_ptr(const __owned_link*);
   151 #  endif
   152 
   153   // debug messages and formats
   154   static _STLP_STATIC_MEMBER_DECLSPEC const char* _Message_table[_StlMsg_MAX];
   155 };
   156 
   157 #undef _STLP_MESSAGE_NORETURN
   158 
   159 #  if defined (_STLP_USE_TEMPLATE_EXPORT)
   160 _STLP_EXPORT_TEMPLATE struct _STLP_CLASS_DECLSPEC __stl_debug_engine<bool>;
   161 #  endif /* _STLP_USE_TEMPLATE_EXPORT */
   162 
   163 typedef __stl_debug_engine<bool> __stl_debugger;
   164 
   165 _STLP_MOVE_TO_STD_NAMESPACE
   166 
   167 _STLP_END_NAMESPACE
   168 
   169 #  if !defined (_STLP_ASSERT)
   170 #    define _STLP_ASSERT(expr) \
   171        if (!(expr)) { _STLP_PRIV __stl_debugger::_Assert( # expr, _STLP_FILE__, __LINE__); }
   172 #  endif
   173 
   174 #endif /* _STLP_ASSERTIONS || _STLP_DEBUG */
   175 
   176 // this section is for _STLP_DEBUG only
   177 #if defined (_STLP_DEBUG)
   178 
   179 #  if !defined (_STLP_VERBOSE_ASSERT)
   180 // fbp : new form not requiring ";"
   181 #    define _STLP_VERBOSE_ASSERT(expr, __diag_num) \
   182        if (!(expr)) { _STLP_PRIV __stl_debugger::_VerboseAssert\
   183                                ( # expr,  _STLP_PRIV __diag_num, _STLP_FILE__, __LINE__ ); \
   184           }
   185 #  endif
   186 
   187 #  define _STLP_DEBUG_CHECK(expr) _STLP_ASSERT(expr)
   188 #  define _STLP_DEBUG_DO(expr)    expr;
   189 
   190 #  if (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
   191 #    define _STLP_STD_DEBUG_CHECK(expr) _STLP_DEBUG_CHECK(expr)
   192 #    define _STLP_STD_DEBUG_DO(expr) _STLP_DEBUG_DO(expr)
   193 #  else
   194 #    define _STLP_STD_DEBUG_CHECK(expr)
   195 #    define _STLP_STD_DEBUG_DO(expr)
   196 #  endif
   197 
   198 #  if !defined (_STLP_VERBOSE_RETURN)
   199 #    define _STLP_VERBOSE_RETURN(__expr,__diag_num) if (!(__expr)) { \
   200          _STLP_PRIV __stl_debugger::_IndexedError(__diag_num, _STLP_FILE__ , __LINE__); \
   201          return false; }
   202 #  endif
   203 
   204 #  if !defined (_STLP_VERBOSE_RETURN_0)
   205 #    define _STLP_VERBOSE_RETURN_0(__expr,__diag_num) if (!(__expr)) { \
   206          _STLP_PRIV __stl_debugger::_IndexedError(__diag_num, _STLP_FILE__, __LINE__); \
   207          return 0; }
   208 #  endif
   209 
   210 #  ifndef _STLP_INTERNAL_THREADS_H
   211 #    include <stl/_threads.h>
   212 #  endif
   213 
   214 #  ifndef _STLP_INTERNAL_ITERATOR_BASE_H
   215 #    include <stl/_iterator_base.h>
   216 #  endif
   217 
   218 _STLP_BEGIN_NAMESPACE
   219 
   220 _STLP_MOVE_TO_PRIV_NAMESPACE
   221 
   222 /*
   223  * Special debug iterator traits having an additionnal static member
   224  * method _Check. It is used by the slit debug implementation to check
   225  * the special before_begin iterator.
   226  */
   227 template <class _Traits>
   228 struct _DbgTraits : _Traits {
   229   typedef _DbgTraits<typename _Traits::_ConstTraits> _ConstTraits;
   230   typedef _DbgTraits<typename _Traits::_NonConstTraits> _NonConstTraits;
   231 
   232   template <class _Iterator>
   233   static bool _Check(const _Iterator&) {return true;}
   234 };
   235 
   236 //=============================================================
   237 template <class _Iterator>
   238 inline bool  _STLP_CALL __valid_range(const _Iterator& __i1 ,const _Iterator& __i2,
   239                                       const random_access_iterator_tag&)
   240 { return (__i1 < __i2) || (__i1 == __i2); }
   241 
   242 template <class _Iterator>
   243 inline bool  _STLP_CALL __valid_range(const _Iterator& __i1 ,const _Iterator& __i2,
   244                                       const bidirectional_iterator_tag&) {
   245   // check if comparable
   246   bool __dummy(__i1==__i2);
   247   return (__dummy==__dummy);
   248 }
   249 
   250 template <class _Iterator>
   251 inline bool  _STLP_CALL __valid_range(const _Iterator& __i1 ,const _Iterator& __i2,
   252                                       const forward_iterator_tag&) {
   253   // check if comparable
   254   bool __dummy(__i1==__i2);
   255   return (__dummy==__dummy);
   256 }
   257 
   258 template <class _Iterator>
   259 inline bool  _STLP_CALL __valid_range(const _Iterator&,const _Iterator&,
   260                                       const input_iterator_tag&)
   261 { return true; }
   262 
   263 template <class _Iterator>
   264 inline bool  _STLP_CALL __valid_range(const _Iterator&,const _Iterator&,
   265                                       const output_iterator_tag&)
   266 { return true; }
   267 
   268 template <class _Iterator>
   269 inline bool _STLP_CALL __valid_range(const _Iterator& __i1, const _Iterator& __i2)
   270 { return __valid_range(__i1,__i2,_STLP_ITERATOR_CATEGORY(__i1, _Iterator)); }
   271 
   272 // Note : that means in range [i1, i2].
   273 template <class _Iterator>
   274 inline bool  _STLP_CALL __in_range(const _Iterator& _It,
   275                                    const _Iterator& __i1, const _Iterator& __i2)
   276 { return __valid_range(__i1,_It) && __valid_range(_It,__i2); }
   277 
   278 template <class _Iterator>
   279 inline bool  _STLP_CALL __in_range(const _Iterator& __first, const _Iterator& __last,
   280                                    const _Iterator& __start, const _Iterator& __finish)
   281 { return __valid_range(__first,__last) && __valid_range(__start,__first) && __valid_range(__last,__finish); }
   282 
   283 //==========================================================
   284 class _STLP_CLASS_DECLSPEC __owned_link {
   285 public:
   286   __owned_link() : _M_owner(0) {}
   287   __owned_link(const __owned_list* __c) : _M_owner(0), _M_next(0)
   288   { __stl_debugger::_M_attach(__CONST_CAST(__owned_list*,__c), this); }
   289   __owned_link(const __owned_link& __rhs): _M_owner(0)
   290   { __stl_debugger::_M_attach(__CONST_CAST(__owned_list*,__rhs._M_owner), this); }
   291   __owned_link& operator=(const __owned_link& __rhs) {
   292     __owned_list* __new_owner = __CONST_CAST(__owned_list*,__rhs._M_owner);
   293     __owned_list* __old_owner = _M_owner;
   294     if ( __old_owner != __new_owner ) {
   295       __stl_debugger::_M_detach(__old_owner, this);
   296       __stl_debugger::_M_attach(__new_owner, this);
   297     }
   298     return *this;
   299   }
   300   ~__owned_link() {
   301     __stl_debugger::_M_detach(_M_owner, this);
   302     _Invalidate();
   303   }
   304 
   305   const __owned_list* _Owner() const { return _M_owner; }
   306   __owned_list* _Owner() { return _M_owner; }
   307   void _Set_owner(const __owned_list* __o) { _M_owner= __CONST_CAST(__owned_list*,__o); }
   308   bool _Valid() const { return _M_owner != 0; }
   309   void _Invalidate() { _M_owner = 0; _M_next = 0; }
   310   void _Link_to_self() { _M_next = 0; }
   311 
   312   __owned_link* _Next() { return _M_next; }
   313   const __owned_link* _Next() const { return _M_next; }
   314 
   315 public:
   316   __owned_list* _M_owner;
   317   __owned_link* _M_next;
   318 };
   319 
   320 
   321 class _STLP_CLASS_DECLSPEC __owned_list {
   322 public:
   323   __owned_list(void* __o) {
   324     //    fprintf(stderr, "__owned_list(): %p\n",(void*)this);
   325     _M_node._M_owner = __REINTERPRET_CAST(__owned_list*,__o);
   326     _M_node._M_next = 0;
   327   }
   328   ~__owned_list() {
   329     //    fprintf(stderr, "~__owned_list(): %p\n",(void*)this);
   330     _Invalidate_all();
   331     // that prevents detach
   332     _M_node._Invalidate();
   333   }
   334   const void* _Owner() const { return (const void*)_M_node._M_owner; }
   335   void* _Owner() { return (void*)_M_node._M_owner; }
   336   bool  _Valid() const { return _M_node._M_owner != 0; }
   337   void _Invalidate() { _M_node._M_owner = 0; }
   338 
   339   __owned_link* _First() { return _M_node._Next(); }
   340   __owned_link* _Last() { return 0 ; }
   341 
   342   const __owned_link* _First() const { return (__owned_link*)_M_node._M_next; }
   343   const __owned_link* _Last() const { return 0 ;}
   344 
   345   void _Verify() const { __stl_debugger::_Verify(this); }
   346   void _Swap_owners(__owned_list& __y) { __stl_debugger::_Swap_owners(*this, __y); }
   347   void _Invalidate_all() { __stl_debugger::_Invalidate_all(this); }
   348   void _Set_owner(__owned_list& __y) { __stl_debugger::_Set_owner(*this, __y); }
   349 
   350   mutable __owned_link _M_node;
   351   mutable _STLP_mutex  _M_lock;
   352 
   353 private:
   354   // should never be called, should be left not implemented,
   355   // but some compilers complain about it ;(
   356   __owned_list(const __owned_list&){}
   357   __owned_list& operator = (const __owned_list&) { return *this; }
   358 
   359   friend class __owned_link;
   360   friend struct __stl_debug_engine<bool>;
   361 };
   362 
   363 
   364 //==========================================================
   365 
   366 // forward declaratioins
   367 
   368 template <class _Iterator>
   369 bool _STLP_CALL __check_range(const _Iterator&, const _Iterator&);
   370 template <class _Iterator>
   371 bool _STLP_CALL __check_range(const _Iterator&,
   372                               const _Iterator&, const _Iterator&);
   373 template <class _Iterator>
   374 bool _STLP_CALL __check_range(const _Iterator&, const _Iterator& ,
   375                               const _Iterator&, const _Iterator& );
   376 template <class _Tp>
   377 bool _STLP_CALL __check_ptr_range(const _Tp*, const _Tp*);
   378 
   379 
   380 template <class _Iterator>
   381 void _STLP_CALL __invalidate_range(const __owned_list* __base,
   382                                    const _Iterator& __first,
   383                                    const _Iterator& __last);
   384 
   385 template <class _Iterator>
   386 void _STLP_CALL __invalidate_iterator(const __owned_list* __base,
   387                                       const _Iterator& __it);
   388 
   389 template <class _Iterator>
   390 void _STLP_CALL __change_range_owner(const _Iterator& __first,
   391                                      const _Iterator& __last,
   392                                      const __owned_list* __dst);
   393 
   394 template <class _Iterator>
   395 void  _STLP_CALL __change_ite_owner(const _Iterator& __it,
   396                                     const __owned_list* __dst);
   397 
   398 //============================================================
   399 inline bool _STLP_CALL
   400 __check_same_owner(const __owned_link& __i1, const __owned_link& __i2)
   401 { return __stl_debugger::_Check_same_owner(__i1,__i2); }
   402 
   403 inline bool _STLP_CALL
   404 __check_same_or_null_owner(const __owned_link& __i1, const __owned_link& __i2)
   405 { return __stl_debugger::_Check_same_or_null_owner(__i1,__i2); }
   406 
   407 template <class _Iterator>
   408 inline bool _STLP_CALL  __check_if_owner( const __owned_list* __owner,
   409                                           const _Iterator& __it)
   410 { return __stl_debugger::_Check_if_owner(__owner, (const __owned_link&)__it); }
   411 
   412 template <class _Iterator>
   413 inline bool _STLP_CALL __check_if_not_owner( const __owned_list* /*__owner*/,
   414                                              const _Iterator& /*__it*/,
   415                                              const __false_type&)
   416 { return true; }
   417 
   418 template <class _Iterator>
   419 inline bool _STLP_CALL __check_if_not_owner( const __owned_list* __owner,
   420                                              const _Iterator& __it,
   421                                              const __true_type&)
   422 { return __stl_debugger::_Check_if_not_owner(__owner, (const __owned_link&)__it); }
   423 
   424 _STLP_MOVE_TO_STD_NAMESPACE
   425 
   426 _STLP_END_NAMESPACE
   427 
   428 #endif /* _STLP_DEBUG */
   429 
   430 #if defined (_STLP_ASSERTIONS)
   431 
   432 #  if !defined (_STLP_ASSERT_MSG_TRAILER)
   433 #    define _STLP_ASSERT_MSG_TRAILER
   434 #  endif
   435 
   436 // dwa 12/30/98 - if _STLP_DEBUG_MESSAGE is defined, the user can supply own definition.
   437 #  if !defined (_STLP_DEBUG_MESSAGE)
   438 #    define __stl_debug_message __stl_debugger::_Message
   439 #  else
   440 extern  void __stl_debug_message(const char * format_str, ...);
   441 #  endif
   442 
   443 // fbp: if _STLP_DEBUG_TERMINATE is defined, the user can supply own definition.
   444 #  if !defined (_STLP_DEBUG_TERMINATE)
   445 #    define __stl_debug_terminate __stl_debugger::_Terminate
   446 #  else
   447 extern  void __stl_debug_terminate();
   448 #  endif
   449 
   450 #endif
   451 
   452 #if !defined (_STLP_LINK_TIME_INSTANTIATION)
   453 #  include <stl/debug/_debug.c>
   454 #endif
   455 
   456 #endif /* DEBUG_H */
   457 
   458 // Local Variables:
   459 // mode:C++
   460 // End: