2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
4 * Hewlett-Packard Company
6 * Copyright (c) 1996,1997
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
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.
26 /* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
30 #ifndef _STLP_INTERNAL_CONSTRUCT_H
31 #define _STLP_INTERNAL_CONSTRUCT_H
33 #ifdef _STLP_USE_TRAP_LEAVE
35 #endif // _STLP_USE_TRAP_LEAVE
37 # if defined (_STLP_DEBUG_UNINITIALIZED) && ! defined (_STLP_CSTRING)
41 # ifndef _STLP_INTERNAL_NEW_HEADER
42 # include <stl/_new.h>
46 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
47 # include <stl/_iterator_base.h>
52 # ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
54 inline void __destroy_aux(_Tp* __pointer, const __false_type&) { __pointer->~_Tp(); }
56 inline void __destroy_aux(_Tp* __pointer, const __true_type&) {}
60 inline void _Destroy(_Tp* __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());
68 # if ( defined (__BORLANDC__) && ( __BORLANDC__ < 0x500 ) )
69 __pointer->_Tp::~_Tp();
74 # ifdef _STLP_DEBUG_UNINITIALIZED
75 memset((char*)__pointer, _STLP_SHRED_BYTE, sizeof(_Tp));
80 # define _STLP_NEW_REDEFINE new
84 # ifdef _STLP_DEFAULT_CONSTRUCTOR_BUG
86 inline void _Construct_aux (_T1* __p, const __false_type&) {
87 _STLP_PLACEMENT_NEW (__p) _T1();
91 inline void _Construct_aux (_T1* __p, const __true_type&) {
92 _STLP_PLACEMENT_NEW (__p) _T1(0);
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));
101 _STLP_PLACEMENT_NEW (__p) _T1(__val);
105 inline void _Construct(_T1* __p) {
106 # ifdef _STLP_DEBUG_UNINITIALIZED
107 memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
109 # ifdef _STLP_DEFAULT_CONSTRUCTOR_BUG
110 typedef typename _Is_integer<_T1>::_Integral _Is_Integral;
111 _Construct_aux (__p, _Is_Integral() );
113 _STLP_PLACEMENT_NEW (__p) _T1();
117 # if defined(_STLP_NEW_REDEFINE)
119 # define new DEBUG_NEW
121 # undef _STLP_NEW_REDEFINE
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);
131 template <class _ForwardIterator>
132 inline void __destroy_aux(_ForwardIterator, _ForwardIterator, const __true_type&) {}
134 template <class _ForwardIterator, class _Tp>
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());
141 template <class _ForwardIterator>
142 inline void _Destroy(_ForwardIterator __first, _ForwardIterator __last) {
143 __destroy(__first, __last, _STLP_VALUE_TYPE(__first, _ForwardIterator));
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*) {}
152 # ifndef _STLP_NO_ANACHRONISMS
153 // --------------------------------------------------
154 // Old names from the HP STL.
156 template <class _T1, class _T2>
157 inline void construct(_T1* __p, const _T2& __val) {_Construct(__p, __val); }
159 inline void construct(_T1* __p) { _Construct(__p); }
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); }
166 #ifdef _STLP_USE_TRAP_LEAVE
168 struct TCleanupOverlay
177 struct _STLP_StackHelper {
178 static unsigned int Check( void *ptr );
179 static void* _NewLC (size_t __n);
182 struct _STLP_StackPopper {
183 ~_STLP_StackPopper() { CleanupStack::Pop(); }
187 struct _STLP_Cleanup {
188 static void clear(TAny* __p);
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
196 # define _STLP_POP_ITEM CleanupStack::Pop();
198 // to be used in complex object constructors
200 struct _STLP_StackPusher {
201 _STLP_StackPusher(_Tp * __p) { _STLP_PUSH_CLEANUP_ITEM(_Tp, (void*)__p) }
205 unsigned int _STLP_StackHelper<_Tp>::Check( void *ptr )
208 TCleanupTrapHandler *handler =
209 (TCleanupTrapHandler *)User::TrapHandler();
211 CCleanup &cleanup = handler->Cleanup();
213 TCleanupOverlay *overlay = (TCleanupOverlay *)( &cleanup );
215 char *raw = (char *)(overlay->iNext) - 4;
216 void *topptr = *( (void **)(raw) );
218 return ( ptr == topptr );
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);
231 void _STLP_Cleanup<_Tp>::clear(TAny* __p)
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
248 #endif /* _STLP_INTERNAL_CONSTRUCT_H */