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