epoc32/include/stdapis/stlportv5/stl/_construct.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/stdapis/stlport/stl/_construct.h@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     1 /*
     2  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
     3  * Copyright (c) 1994
     4  * Hewlett-Packard Company
     5  *
     6  * Copyright (c) 1996,1997
     7  * Silicon Graphics Computer Systems, Inc.
     8  *
     9  * Copyright (c) 1997
    10  * Moscow Center for SPARC Technology
    11  *
    12  * Copyright (c) 1999 
    13  * Boris Fomitchev
    14  *
    15  * This material is provided "as is", with absolutely no warranty expressed
    16  * or implied. Any use is at your own risk.
    17  *
    18  * Permission to use or copy this software for any purpose is hereby granted 
    19  * without fee, provided the above notices are retained on all copies.
    20  * Permission to modify the code and to distribute modified code is granted,
    21  * provided the above notices are retained, and a notice that the code was
    22  * modified is included with the above copyright notice.
    23  *
    24  */
    25 
    26 /* NOTE: This is an internal header file, included by other STL headers.
    27  *   You should not attempt to use it directly.
    28  */
    29 
    30 #ifndef _STLP_INTERNAL_CONSTRUCT_H
    31 #define _STLP_INTERNAL_CONSTRUCT_H
    32 
    33 #ifdef _STLP_USE_TRAP_LEAVE
    34 #include <e32base.h>
    35 #endif // _STLP_USE_TRAP_LEAVE
    36 
    37 # if defined (_STLP_DEBUG_UNINITIALIZED) && ! defined (_STLP_CSTRING)
    38 # include <cstring>
    39 # endif
    40 
    41 # ifndef _STLP_INTERNAL_NEW_HEADER
    42 #  include <stl/_new.h>
    43 # endif
    44 
    45 
    46 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
    47 # include <stl/_iterator_base.h>
    48 #endif
    49 
    50 _STLP_BEGIN_NAMESPACE
    51 
    52 # ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
    53 template <class _Tp>
    54 inline void __destroy_aux(_Tp* __pointer, const __false_type&) { __pointer->~_Tp(); }
    55 template <class _Tp>
    56 inline void __destroy_aux(_Tp* __pointer, const __true_type&) {}
    57 # endif
    58 
    59 template <class _Tp>
    60 inline void _Destroy(_Tp* __pointer) {
    61 # if _MSC_VER >= 1010
    62   __pointer;
    63 # endif	// _MSC_VER >= 1000
    64 # ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
    65   typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
    66   __destroy_aux(__pointer, _Trivial_destructor());
    67 # else
    68 #  if ( defined (__BORLANDC__) && ( __BORLANDC__ < 0x500 ) )
    69     __pointer->_Tp::~_Tp();
    70 #  else
    71     __pointer->~_Tp();
    72 #  endif
    73 # endif
    74 # ifdef _STLP_DEBUG_UNINITIALIZED
    75 	memset((char*)__pointer, _STLP_SHRED_BYTE, sizeof(_Tp));
    76 # endif
    77 }
    78 
    79 # if defined (new)
    80 #   define _STLP_NEW_REDEFINE new
    81 #   undef new
    82 # endif 
    83 
    84 # ifdef _STLP_DEFAULT_CONSTRUCTOR_BUG
    85 template <class _T1>
    86 inline void _Construct_aux (_T1* __p, const __false_type&) {
    87 _STLP_PLACEMENT_NEW (__p) _T1();
    88 }
    89 
    90 template <class _T1>
    91 inline void _Construct_aux (_T1* __p, const __true_type&) {
    92 _STLP_PLACEMENT_NEW (__p) _T1(0);
    93 }
    94 # endif
    95 
    96 template <class _T1, class _T2>
    97 inline void _Construct(_T1* __p, const _T2& __val) {
    98 # ifdef _STLP_DEBUG_UNINITIALIZED
    99 	memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
   100 # endif
   101     _STLP_PLACEMENT_NEW (__p) _T1(__val);
   102 }
   103 
   104 template <class _T1>
   105 inline void _Construct(_T1* __p) {
   106 # ifdef _STLP_DEBUG_UNINITIALIZED
   107   memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
   108 # endif
   109 # ifdef _STLP_DEFAULT_CONSTRUCTOR_BUG
   110 typedef typename _Is_integer<_T1>::_Integral _Is_Integral;
   111 _Construct_aux (__p, _Is_Integral() );
   112 # else
   113   _STLP_PLACEMENT_NEW (__p) _T1();
   114 # endif
   115 }
   116 
   117 # if defined(_STLP_NEW_REDEFINE)
   118 # ifdef DEBUG_NEW
   119 #  define new DEBUG_NEW
   120 # endif
   121 #  undef _STLP_NEW_REDEFINE
   122 # endif 
   123 
   124 template <class _ForwardIterator>
   125 _STLP_INLINE_LOOP void
   126 __destroy_aux(_ForwardIterator __first, _ForwardIterator __last, const __false_type&) {
   127   for ( ; __first != __last; ++__first)
   128     _STLP_STD::_Destroy(&*__first);
   129 }
   130 
   131 template <class _ForwardIterator> 
   132 inline void __destroy_aux(_ForwardIterator, _ForwardIterator, const __true_type&) {}
   133 
   134 template <class _ForwardIterator, class _Tp>
   135 inline void 
   136 __destroy(_ForwardIterator __first, _ForwardIterator __last, _Tp*) {
   137   typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
   138   __destroy_aux(__first, __last, _Trivial_destructor());
   139 }
   140 
   141 template <class _ForwardIterator>
   142 inline void _Destroy(_ForwardIterator __first, _ForwardIterator __last) {
   143   __destroy(__first, __last, _STLP_VALUE_TYPE(__first, _ForwardIterator));
   144 }
   145 
   146 inline void _Destroy(char*, char*) {}
   147 # ifdef _STLP_HAS_WCHAR_T // dwa 8/15/97
   148 inline void _Destroy(wchar_t*, wchar_t*) {}
   149 inline void _Destroy(const wchar_t*, const wchar_t*) {}
   150 # endif
   151 
   152 # ifndef _STLP_NO_ANACHRONISMS
   153 // --------------------------------------------------
   154 // Old names from the HP STL.
   155 
   156 template <class _T1, class _T2>
   157 inline void construct(_T1* __p, const _T2& __val) {_Construct(__p, __val); }
   158 template <class _T1>
   159 inline void construct(_T1* __p) { _Construct(__p); }
   160 template <class _Tp>
   161 inline void destroy(_Tp* __pointer) {  _STLP_STD::_Destroy(__pointer); }
   162 template <class _ForwardIterator>
   163 inline void destroy(_ForwardIterator __first, _ForwardIterator __last) { _STLP_STD::_Destroy(__first, __last); }
   164 # endif
   165 
   166 #ifdef _STLP_USE_TRAP_LEAVE
   167 
   168 struct TCleanupOverlay
   169 {
   170     TAny *vtable;
   171     TAny *iBase;
   172     TAny *iTop;
   173     TAny *iNext;
   174 };
   175 
   176 template <class _Tp>
   177 struct _STLP_StackHelper {
   178   static unsigned int Check( void *ptr );
   179   static void* _NewLC (size_t __n);
   180 };
   181 
   182 struct _STLP_StackPopper {
   183   ~_STLP_StackPopper() { CleanupStack::Pop(); }
   184 };
   185 
   186 template <class _Tp>
   187 struct _STLP_Cleanup {
   188   static void clear(TAny* __p);
   189 };
   190 
   191 # define _STLP_PUSH_CLEANUP_ITEM(_Tp, __p)  CleanupStack::PushL(TCleanupItem(&_STLP_Cleanup< _Tp >::clear, (TAny*)__p));
   192 # define _STLP_PUSH_STACK_ITEM(_Tp, __p)  _STLP_PUSH_CLEANUP_ITEM(_Tp, __p)   _STLP_StackPopper __Popper; _STLP_no_unused_variable_warning( __Popper );
   193 # define _STLP_POP_IF_CHECK if (_STLP_StackHelper<bool>::Check(this)) CleanupStack::Pop();
   194 # define _STLP_POP_CLEANUP_ITEM CleanupStack::Pop(); _STLP_POP_IF_CHECK
   195 
   196 # define _STLP_POP_ITEM CleanupStack::Pop();
   197 
   198 // to be used in complex object constructors
   199 template <class _Tp>
   200 struct _STLP_StackPusher {
   201   _STLP_StackPusher(_Tp * __p) { _STLP_PUSH_CLEANUP_ITEM(_Tp, (void*)__p) }
   202 };
   203 
   204 template <class _Tp>
   205 unsigned int _STLP_StackHelper<_Tp>::Check( void *ptr )
   206 
   207 {
   208     TCleanupTrapHandler *handler =
   209         (TCleanupTrapHandler *)User::TrapHandler();
   210 
   211     CCleanup &cleanup = handler->Cleanup();
   212 
   213     TCleanupOverlay *overlay = (TCleanupOverlay *)( &cleanup );
   214 
   215     char *raw = (char *)(overlay->iNext) - 4;
   216     void *topptr = *( (void **)(raw) );
   217 
   218     return ( ptr == topptr );
   219 } 
   220 
   221 
   222 template <class _Tp>
   223 void* _STLP_StackHelper<_Tp>::_NewLC(size_t __n) { 
   224   void* __p = ::operator new (__n, ELeave) ; 
   225   // constructor will pop it back
   226   CleanupStack::PushL(__p); 
   227   return __p;
   228 }
   229 
   230 template <class _Tp>
   231 void _STLP_Cleanup<_Tp>::clear(TAny* __p)
   232 {
   233   ((_Tp*)__p)->~_Tp();
   234 }
   235 
   236 
   237 #else
   238 # define _STLP_PUSH_CLEANUP_ITEM(_Tp, __p)
   239 # define _STLP_POP_CLEANUP_ITEM
   240 # define _STLP_PUSH_STACK_ITEM(_Tp, p)
   241 # define _STLP_POP_ITEM
   242 # define _STLP_POP_IF_CHECK
   243 # define TPush TLeave
   244 #endif
   245 
   246 _STLP_END_NAMESPACE
   247 
   248 #endif /* _STLP_INTERNAL_CONSTRUCT_H */
   249 
   250 // Local Variables:
   251 // mode:C++
   252 // End: