ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

_uninitialized.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_UNINITIALIZED_H
00031 #define _STLP_INTERNAL_UNINITIALIZED_H
00032 
00033 #ifndef _STLP_INTERNAL_CSTRING
00034 #  include <stl/_cstring.h>
00035 #endif
00036 
00037 #ifndef _STLP_INTERNAL_ALGOBASE_H
00038 #  include <stl/_algobase.h>
00039 #endif
00040 
00041 #ifndef _STLP_INTERNAL_CONSTRUCT_H
00042 #  include <stl/_construct.h>
00043 #endif
00044 
00045 _STLP_BEGIN_NAMESPACE
00046 
00047 _STLP_MOVE_TO_PRIV_NAMESPACE
00048 
00049 // uninitialized_copy
00050 
00051 template <class _InputIter, class _OutputIter, class _Distance>
00052 inline _OutputIter __ucopy(_InputIter __first, _InputIter __last,
00053                            _OutputIter __result, _Distance*) {
00054   _OutputIter __cur = __result;
00055   _STLP_TRY {
00056     for ( ; __first != __last; ++__first, ++__cur)
00057       _Param_Construct(&*__cur, *__first);
00058     return __cur;
00059   }
00060   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__result, __cur))
00061   _STLP_RET_AFTER_THROW(__cur)
00062 }
00063 
00064 template <class _InputIter, class _OutputIter, class _Distance>
00065 inline _OutputIter __ucopy(_InputIter __first, _InputIter __last,
00066                            _OutputIter __result, const input_iterator_tag &, _Distance* __d)
00067 { return __ucopy(__first, __last, __result, __d); }
00068 
00069 #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
00070 template <class _InputIter, class _OutputIter, class _Distance>
00071 inline _OutputIter __ucopy(_InputIter __first, _InputIter __last,
00072                            _OutputIter __result, const forward_iterator_tag &, _Distance* __d)
00073 { return __ucopy(__first, __last, __result, __d); }
00074 
00075 template <class _InputIter, class _OutputIter, class _Distance>
00076 inline _OutputIter __ucopy(_InputIter __first, _InputIter __last,
00077                            _OutputIter __result, const bidirectional_iterator_tag &, _Distance* __d)
00078 { return __ucopy(__first, __last, __result, __d); }
00079 #endif
00080 
00081 template <class _RandomAccessIter, class _OutputIter, class _Distance>
00082 inline _OutputIter __ucopy(_RandomAccessIter __first, _RandomAccessIter __last,
00083                            _OutputIter __result, const random_access_iterator_tag &, _Distance*) {
00084   _OutputIter __cur = __result;
00085   _STLP_TRY {
00086     for (_Distance __n = __last - __first; __n > 0; --__n) {
00087       _Param_Construct(&*__cur, *__first);
00088       ++__first;
00089       ++__cur;
00090     }
00091     return __cur;
00092   }
00093   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__result, __cur))
00094   _STLP_RET_AFTER_THROW(__cur)
00095 }
00096 
00097 //Used internaly
00098 template <class _RandomAccessIter, class _OutputIter>
00099 inline _OutputIter __ucopy(_RandomAccessIter __first, _RandomAccessIter __last, _OutputIter __result)
00100 { return __ucopy(__first, __last, __result, random_access_iterator_tag(), (ptrdiff_t*)0); }
00101 
00102 inline void*
00103 __ucopy_trivial(const void* __first, const void* __last, void* __result) {
00104   //dums: this version can use memcpy (__copy_trivial can't)
00105   return (__last == __first) ? __result :
00106     ((char*)memcpy(__result, __first, ((const char*)__last - (const char*)__first))) +
00107     ((const char*)__last - (const char*)__first);
00108 }
00109 
00110 template <class _InputIter, class _OutputIter>
00111 inline _OutputIter __ucopy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result,
00112                                 const __false_type& /*TrivialUCopy*/)
00113 { return __ucopy(__first, __last, __result, random_access_iterator_tag(), (ptrdiff_t*)0); }
00114 
00115 template <class _InputIter, class _OutputIter>
00116 inline _OutputIter __ucopy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result,
00117                                 const __true_type& /*TrivialUCopy*/) {
00118   // we know they all pointers, so this cast is OK
00119   //  return (_OutputIter)__copy_trivial(&(*__first), &(*__last), &(*__result));
00120   return (_OutputIter)__ucopy_trivial(__first, __last, __result);
00121 }
00122 
00123 template <class _InputIter, class _OutputIter>
00124 inline _OutputIter __ucopy_aux(_InputIter __first, _InputIter __last, _OutputIter __result,
00125                                const __true_type& /*BothPtrType*/) {
00126   return __ucopy_ptrs(__first, __last, __result,
00127                       _UseTrivialUCopy(_STLP_VALUE_TYPE(__first, _InputIter),
00128                                        _STLP_VALUE_TYPE(__result, _OutputIter))._Answer());
00129 }
00130 
00131 template <class _InputIter, class _OutputIter>
00132 inline _OutputIter __ucopy_aux(_InputIter __first, _InputIter __last, _OutputIter __result,
00133                                const __false_type& /*BothPtrType*/) {
00134   return __ucopy(__first, __last, __result,
00135                  _STLP_ITERATOR_CATEGORY(__first, _InputIter),
00136                  _STLP_DISTANCE_TYPE(__first, _InputIter));
00137 }
00138 
00139 _STLP_MOVE_TO_STD_NAMESPACE
00140 
00141 template <class _InputIter, class _ForwardIter>
00142 inline _ForwardIter
00143 uninitialized_copy(_InputIter __first, _InputIter __last, _ForwardIter __result)
00144 { return _STLP_PRIV __ucopy_aux(__first, __last, __result, _BothPtrType< _InputIter, _ForwardIter>::_Answer()); }
00145 
00146 inline char*
00147 uninitialized_copy(const char* __first, const char* __last, char* __result)
00148 { return  (char*)_STLP_PRIV __ucopy_trivial(__first, __last, __result); }
00149 
00150 #  if defined (_STLP_HAS_WCHAR_T) // dwa 8/15/97
00151 inline wchar_t*
00152 uninitialized_copy(const wchar_t* __first, const wchar_t* __last, wchar_t* __result)
00153 { return  (wchar_t*)_STLP_PRIV __ucopy_trivial (__first, __last, __result); }
00154 #  endif
00155 
00156 // uninitialized_copy_n (not part of the C++ standard)
00157 _STLP_MOVE_TO_PRIV_NAMESPACE
00158 
00159 template <class _InputIter, class _Size, class _ForwardIter>
00160 _STLP_INLINE_LOOP
00161 pair<_InputIter, _ForwardIter>
00162 __ucopy_n(_InputIter __first, _Size __count, _ForwardIter __result,
00163           const input_iterator_tag &) {
00164   _ForwardIter __cur = __result;
00165   _STLP_TRY {
00166     for ( ; __count > 0 ; --__count, ++__first, ++__cur)
00167       _Param_Construct(&*__cur, *__first);
00168     return pair<_InputIter, _ForwardIter>(__first, __cur);
00169   }
00170   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__result, __cur))
00171   _STLP_RET_AFTER_THROW((pair<_InputIter, _ForwardIter>(__first, __cur)))
00172 }
00173 
00174 #  if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
00175 template <class _InputIter, class _Size, class _ForwardIterator>
00176 inline pair<_InputIter, _ForwardIterator>
00177 __ucopy_n(_InputIter __first, _Size __count,
00178                        _ForwardIterator __result,
00179                        const forward_iterator_tag &)
00180 { return __ucopy_n(__first, __count, __result, input_iterator_tag()); }
00181 
00182 template <class _InputIter, class _Size, class _ForwardIterator>
00183 inline pair<_InputIter, _ForwardIterator>
00184 __ucopy_n(_InputIter __first, _Size __count,
00185                        _ForwardIterator __result,
00186                        const bidirectional_iterator_tag &)
00187 { return __ucopy_n(__first, __count, __result, input_iterator_tag()); }
00188 #  endif
00189 
00190 template <class _RandomAccessIter, class _Size, class _ForwardIter>
00191 inline pair<_RandomAccessIter, _ForwardIter>
00192 __ucopy_n(_RandomAccessIter __first, _Size __count, _ForwardIter __result,
00193                        const random_access_iterator_tag &) {
00194   _RandomAccessIter __last = __first + __count;
00195   return pair<_RandomAccessIter, _ForwardIter>(__last, uninitialized_copy(__first, __last, __result));
00196 }
00197 
00198 // This is used internally in <rope> , which is extension itself.
00199 template <class _InputIter, class _Size, class _ForwardIter>
00200 inline pair<_InputIter, _ForwardIter>
00201 __ucopy_n(_InputIter __first, _Size __count, _ForwardIter __result)
00202 { return _STLP_PRIV __ucopy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter)); }
00203 
00204 #if !defined (_STLP_NO_EXTENSIONS)
00205 
00206 _STLP_MOVE_TO_STD_NAMESPACE
00207 
00208 template <class _InputIter, class _Size, class _ForwardIter>
00209 inline pair<_InputIter, _ForwardIter>
00210 uninitialized_copy_n(_InputIter __first, _Size __count, _ForwardIter __result)
00211 { return _STLP_PRIV __ucopy_n(__first, __count, __result); }
00212 
00213 _STLP_MOVE_TO_PRIV_NAMESPACE
00214 
00215 #endif
00216 
00217 template <class _ForwardIter, class _Tp, class _Distance>
00218 inline void __ufill(_ForwardIter __first, _ForwardIter __last, const _Tp& __x, _Distance*) {
00219   _ForwardIter __cur = __first;
00220   _STLP_TRY {
00221     for ( ; __cur != __last; ++__cur)
00222       _Param_Construct(&*__cur, __x);
00223   }
00224   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__first, __cur))
00225 }
00226 
00227 template <class _ForwardIter, class _Tp, class _Distance>
00228 inline void __ufill(_ForwardIter __first, _ForwardIter __last,
00229                     const _Tp& __x, const input_iterator_tag &, _Distance* __d)
00230 { __ufill(__first, __last, __x, __d); }
00231 
00232 #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
00233 template <class _ForwardIter, class _Tp, class _Distance>
00234 inline void __ufill(_ForwardIter __first, _ForwardIter __last,
00235                     const _Tp& __x, const forward_iterator_tag &, _Distance* __d)
00236 { __ufill(__first, __last, __x, __d); }
00237 
00238 template <class _ForwardIter, class _Tp, class _Distance>
00239 inline void __ufill(_ForwardIter __first, _ForwardIter __last,
00240                     const _Tp& __x, const bidirectional_iterator_tag &, _Distance* __d)
00241 { __ufill(__first, __last, __x, __d); }
00242 #endif
00243 
00244 template <class _ForwardIter, class _Tp, class _Distance>
00245 inline void __ufill(_ForwardIter __first, _ForwardIter __last,
00246                     const _Tp& __x, const random_access_iterator_tag &, _Distance*) {
00247   _ForwardIter __cur = __first;
00248   _STLP_TRY {
00249     for (_Distance __n = __last - __first; __n > 0; --__n, ++__cur)
00250       _Param_Construct(&*__cur, __x);
00251   }
00252   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__first, __cur))
00253 }
00254 
00255 _STLP_MOVE_TO_STD_NAMESPACE
00256 
00257 template <class _ForwardIter, class _Tp>
00258 inline void uninitialized_fill(_ForwardIter __first, _ForwardIter __last,  const _Tp& __x) {
00259   _STLP_PRIV __ufill(__first, __last, __x,
00260                      _STLP_ITERATOR_CATEGORY(__first, _ForwardIter),
00261                      _STLP_DISTANCE_TYPE(__first, _ForwardIter));
00262 }
00263 
00264 // Specialization: for one-byte types we can use memset.
00265 inline void uninitialized_fill(unsigned char* __first, unsigned char* __last,
00266                                const unsigned char& __val) {
00267   unsigned char __tmp = __val;
00268   memset(__first, __tmp, __last - __first);
00269 }
00270 #if !defined (_STLP_NO_SIGNED_BUILTINS)
00271 inline void uninitialized_fill(signed char* __first, signed char* __last,
00272                                const signed char& __val) {
00273   signed char __tmp = __val;
00274   memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
00275 }
00276 #endif
00277 inline void uninitialized_fill(char* __first, char* __last, const char& __val) {
00278   char __tmp = __val;
00279   memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
00280 }
00281 
00282 _STLP_MOVE_TO_PRIV_NAMESPACE
00283 
00284 template <class _ForwardIter, class _Size, class _Tp>
00285 inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x) {
00286   _ForwardIter __cur = __first;
00287   _STLP_TRY {
00288     for ( ; __n > 0; --__n, ++__cur)
00289       _Param_Construct(&*__cur, __x);
00290   }
00291   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__first, __cur))
00292   return __cur;
00293 }
00294 
00295 template <class _ForwardIter, class _Size, class _Tp>
00296 inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x,
00297                               const input_iterator_tag &)
00298 { return __ufill_n(__first, __n, __x); }
00299 
00300 #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
00301 template <class _ForwardIter, class _Size, class _Tp>
00302 inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x,
00303                               const forward_iterator_tag &)
00304 { return __ufill_n(__first, __n, __x); }
00305 
00306 template <class _ForwardIter, class _Size, class _Tp>
00307 inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x,
00308                               const bidirectional_iterator_tag &)
00309 { return __ufill_n(__first, __n, __x); }
00310 #endif
00311 
00312 template <class _ForwardIter, class _Size, class _Tp>
00313 inline _ForwardIter __uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x) {
00314   _ForwardIter __last = __first + __n;
00315   __ufill(__first, __last, __x, random_access_iterator_tag(), (ptrdiff_t*)0);
00316   return __last;
00317 }
00318 
00319 template <class _ForwardIter, class _Size, class _Tp>
00320 inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x,
00321                               const random_access_iterator_tag &)
00322 { return __uninitialized_fill_n(__first, __n, __x); }
00323 
00324 /* __uninitialized_init is an internal algo to init a range with a value
00325  * built using default constructor. It is only called with pointer as
00326  * iterator.
00327  */
00328 template <class _ForwardIter, class _Size, class _Tp>
00329 inline _ForwardIter __uinit_aux_aux(_ForwardIter __first, _Size __n, const _Tp& __val,
00330                                     const __false_type& /*_HasDefaultZero*/)
00331 { return __uninitialized_fill_n(__first, __n, __val); }
00332 
00333 template <class _ForwardIter, class _Size, class _Tp>
00334 inline _ForwardIter __uinit_aux_aux(_ForwardIter __first, _Size __n, const _Tp& /* __val */,
00335                                     const __true_type& /*_HasDefaultZero*/) {
00336   memset((unsigned char*)__first, 0, __n * sizeof(_Tp));
00337   return __first + __n;
00338 }
00339 
00340 template <class _ForwardIter, class _Size, class _Tp>
00341 inline _ForwardIter __uinit_aux(_ForwardIter __first, _Size __n, const _Tp&,
00342                                 const __true_type& /*_TrivialInit*/)
00343 { return __first + __n; }
00344 
00345 template <class _ForwardIter, class _Size, class _Tp>
00346 inline _ForwardIter __uinit_aux(_ForwardIter __first, _Size __n, const _Tp& __val,
00347                                 const __false_type& /*_TrivialInit*/)
00348 { return __uinit_aux_aux(__first, __n, __val, _HasDefaultZeroValue(__first)._Answer()); }
00349 
00350 template <class _ForwardIter, class _Size, class _Tp>
00351 inline _ForwardIter __uninitialized_init(_ForwardIter __first, _Size __n, const _Tp& __val)
00352 { return __uinit_aux(__first, __n, __val, _UseTrivialInit(__first)._Answer()); }
00353 
00354 _STLP_MOVE_TO_STD_NAMESPACE
00355 
00356 template <class _ForwardIter, class _Size, class _Tp>
00357 inline void
00358 uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x)
00359 { _STLP_PRIV __ufill_n(__first, __n, __x, _STLP_ITERATOR_CATEGORY(__first, _ForwardIter)); }
00360 
00361 // Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill,
00362 // __uninitialized_fill_copy.
00363 
00364 // __uninitialized_copy_copy
00365 // Copies [first1, last1) into [result, result + (last1 - first1)), and
00366 //  copies [first2, last2) into
00367 //  [result + (last1 - first1), result + (last1 - first1) + (last2 - first2)).
00368 
00369 _STLP_MOVE_TO_PRIV_NAMESPACE
00370 
00371 template <class _InputIter1, class _InputIter2, class _ForwardIter>
00372 inline _ForwardIter
00373 __uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
00374                           _InputIter2 __first2, _InputIter2 __last2,
00375                           _ForwardIter __result) {
00376   _ForwardIter __new_result = uninitialized_copy(__first1, __last1, __result);
00377   _STLP_TRY {
00378     return uninitialized_copy(__first2, __last2, __new_result);
00379   }
00380   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__result, __new_result))
00381   _STLP_RET_AFTER_THROW(__result)
00382 }
00383 
00384 // __uninitialized_fill_copy
00385 // Fills [result, mid) with x, and copies [first, last) into
00386 //  [mid, mid + (last - first)).
00387 template <class _ForwardIter, class _Tp, class _InputIter>
00388 inline _ForwardIter
00389 __uninitialized_fill_copy(_ForwardIter __result, _ForwardIter __mid, const _Tp& __x,
00390                           _InputIter __first, _InputIter __last) {
00391   uninitialized_fill(__result, __mid, __x);
00392   _STLP_TRY {
00393     return uninitialized_copy(__first, __last, __mid);
00394   }
00395   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__result, __mid))
00396   _STLP_RET_AFTER_THROW(__result)
00397 }
00398 
00399 // __uninitialized_copy_fill
00400 // Copies [first1, last1) into [first2, first2 + (last1 - first1)), and
00401 //  fills [first2 + (last1 - first1), last2) with x.
00402 template <class _Iter, class _Tp>
00403 inline void
00404 __uninitialized_copy_fill(_Iter __first1, _Iter __last1, _Iter __first2, _Iter __last2,
00405                           const _Tp& __x) {
00406   _Iter __mid2 = uninitialized_copy(__first1, __last1, __first2);
00407   _STLP_TRY {
00408     uninitialized_fill(__mid2, __last2, __x);
00409   }
00410   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__first2, __mid2))
00411 }
00412 
00413 /* __uninitialized_move:
00414  * This function is used internaly and only with pointers as iterators.
00415  */
00416 template <class _InputIter, class _ForwardIter, class _TrivialUCpy>
00417 inline _ForwardIter
00418 __uninitialized_move(_InputIter __first, _InputIter __last, _ForwardIter __result,
00419                      _TrivialUCpy __trivial_ucpy, const __false_type& /*_Movable*/)
00420 { return __ucopy_ptrs(__first, __last, __result, __trivial_ucpy); }
00421 
00422 template <class _InputIter, class _ForwardIter, class _TrivialUCpy>
00423 _STLP_INLINE_LOOP
00424 _ForwardIter
00425 __uninitialized_move(_InputIter __first, _InputIter __last, _ForwardIter __result,
00426                      _TrivialUCpy , const __true_type& /*_Movable*/) {
00427   //Move constructor should not throw so we do not need to take care of exceptions here.
00428   for (ptrdiff_t __n = __last - __first ; __n > 0; --__n) {
00429     _Move_Construct(&*__result, *__first);
00430     ++__first; ++__result;
00431   }
00432   return __result;
00433 }
00434 
00435 _STLP_MOVE_TO_STD_NAMESPACE
00436 
00437 _STLP_END_NAMESPACE
00438 
00439 #endif /* _STLP_INTERNAL_UNINITIALIZED_H */
00440 
00441 // Local Variables:
00442 // mode:C++
00443 // End:

Generated on Sun May 27 2012 04:29:41 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.