epoc32/include/stdapis/stlportv5/stl/_construct.h
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
     1.1 --- a/epoc32/include/stdapis/stlportv5/stl/_construct.h	Wed Mar 31 12:27:01 2010 +0100
     1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_construct.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
     1.6 + *
     1.7   * Copyright (c) 1994
     1.8   * Hewlett-Packard Company
     1.9   *
    1.10 @@ -9,13 +9,13 @@
    1.11   * Copyright (c) 1997
    1.12   * Moscow Center for SPARC Technology
    1.13   *
    1.14 - * Copyright (c) 1999 
    1.15 + * Copyright (c) 1999
    1.16   * Boris Fomitchev
    1.17   *
    1.18   * This material is provided "as is", with absolutely no warranty expressed
    1.19   * or implied. Any use is at your own risk.
    1.20   *
    1.21 - * Permission to use or copy this software for any purpose is hereby granted 
    1.22 + * Permission to use or copy this software for any purpose is hereby granted
    1.23   * without fee, provided the above notices are retained on all copies.
    1.24   * Permission to modify the code and to distribute modified code is granted,
    1.25   * provided the above notices are retained, and a notice that the code was
    1.26 @@ -30,218 +30,211 @@
    1.27  #ifndef _STLP_INTERNAL_CONSTRUCT_H
    1.28  #define _STLP_INTERNAL_CONSTRUCT_H
    1.29  
    1.30 -#ifdef _STLP_USE_TRAP_LEAVE
    1.31 -#include <e32base.h>
    1.32 -#endif // _STLP_USE_TRAP_LEAVE
    1.33 +#if !defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_INTERNAL_CSTRING)
    1.34 +#  include <stl/_cstring.h>
    1.35 +#endif
    1.36  
    1.37 -# if defined (_STLP_DEBUG_UNINITIALIZED) && ! defined (_STLP_CSTRING)
    1.38 -# include <cstring>
    1.39 -# endif
    1.40 -
    1.41 -# ifndef _STLP_INTERNAL_NEW_HEADER
    1.42 +#ifndef _STLP_INTERNAL_NEW
    1.43  #  include <stl/_new.h>
    1.44 -# endif
    1.45 -
    1.46 +#endif
    1.47  
    1.48  #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
    1.49 -# include <stl/_iterator_base.h>
    1.50 +#  include <stl/_iterator_base.h>
    1.51 +#endif
    1.52 +
    1.53 +#ifndef _STLP_MOVE_CONSTRUCT_FWK_H
    1.54 +#  include <stl/_move_construct_fwk.h>
    1.55  #endif
    1.56  
    1.57  _STLP_BEGIN_NAMESPACE
    1.58  
    1.59 -# ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
    1.60  template <class _Tp>
    1.61 -inline void __destroy_aux(_Tp* __pointer, const __false_type&) { __pointer->~_Tp(); }
    1.62 +inline void __destroy_aux(_Tp* __pointer, const __false_type& /*_Trivial_destructor*/)
    1.63 +{ __pointer->~_Tp(); }
    1.64 +
    1.65  template <class _Tp>
    1.66 -inline void __destroy_aux(_Tp* __pointer, const __true_type&) {}
    1.67 -# endif
    1.68 +inline void __destroy_aux(_Tp*, const __true_type& /*_Trivial_destructor*/) {}
    1.69  
    1.70  template <class _Tp>
    1.71  inline void _Destroy(_Tp* __pointer) {
    1.72 -# if _MSC_VER >= 1010
    1.73 +#if defined (_STLP_MSVC) && (_STLP_MSVC <= 1010)
    1.74    __pointer;
    1.75 -# endif	// _MSC_VER >= 1000
    1.76 -# ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
    1.77 +#endif
    1.78    typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
    1.79    __destroy_aux(__pointer, _Trivial_destructor());
    1.80 -# else
    1.81 -#  if ( defined (__BORLANDC__) && ( __BORLANDC__ < 0x500 ) )
    1.82 -    __pointer->_Tp::~_Tp();
    1.83 -#  else
    1.84 -    __pointer->~_Tp();
    1.85 -#  endif
    1.86 -# endif
    1.87 -# ifdef _STLP_DEBUG_UNINITIALIZED
    1.88 -	memset((char*)__pointer, _STLP_SHRED_BYTE, sizeof(_Tp));
    1.89 -# endif
    1.90 +#if defined (_STLP_DEBUG_UNINITIALIZED)
    1.91 +  memset(__REINTERPRET_CAST(char*, __pointer), _STLP_SHRED_BYTE, sizeof(_Tp));
    1.92 +#endif
    1.93  }
    1.94  
    1.95 -# if defined (new)
    1.96 -#   define _STLP_NEW_REDEFINE new
    1.97 -#   undef new
    1.98 -# endif 
    1.99 +template <class _Tp>
   1.100 +inline void _Destroy_Moved(_Tp* __pointer) {
   1.101 +  typedef typename __move_traits<_Tp>::complete _Trivial_destructor;
   1.102 +  __destroy_aux(__pointer, _Trivial_destructor());
   1.103 +#if defined (_STLP_DEBUG_UNINITIALIZED)
   1.104 +  memset((char*)__pointer, _STLP_SHRED_BYTE, sizeof(_Tp));
   1.105 +#endif
   1.106 +}
   1.107  
   1.108 -# ifdef _STLP_DEFAULT_CONSTRUCTOR_BUG
   1.109 +#if defined (new)
   1.110 +#  define _STLP_NEW_REDEFINE new
   1.111 +#  undef new
   1.112 +#endif
   1.113 +
   1.114 +#if defined (_STLP_DEF_CONST_PLCT_NEW_BUG)
   1.115  template <class _T1>
   1.116  inline void _Construct_aux (_T1* __p, const __false_type&) {
   1.117 -_STLP_PLACEMENT_NEW (__p) _T1();
   1.118 +  _STLP_PLACEMENT_NEW (__p) _T1();
   1.119  }
   1.120  
   1.121  template <class _T1>
   1.122  inline void _Construct_aux (_T1* __p, const __true_type&) {
   1.123 -_STLP_PLACEMENT_NEW (__p) _T1(0);
   1.124 +  _STLP_PLACEMENT_NEW (__p) _T1(0);
   1.125  }
   1.126 -# endif
   1.127 -
   1.128 -template <class _T1, class _T2>
   1.129 -inline void _Construct(_T1* __p, const _T2& __val) {
   1.130 -# ifdef _STLP_DEBUG_UNINITIALIZED
   1.131 -	memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
   1.132 -# endif
   1.133 -    _STLP_PLACEMENT_NEW (__p) _T1(__val);
   1.134 -}
   1.135 +#endif /* _STLP_DEF_CONST_PLCT_NEW_BUG */
   1.136  
   1.137  template <class _T1>
   1.138  inline void _Construct(_T1* __p) {
   1.139 -# ifdef _STLP_DEBUG_UNINITIALIZED
   1.140 +#if defined (_STLP_DEBUG_UNINITIALIZED)
   1.141    memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
   1.142 -# endif
   1.143 -# ifdef _STLP_DEFAULT_CONSTRUCTOR_BUG
   1.144 -typedef typename _Is_integer<_T1>::_Integral _Is_Integral;
   1.145 -_Construct_aux (__p, _Is_Integral() );
   1.146 -# else
   1.147 +#endif
   1.148 +#if defined (_STLP_DEF_CONST_PLCT_NEW_BUG)
   1.149 +  _Construct_aux (__p, _HasDefaultZeroValue(__p)._Answer() );
   1.150 +#else
   1.151    _STLP_PLACEMENT_NEW (__p) _T1();
   1.152 -# endif
   1.153 +#endif /* _STLP_DEF_CONST_PLCT_NEW_BUG */
   1.154  }
   1.155  
   1.156 -# if defined(_STLP_NEW_REDEFINE)
   1.157 -# ifdef DEBUG_NEW
   1.158 -#  define new DEBUG_NEW
   1.159 -# endif
   1.160 -#  undef _STLP_NEW_REDEFINE
   1.161 -# endif 
   1.162 -
   1.163 -template <class _ForwardIterator>
   1.164 -_STLP_INLINE_LOOP void
   1.165 -__destroy_aux(_ForwardIterator __first, _ForwardIterator __last, const __false_type&) {
   1.166 -  for ( ; __first != __last; ++__first)
   1.167 -    _STLP_STD::_Destroy(&*__first);
   1.168 +template <class _Tp>
   1.169 +inline void _Copy_Construct(_Tp* __p, const _Tp& __val) {
   1.170 +#if defined (_STLP_DEBUG_UNINITIALIZED)
   1.171 +  memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_Tp));
   1.172 +#endif
   1.173 +  _STLP_PLACEMENT_NEW (__p) _Tp(__val);
   1.174  }
   1.175  
   1.176 -template <class _ForwardIterator> 
   1.177 -inline void __destroy_aux(_ForwardIterator, _ForwardIterator, const __true_type&) {}
   1.178 +template <class _T1, class _T2>
   1.179 +inline void _Param_Construct(_T1* __p, const _T2& __val) {
   1.180 +#if defined (_STLP_DEBUG_UNINITIALIZED)
   1.181 +  memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
   1.182 +#endif
   1.183 +  _STLP_PLACEMENT_NEW (__p) _T1(__val);
   1.184 +}
   1.185 +
   1.186 +template <class _T1, class _T2>
   1.187 +inline void _Move_Construct_Aux(_T1* __p, _T2& __val, const __false_type& /*_IsPOD*/) {
   1.188 +  _STLP_PLACEMENT_NEW (__p) _T1(_STLP_PRIV _AsMoveSource(__val));
   1.189 +}
   1.190 +
   1.191 +template <class _T1, class _T2>
   1.192 +inline void _Move_Construct_Aux(_T1* __p, _T2& __val, const __true_type& /*_IsPOD*/) {
   1.193 +  _STLP_PLACEMENT_NEW (__p) _T1(__val);
   1.194 +}
   1.195 +
   1.196 +template <class _T1, class _T2>
   1.197 +inline void _Move_Construct(_T1* __p, _T2& __val) {
   1.198 +#if defined (_STLP_DEBUG_UNINITIALIZED)
   1.199 +  memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
   1.200 +#endif
   1.201 +  _Move_Construct_Aux(__p, __val, _Is_POD(__p)._Answer());
   1.202 +}
   1.203 +
   1.204 +#if defined(_STLP_NEW_REDEFINE)
   1.205 +#  if defined (DEBUG_NEW)
   1.206 +#    define new DEBUG_NEW
   1.207 +#  endif
   1.208 +#  undef _STLP_NEW_REDEFINE
   1.209 +#endif
   1.210  
   1.211  template <class _ForwardIterator, class _Tp>
   1.212 -inline void 
   1.213 -__destroy(_ForwardIterator __first, _ForwardIterator __last, _Tp*) {
   1.214 +_STLP_INLINE_LOOP void
   1.215 +__destroy_range_aux(_ForwardIterator __first, _ForwardIterator __last, _Tp*, const __false_type& /*_Trivial_destructor*/) {
   1.216 +  for ( ; __first != __last; ++__first) {
   1.217 +    __destroy_aux(&(*__first), __false_type());
   1.218 +#if defined (_STLP_DEBUG_UNINITIALIZED)
   1.219 +    memset((char*)&(*__first), _STLP_SHRED_BYTE, sizeof(_Tp));
   1.220 +#endif
   1.221 +  }
   1.222 +}
   1.223 +
   1.224 +template <class _ForwardIterator, class _Tp>
   1.225 +#if defined (_STLP_DEBUG_UNINITIALIZED)
   1.226 +_STLP_INLINE_LOOP void
   1.227 +__destroy_range_aux(_ForwardIterator __first, _ForwardIterator __last, _Tp*, const __true_type& /*_Trivial_destructor*/) {
   1.228 +  for ( ; __first != __last; ++__first)
   1.229 +    memset((char*)&(*__first), _STLP_SHRED_BYTE, sizeof(_Tp));
   1.230 +}
   1.231 +#else
   1.232 +inline void
   1.233 +__destroy_range_aux(_ForwardIterator, _ForwardIterator, _Tp*, const __true_type& /*_Trivial_destructor*/) {}
   1.234 +#endif
   1.235 +
   1.236 +template <class _ForwardIterator, class _Tp>
   1.237 +inline void
   1.238 +__destroy_range(_ForwardIterator __first, _ForwardIterator __last, _Tp *__ptr) {
   1.239    typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
   1.240 -  __destroy_aux(__first, __last, _Trivial_destructor());
   1.241 +  __destroy_range_aux(__first, __last, __ptr, _Trivial_destructor());
   1.242  }
   1.243  
   1.244  template <class _ForwardIterator>
   1.245 -inline void _Destroy(_ForwardIterator __first, _ForwardIterator __last) {
   1.246 -  __destroy(__first, __last, _STLP_VALUE_TYPE(__first, _ForwardIterator));
   1.247 +inline void _Destroy_Range(_ForwardIterator __first, _ForwardIterator __last) {
   1.248 +  __destroy_range(__first, __last, _STLP_VALUE_TYPE(__first, _ForwardIterator));
   1.249  }
   1.250  
   1.251 -inline void _Destroy(char*, char*) {}
   1.252 -# ifdef _STLP_HAS_WCHAR_T // dwa 8/15/97
   1.253 -inline void _Destroy(wchar_t*, wchar_t*) {}
   1.254 -inline void _Destroy(const wchar_t*, const wchar_t*) {}
   1.255 -# endif
   1.256 +inline void _Destroy_Range(char*, char*) {}
   1.257 +#if defined (_STLP_HAS_WCHAR_T) // dwa 8/15/97
   1.258 +inline void _Destroy_Range(wchar_t*, wchar_t*) {}
   1.259 +inline void _Destroy_Range(const wchar_t*, const wchar_t*) {}
   1.260 +#endif
   1.261  
   1.262 -# ifndef _STLP_NO_ANACHRONISMS
   1.263 +template <class _ForwardIterator, class _Tp>
   1.264 +inline void
   1.265 +__destroy_mv_srcs(_ForwardIterator __first, _ForwardIterator __last, _Tp *__ptr) {
   1.266 +  typedef typename __move_traits<_Tp>::complete _CompleteMove;
   1.267 +  __destroy_range_aux(__first, __last, __ptr, _CompleteMove());
   1.268 +}
   1.269 +
   1.270 +template <class _ForwardIterator>
   1.271 +inline void _Destroy_Moved_Range(_ForwardIterator __first, _ForwardIterator __last) {
   1.272 +  __destroy_mv_srcs(__first, __last, _STLP_VALUE_TYPE(__first, _ForwardIterator));
   1.273 +}
   1.274 +
   1.275 +#if defined (_STLP_DEF_CONST_DEF_PARAM_BUG)
   1.276 +// Those adaptors are here to fix common compiler bug regarding builtins:
   1.277 +// expressions like int k = int() should initialize k to 0
   1.278 +template <class _Tp>
   1.279 +inline _Tp __default_constructed_aux(_Tp*, const __false_type&) {
   1.280 +  return _Tp();
   1.281 +}
   1.282 +template <class _Tp>
   1.283 +inline _Tp __default_constructed_aux(_Tp*, const __true_type&) {
   1.284 +  return _Tp(0);
   1.285 +}
   1.286 +
   1.287 +template <class _Tp>
   1.288 +inline _Tp __default_constructed(_Tp* __p) {
   1.289 +  return __default_constructed_aux(__p, _HasDefaultZeroValue(__p)._Answer());
   1.290 +}
   1.291 +
   1.292 +#  define _STLP_DEFAULT_CONSTRUCTED(_TTp) __default_constructed((_TTp*)0)
   1.293 +#else
   1.294 +#  define _STLP_DEFAULT_CONSTRUCTED(_TTp) _TTp()
   1.295 +#endif /* _STLP_DEF_CONST_DEF_PARAM_BUG */
   1.296 +
   1.297 +
   1.298 +#if !defined (_STLP_NO_ANACHRONISMS)
   1.299  // --------------------------------------------------
   1.300  // Old names from the HP STL.
   1.301  
   1.302  template <class _T1, class _T2>
   1.303 -inline void construct(_T1* __p, const _T2& __val) {_Construct(__p, __val); }
   1.304 +inline void construct(_T1* __p, const _T2& __val) {_Param_Construct(__p, __val); }
   1.305  template <class _T1>
   1.306 -inline void construct(_T1* __p) { _Construct(__p); }
   1.307 +inline void construct(_T1* __p) { _STLP_STD::_Construct(__p); }
   1.308  template <class _Tp>
   1.309  inline void destroy(_Tp* __pointer) {  _STLP_STD::_Destroy(__pointer); }
   1.310  template <class _ForwardIterator>
   1.311 -inline void destroy(_ForwardIterator __first, _ForwardIterator __last) { _STLP_STD::_Destroy(__first, __last); }
   1.312 -# endif
   1.313 -
   1.314 -#ifdef _STLP_USE_TRAP_LEAVE
   1.315 -
   1.316 -struct TCleanupOverlay
   1.317 -{
   1.318 -    TAny *vtable;
   1.319 -    TAny *iBase;
   1.320 -    TAny *iTop;
   1.321 -    TAny *iNext;
   1.322 -};
   1.323 -
   1.324 -template <class _Tp>
   1.325 -struct _STLP_StackHelper {
   1.326 -  static unsigned int Check( void *ptr );
   1.327 -  static void* _NewLC (size_t __n);
   1.328 -};
   1.329 -
   1.330 -struct _STLP_StackPopper {
   1.331 -  ~_STLP_StackPopper() { CleanupStack::Pop(); }
   1.332 -};
   1.333 -
   1.334 -template <class _Tp>
   1.335 -struct _STLP_Cleanup {
   1.336 -  static void clear(TAny* __p);
   1.337 -};
   1.338 -
   1.339 -# define _STLP_PUSH_CLEANUP_ITEM(_Tp, __p)  CleanupStack::PushL(TCleanupItem(&_STLP_Cleanup< _Tp >::clear, (TAny*)__p));
   1.340 -# define _STLP_PUSH_STACK_ITEM(_Tp, __p)  _STLP_PUSH_CLEANUP_ITEM(_Tp, __p)   _STLP_StackPopper __Popper; _STLP_no_unused_variable_warning( __Popper );
   1.341 -# define _STLP_POP_IF_CHECK if (_STLP_StackHelper<bool>::Check(this)) CleanupStack::Pop();
   1.342 -# define _STLP_POP_CLEANUP_ITEM CleanupStack::Pop(); _STLP_POP_IF_CHECK
   1.343 -
   1.344 -# define _STLP_POP_ITEM CleanupStack::Pop();
   1.345 -
   1.346 -// to be used in complex object constructors
   1.347 -template <class _Tp>
   1.348 -struct _STLP_StackPusher {
   1.349 -  _STLP_StackPusher(_Tp * __p) { _STLP_PUSH_CLEANUP_ITEM(_Tp, (void*)__p) }
   1.350 -};
   1.351 -
   1.352 -template <class _Tp>
   1.353 -unsigned int _STLP_StackHelper<_Tp>::Check( void *ptr )
   1.354 -
   1.355 -{
   1.356 -    TCleanupTrapHandler *handler =
   1.357 -        (TCleanupTrapHandler *)User::TrapHandler();
   1.358 -
   1.359 -    CCleanup &cleanup = handler->Cleanup();
   1.360 -
   1.361 -    TCleanupOverlay *overlay = (TCleanupOverlay *)( &cleanup );
   1.362 -
   1.363 -    char *raw = (char *)(overlay->iNext) - 4;
   1.364 -    void *topptr = *( (void **)(raw) );
   1.365 -
   1.366 -    return ( ptr == topptr );
   1.367 -} 
   1.368 -
   1.369 -
   1.370 -template <class _Tp>
   1.371 -void* _STLP_StackHelper<_Tp>::_NewLC(size_t __n) { 
   1.372 -  void* __p = ::operator new (__n, ELeave) ; 
   1.373 -  // constructor will pop it back
   1.374 -  CleanupStack::PushL(__p); 
   1.375 -  return __p;
   1.376 -}
   1.377 -
   1.378 -template <class _Tp>
   1.379 -void _STLP_Cleanup<_Tp>::clear(TAny* __p)
   1.380 -{
   1.381 -  ((_Tp*)__p)->~_Tp();
   1.382 -}
   1.383 -
   1.384 -
   1.385 -#else
   1.386 -# define _STLP_PUSH_CLEANUP_ITEM(_Tp, __p)
   1.387 -# define _STLP_POP_CLEANUP_ITEM
   1.388 -# define _STLP_PUSH_STACK_ITEM(_Tp, p)
   1.389 -# define _STLP_POP_ITEM
   1.390 -# define _STLP_POP_IF_CHECK
   1.391 -# define TPush TLeave
   1.392 -#endif
   1.393 +inline void destroy(_ForwardIterator __first, _ForwardIterator __last) { _STLP_STD::_Destroy_Range(__first, __last); }
   1.394 +#endif /* _STLP_NO_ANACHRONISMS */
   1.395  
   1.396  _STLP_END_NAMESPACE
   1.397