/home/ntakagi/work/STLport-5.1.5/stlport/stl/_construct.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Copyright (c) 1996,1997
00007  * Silicon Graphics Computer Systems, Inc.
00008  *
00009  * Copyright (c) 1997
00010  * Moscow Center for SPARC Technology
00011  *
00012  * Copyright (c) 1999
00013  * Boris Fomitchev
00014  *
00015  * This material is provided "as is", with absolutely no warranty expressed
00016  * or implied. Any use is at your own risk.
00017  *
00018  * Permission to use or copy this software for any purpose is hereby granted
00019  * without fee, provided the above notices are retained on all copies.
00020  * Permission to modify the code and to distribute modified code is granted,
00021  * provided the above notices are retained, and a notice that the code was
00022  * modified is included with the above copyright notice.
00023  *
00024  */
00025 
00026 /* NOTE: This is an internal header file, included by other STL headers.
00027  *   You should not attempt to use it directly.
00028  */
00029 
00030 #ifndef _STLP_INTERNAL_CONSTRUCT_H
00031 #define _STLP_INTERNAL_CONSTRUCT_H
00032 
00033 #if !defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_INTERNAL_CSTRING)
00034 #  include <stl/_cstring.h>
00035 #endif
00036 
00037 #ifndef _STLP_INTERNAL_NEW
00038 #  include <stl/_new.h>
00039 #endif
00040 
00041 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
00042 #  include <stl/_iterator_base.h>
00043 #endif
00044 
00045 #ifndef _STLP_MOVE_CONSTRUCT_FWK_H
00046 #  include <stl/_move_construct_fwk.h>
00047 #endif
00048 
00049 _STLP_BEGIN_NAMESPACE
00050 
00051 template <class _Tp>
00052 inline void __destroy_aux(_Tp* __pointer, const __false_type& /*_Trivial_destructor*/)
00053 { __pointer->~_Tp(); }
00054 
00055 template <class _Tp>
00056 inline void __destroy_aux(_Tp*, const __true_type& /*_Trivial_destructor*/) {}
00057 
00058 template <class _Tp>
00059 inline void _Destroy(_Tp* __pointer) {
00060 #if defined (_STLP_MSVC) && (_STLP_MSVC <= 1010)
00061   __pointer;
00062 #endif
00063   typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
00064   __destroy_aux(__pointer, _Trivial_destructor());
00065 #if defined (_STLP_DEBUG_UNINITIALIZED)
00066   memset(__REINTERPRET_CAST(char*, __pointer), _STLP_SHRED_BYTE, sizeof(_Tp));
00067 #endif
00068 }
00069 
00070 template <class _Tp>
00071 inline void _Destroy_Moved(_Tp* __pointer) {
00072   typedef typename __move_traits<_Tp>::complete _Trivial_destructor;
00073   __destroy_aux(__pointer, _Trivial_destructor());
00074 #if defined (_STLP_DEBUG_UNINITIALIZED)
00075   memset((char*)__pointer, _STLP_SHRED_BYTE, sizeof(_Tp));
00076 #endif
00077 }
00078 
00079 #if defined (new)
00080 #  define _STLP_NEW_REDEFINE new
00081 #  undef new
00082 #endif
00083 
00084 #if defined (_STLP_DEF_CONST_PLCT_NEW_BUG)
00085 template <class _T1>
00086 inline void _Construct_aux (_T1* __p, const __false_type&) {
00087   _STLP_PLACEMENT_NEW (__p) _T1();
00088 }
00089 
00090 template <class _T1>
00091 inline void _Construct_aux (_T1* __p, const __true_type&) {
00092   _STLP_PLACEMENT_NEW (__p) _T1(0);
00093 }
00094 #endif /* _STLP_DEF_CONST_PLCT_NEW_BUG */
00095 
00096 template <class _T1>
00097 inline void _Construct(_T1* __p) {
00098 #if defined (_STLP_DEBUG_UNINITIALIZED)
00099   memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
00100 #endif
00101 #if defined (_STLP_DEF_CONST_PLCT_NEW_BUG)
00102   _Construct_aux (__p, _HasDefaultZeroValue(__p)._Answer() );
00103 #else
00104   _STLP_PLACEMENT_NEW (__p) _T1();
00105 #endif /* _STLP_DEF_CONST_PLCT_NEW_BUG */
00106 }
00107 
00108 template <class _Tp>
00109 inline void _Copy_Construct(_Tp* __p, const _Tp& __val) {
00110 #if defined (_STLP_DEBUG_UNINITIALIZED)
00111   memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_Tp));
00112 #endif
00113   _STLP_PLACEMENT_NEW (__p) _Tp(__val);
00114 }
00115 
00116 template <class _T1, class _T2>
00117 inline void _Param_Construct(_T1* __p, const _T2& __val) {
00118 #if defined (_STLP_DEBUG_UNINITIALIZED)
00119   memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
00120 #endif
00121   _STLP_PLACEMENT_NEW (__p) _T1(__val);
00122 }
00123 
00124 template <class _T1, class _T2>
00125 inline void _Move_Construct_Aux(_T1* __p, _T2& __val, const __false_type& /*_IsPOD*/) {
00126   _STLP_PLACEMENT_NEW (__p) _T1(_STLP_PRIV _AsMoveSource(__val));
00127 }
00128 
00129 template <class _T1, class _T2>
00130 inline void _Move_Construct_Aux(_T1* __p, _T2& __val, const __true_type& /*_IsPOD*/) {
00131   _STLP_PLACEMENT_NEW (__p) _T1(__val);
00132 }
00133 
00134 template <class _T1, class _T2>
00135 inline void _Move_Construct(_T1* __p, _T2& __val) {
00136 #if defined (_STLP_DEBUG_UNINITIALIZED)
00137   memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
00138 #endif
00139   _Move_Construct_Aux(__p, __val, _Is_POD(__p)._Answer());
00140 }
00141 
00142 #if defined(_STLP_NEW_REDEFINE)
00143 #  if defined (DEBUG_NEW)
00144 #    define new DEBUG_NEW
00145 #  endif
00146 #  undef _STLP_NEW_REDEFINE
00147 #endif
00148 
00149 template <class _ForwardIterator, class _Tp>
00150 _STLP_INLINE_LOOP void
00151 __destroy_range_aux(_ForwardIterator __first, _ForwardIterator __last, _Tp*, const __false_type& /*_Trivial_destructor*/) {
00152   for ( ; __first != __last; ++__first) {
00153     __destroy_aux(&(*__first), __false_type());
00154 #if defined (_STLP_DEBUG_UNINITIALIZED)
00155     memset((char*)&(*__first), _STLP_SHRED_BYTE, sizeof(_Tp));
00156 #endif
00157   }
00158 }
00159 
00160 template <class _ForwardIterator, class _Tp>
00161 #if defined (_STLP_DEBUG_UNINITIALIZED)
00162 _STLP_INLINE_LOOP void
00163 __destroy_range_aux(_ForwardIterator __first, _ForwardIterator __last, _Tp*, const __true_type& /*_Trivial_destructor*/) {
00164   for ( ; __first != __last; ++__first)
00165     memset((char*)&(*__first), _STLP_SHRED_BYTE, sizeof(_Tp));
00166 }
00167 #else
00168 inline void
00169 __destroy_range_aux(_ForwardIterator, _ForwardIterator, _Tp*, const __true_type& /*_Trivial_destructor*/) {}
00170 #endif
00171 
00172 template <class _ForwardIterator, class _Tp>
00173 inline void
00174 __destroy_range(_ForwardIterator __first, _ForwardIterator __last, _Tp *__ptr) {
00175   typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
00176   __destroy_range_aux(__first, __last, __ptr, _Trivial_destructor());
00177 }
00178 
00179 template <class _ForwardIterator>
00180 inline void _Destroy_Range(_ForwardIterator __first, _ForwardIterator __last) {
00181   __destroy_range(__first, __last, _STLP_VALUE_TYPE(__first, _ForwardIterator));
00182 }
00183 
00184 inline void _Destroy_Range(char*, char*) {}
00185 #if defined (_STLP_HAS_WCHAR_T) // dwa 8/15/97
00186 inline void _Destroy_Range(wchar_t*, wchar_t*) {}
00187 inline void _Destroy_Range(const wchar_t*, const wchar_t*) {}
00188 #endif
00189 
00190 template <class _ForwardIterator, class _Tp>
00191 inline void
00192 __destroy_mv_srcs(_ForwardIterator __first, _ForwardIterator __last, _Tp *__ptr) {
00193   typedef typename __move_traits<_Tp>::complete _CompleteMove;
00194   __destroy_range_aux(__first, __last, __ptr, _CompleteMove());
00195 }
00196 
00197 template <class _ForwardIterator>
00198 inline void _Destroy_Moved_Range(_ForwardIterator __first, _ForwardIterator __last) {
00199   __destroy_mv_srcs(__first, __last, _STLP_VALUE_TYPE(__first, _ForwardIterator));
00200 }
00201 
00202 #if defined (_STLP_DEF_CONST_DEF_PARAM_BUG)
00203 // Those adaptors are here to fix common compiler bug regarding builtins:
00204 // expressions like int k = int() should initialize k to 0
00205 template <class _Tp>
00206 inline _Tp __default_constructed_aux(_Tp*, const __false_type&) {
00207   return _Tp();
00208 }
00209 template <class _Tp>
00210 inline _Tp __default_constructed_aux(_Tp*, const __true_type&) {
00211   return _Tp(0);
00212 }
00213 
00214 template <class _Tp>
00215 inline _Tp __default_constructed(_Tp* __p) {
00216   return __default_constructed_aux(__p, _HasDefaultZeroValue(__p)._Answer());
00217 }
00218 
00219 #  define _STLP_DEFAULT_CONSTRUCTED(_TTp) __default_constructed((_TTp*)0)
00220 #else
00221 #  define _STLP_DEFAULT_CONSTRUCTED(_TTp) _TTp()
00222 #endif /* _STLP_DEF_CONST_DEF_PARAM_BUG */
00223 
00224 
00225 #if !defined (_STLP_NO_ANACHRONISMS)
00226 // --------------------------------------------------
00227 // Old names from the HP STL.
00228 
00229 template <class _T1, class _T2>
00230 inline void construct(_T1* __p, const _T2& __val) {_Param_Construct(__p, __val); }
00231 template <class _T1>
00232 inline void construct(_T1* __p) { _STLP_STD::_Construct(__p); }
00233 template <class _Tp>
00234 inline void destroy(_Tp* __pointer) {  _STLP_STD::_Destroy(__pointer); }
00235 template <class _ForwardIterator>
00236 inline void destroy(_ForwardIterator __first, _ForwardIterator __last) { _STLP_STD::_Destroy_Range(__first, __last); }
00237 #endif /* _STLP_NO_ANACHRONISMS */
00238 
00239 _STLP_END_NAMESPACE
00240 
00241 #endif /* _STLP_INTERNAL_CONSTRUCT_H */
00242 
00243 // Local Variables:
00244 // mode:C++
00245 // End:



Generated on Mon Mar 10 15:32:20 2008 by  doxygen 1.5.1