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