Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygen_bvector.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_BVECTOR_H 00031 #define _STLP_INTERNAL_BVECTOR_H 00032 00033 #ifndef _STLP_INTERNAL_VECTOR_H 00034 # include <stl/_vector.h> 00035 #endif 00036 00037 #define _STLP_WORD_BIT (int(CHAR_BIT * sizeof(unsigned int))) 00038 00039 _STLP_BEGIN_NAMESPACE 00040 _STLP_MOVE_TO_PRIV_NAMESPACE 00041 00042 struct _Bit_reference { 00043 unsigned int* _M_p; 00044 unsigned int _M_mask; 00045 _Bit_reference(unsigned int* __x, unsigned int __y) 00046 : _M_p(__x), _M_mask(__y) {} 00047 00048 public: 00049 _Bit_reference() : _M_p(0), _M_mask(0) {} 00050 00051 operator bool() const { 00052 return !(!(*_M_p & _M_mask)); 00053 } 00054 _Bit_reference& operator = (bool __x) { 00055 if (__x) *_M_p |= _M_mask; 00056 else *_M_p &= ~_M_mask; 00057 return *this; 00058 } 00059 _Bit_reference& operator = (const _Bit_reference& __x) { 00060 return *this = bool(__x); 00061 } 00062 bool operator == (const _Bit_reference& __x) const { 00063 return bool(*this) == bool(__x); 00064 } 00065 bool operator < (const _Bit_reference& __x) const { 00066 return !bool(*this) && bool(__x); 00067 } 00068 00069 _Bit_reference& operator |= (bool __x) { 00070 if (__x) 00071 *_M_p |= _M_mask; 00072 return *this; 00073 } 00074 _Bit_reference& operator &= (bool __x) { 00075 if (!__x) 00076 *_M_p &= ~_M_mask; 00077 return *this; 00078 } 00079 void flip() { *_M_p ^= _M_mask; } 00080 }; 00081 00082 00083 _STLP_MOVE_TO_STD_NAMESPACE 00084 00085 inline void swap(_STLP_PRIV _Bit_reference& __x, _STLP_PRIV _Bit_reference& __y) { 00086 bool __tmp = (bool)__x; 00087 __x = __y; 00088 __y = __tmp; 00089 } 00090 00091 // Might not be very useful but costs nothing! 00092 _STLP_TEMPLATE_NULL 00093 struct __type_traits<_STLP_PRIV _Bit_reference> { 00094 typedef __false_type has_trivial_default_constructor; 00095 typedef __true_type has_trivial_copy_constructor; 00096 typedef __false_type has_trivial_assignment_operator; 00097 typedef __true_type has_trivial_destructor; 00098 typedef __false_type is_POD_type; 00099 }; 00100 00101 _STLP_MOVE_TO_PRIV_NAMESPACE 00102 00103 struct _Bit_iterator_base { 00104 typedef ptrdiff_t difference_type; 00105 00106 unsigned int* _M_p; 00107 unsigned int _M_offset; 00108 00109 void _M_bump_up() { 00110 if (_M_offset++ == _STLP_WORD_BIT - 1) { 00111 _M_offset = 0; 00112 ++_M_p; 00113 } 00114 } 00115 00116 void _M_bump_down() { 00117 if (_M_offset-- == 0) { 00118 _M_offset = _STLP_WORD_BIT - 1; 00119 --_M_p; 00120 } 00121 } 00122 00123 _Bit_iterator_base() : _M_p(0), _M_offset(0) {} 00124 _Bit_iterator_base(unsigned int* __x, unsigned int __y) : _M_p(__x), _M_offset(__y) {} 00125 // see comment in doc/README.evc4 and doc/README.evc8 00126 #if defined(_MSC_VER) && _MSC_VER<=1401 && defined(MIPS) && defined(NDEBUG) 00127 _Bit_iterator_base( const _Bit_iterator_base& __x) : _M_p(__x._M_p), _M_offset(__x._M_offset) {} 00128 #endif 00129 // _Bit_iterator_base& operator = ( const _Bit_iterator_base& __x) { _M_p = __x._M_p ; _M_offset = __x._M_offset ; return *this; } 00130 00131 void _M_advance (difference_type __i) { 00132 difference_type __n = __i + _M_offset; 00133 _M_p += __n / _STLP_WORD_BIT; 00134 __n = __n % _STLP_WORD_BIT; 00135 if (__n < 0) { 00136 _M_offset = (unsigned int) __n + _STLP_WORD_BIT; 00137 --_M_p; 00138 } else 00139 _M_offset = (unsigned int) __n; 00140 } 00141 00142 difference_type _M_subtract(const _Bit_iterator_base& __x) const { 00143 return _STLP_WORD_BIT * (_M_p - __x._M_p) + _M_offset - __x._M_offset; 00144 } 00145 }; 00146 00147 inline bool _STLP_CALL operator==(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { 00148 return __y._M_p == __x._M_p && __y._M_offset == __x._M_offset; 00149 } 00150 inline bool _STLP_CALL operator!=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { 00151 return __y._M_p != __x._M_p || __y._M_offset != __x._M_offset; 00152 } 00153 00154 inline bool _STLP_CALL operator<(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { 00155 return __x._M_p < __y._M_p || (__x._M_p == __y._M_p && __x._M_offset < __y._M_offset); 00156 } 00157 00158 inline bool _STLP_CALL operator>(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { 00159 return operator <(__y , __x); 00160 } 00161 inline bool _STLP_CALL operator<=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { 00162 return !(__y < __x); 00163 } 00164 inline bool _STLP_CALL operator>=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { 00165 return !(__x < __y); 00166 } 00167 00168 template <class _Ref, class _Ptr> 00169 struct _Bit_iter : public _Bit_iterator_base { 00170 typedef _Ref reference; 00171 typedef _Ptr pointer; 00172 typedef _Bit_iter<_Ref, _Ptr> _Self; 00173 typedef random_access_iterator_tag iterator_category; 00174 typedef bool value_type; 00175 typedef ptrdiff_t difference_type; 00176 typedef size_t size_type; 00177 00178 _Bit_iter(unsigned int* __x, unsigned int __y) : _Bit_iterator_base(__x, __y) {} 00179 _Bit_iter() {} 00180 00181 _Bit_iter(const _Bit_iter<_Bit_reference, _Bit_reference*>& __x): 00182 _Bit_iterator_base((const _Bit_iterator_base&)__x) {} 00183 00184 // _Self& operator = (const _Bit_iter<_Bit_reference, _Bit_reference*>& __x) 00185 // { (_Bit_iterator_base&)*this = (const _Bit_iterator_base&)__x; return *this; } 00186 00187 reference operator*() const { 00188 return _Bit_reference(_M_p, 1UL << _M_offset); 00189 } 00190 _Self& operator++() { 00191 _M_bump_up(); 00192 return *this; 00193 } 00194 _Self operator++(int) { 00195 _Self __tmp = *this; 00196 _M_bump_up(); 00197 return __tmp; 00198 } 00199 _Self& operator--() { 00200 _M_bump_down(); 00201 return *this; 00202 } 00203 _Self operator--(int) { 00204 _Self __tmp = *this; 00205 _M_bump_down(); 00206 return __tmp; 00207 } 00208 _Self& operator+=(difference_type __i) { 00209 _M_advance(__i); 00210 return *this; 00211 } 00212 _Self& operator-=(difference_type __i) { 00213 *this += -__i; 00214 return *this; 00215 } 00216 _Self operator+(difference_type __i) const { 00217 _Self __tmp = *this; 00218 return __tmp += __i; 00219 } 00220 _Self operator-(difference_type __i) const { 00221 _Self __tmp = *this; 00222 return __tmp -= __i; 00223 } 00224 difference_type operator-(const _Self& __x) const { 00225 return _M_subtract(__x); 00226 } 00227 reference operator[](difference_type __i) { return *(*this + __i); } 00228 }; 00229 00230 template <class _Ref, class _Ptr> 00231 inline _Bit_iter<_Ref,_Ptr> _STLP_CALL 00232 operator+(ptrdiff_t __n, const _Bit_iter<_Ref, _Ptr>& __x) { 00233 return __x + __n; 00234 } 00235 00236 _STLP_MOVE_TO_STD_NAMESPACE 00237 00238 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) 00239 template <class _Ref, class _Ptr> 00240 struct __type_traits< _STLP_PRIV _Bit_iter<_Ref, _Ptr> > { 00241 typedef __false_type has_trivial_default_constructor; 00242 typedef __true_type has_trivial_copy_constructor; 00243 typedef __true_type has_trivial_assignment_operator; 00244 typedef __true_type has_trivial_destructor; 00245 typedef __false_type is_POD_type; 00246 }; 00247 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */ 00248 00249 #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES) 00250 inline random_access_iterator_tag iterator_category(const _STLP_PRIV _Bit_iterator_base&) 00251 { return random_access_iterator_tag(); } 00252 inline ptrdiff_t* distance_type(const _STLP_PRIV _Bit_iterator_base&) 00253 { return (ptrdiff_t*)0; } 00254 inline bool* value_type(const _STLP_PRIV _Bit_iter<_STLP_PRIV _Bit_reference, _STLP_PRIV _Bit_reference*>&) 00255 { return (bool*)0; } 00256 inline bool* value_type(const _STLP_PRIV _Bit_iter<bool, const bool*>&) 00257 { return (bool*)0; } 00258 #endif 00259 00260 _STLP_MOVE_TO_PRIV_NAMESPACE 00261 00262 typedef _Bit_iter<bool, const bool*> _Bit_const_iterator; 00263 typedef _Bit_iter<_Bit_reference, _Bit_reference*> _Bit_iterator; 00264 00265 // Bit-vector base class, which encapsulates the difference between 00266 // old SGI-style allocators and standard-conforming allocators. 00267 template <class _Alloc> 00268 class _Bvector_base { 00269 typedef _Bvector_base<_Alloc> _Self; 00270 public: 00271 _STLP_FORCE_ALLOCATORS(bool, _Alloc) 00272 typedef _Alloc allocator_type; 00273 typedef unsigned int __chunk_type; 00274 typedef typename _Alloc_traits<__chunk_type, _Alloc>::allocator_type __chunk_allocator_type; 00275 allocator_type get_allocator() const 00276 { return _STLP_CONVERT_ALLOCATOR(__STATIC_CAST(const __chunk_allocator_type&, _M_end_of_storage), bool); } 00277 00278 _Bvector_base(const allocator_type& __a) 00279 : _M_start(), _M_finish(), _M_end_of_storage(_STLP_CONVERT_ALLOCATOR(__a, __chunk_type), 00280 (__chunk_type*)0) 00281 {} 00282 #if !defined (_STLP_NO_MOVE_SEMANTIC) 00283 _Bvector_base(__move_source<_Self> src) 00284 : _M_start(src.get()._M_start), _M_finish(src.get()._M_finish), 00285 _M_end_of_storage(src.get()._M_end_of_storage) { 00286 //Make the source destroyable 00287 src.get()._M_start._M_p = 0; 00288 } 00289 #endif 00290 00291 ~_Bvector_base() { 00292 _M_deallocate(); 00293 } 00294 00295 protected: 00296 00297 static size_t _M_bits_to_chunks(size_t __n_bits) 00298 { return (__n_bits + _STLP_WORD_BIT - 1) / _STLP_WORD_BIT; } 00299 00300 __chunk_type* _M_bit_alloc(size_t __n) 00301 { return _M_end_of_storage.allocate(_M_bits_to_chunks(__n)); } 00302 00303 void _M_deallocate() { 00304 if (_M_start._M_p) 00305 _M_end_of_storage.deallocate(_M_start._M_p, 00306 _M_end_of_storage._M_data - _M_start._M_p); 00307 } 00308 00309 _Bit_iterator _M_start; 00310 _Bit_iterator _M_finish; 00311 _STLP_alloc_proxy<__chunk_type*, __chunk_type, __chunk_allocator_type> _M_end_of_storage; 00312 }; 00313 00314 00315 // The next few lines are confusing. What we're doing is declaring a 00316 // partial specialization of vector<T, Alloc> if we have the necessary 00317 // compiler support. Otherwise, we define a class bit_vector which uses 00318 // the default allocator. 00319 00320 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_NO_BOOL) && !defined (__SUNPRO_CC) 00321 # define _STLP_VECBOOL_TEMPLATE 00322 # define __BVEC_TMPL_HEADER template <class _Alloc> 00323 #else 00324 # undef _STLP_VECBOOL_TEMPLATE 00325 # ifdef _STLP_NO_BOOL 00326 # define __BVEC_TMPL_HEADER 00327 # else 00328 # define __BVEC_TMPL_HEADER _STLP_TEMPLATE_NULL 00329 # endif 00330 # define _Alloc allocator<bool> 00331 #endif 00332 00333 #if defined (_STLP_DEBUG) 00334 # define vector _STLP_NON_DBG_NAME(vector) 00335 #endif 00336 00337 #ifdef _STLP_NO_BOOL 00338 # define __BVECTOR_QUALIFIED bit_vector 00339 # define __BVECTOR bit_vector 00340 #else 00341 # ifdef _STLP_VECBOOL_TEMPLATE 00342 # define __BVECTOR_QUALIFIED vector<bool, _Alloc> 00343 # else 00344 # define __BVECTOR_QUALIFIED vector<bool, allocator<bool> > 00345 # endif 00346 # if defined (_STLP_PARTIAL_SPEC_NEEDS_TEMPLATE_ARGS) 00347 # define __BVECTOR __BVECTOR_QUALIFIED 00348 # else 00349 # define __BVECTOR vector 00350 # endif 00351 #endif 00352 00353 #if !defined (_STLP_DEBUG) || defined (_STLP_NO_BOOL) 00354 _STLP_MOVE_TO_STD_NAMESPACE 00355 #endif 00356 00357 __BVEC_TMPL_HEADER 00358 class __BVECTOR_QUALIFIED : public _STLP_PRIV _Bvector_base<_Alloc > 00359 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_DEBUG) 00360 , public __stlport_class< __BVECTOR_QUALIFIED > 00361 #endif 00362 { 00363 typedef _STLP_PRIV _Bvector_base<_Alloc > _Base; 00364 typedef __BVECTOR_QUALIFIED _Self; 00365 public: 00366 typedef bool value_type; 00367 typedef size_t size_type; 00368 typedef ptrdiff_t difference_type; 00369 typedef _STLP_PRIV _Bit_reference reference; 00370 typedef bool const_reference; 00371 typedef _STLP_PRIV _Bit_reference* pointer; 00372 typedef const bool* const_pointer; 00373 typedef random_access_iterator_tag _Iterator_category; 00374 00375 typedef _STLP_PRIV _Bit_iterator iterator; 00376 typedef _STLP_PRIV _Bit_const_iterator const_iterator; 00377 00378 _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS; 00379 00380 #ifdef _STLP_VECBOOL_TEMPLATE 00381 typedef _STLP_TYPENAME _STLP_PRIV _Bvector_base<_Alloc >::allocator_type allocator_type; 00382 typedef _STLP_TYPENAME _STLP_PRIV _Bvector_base<_Alloc >::__chunk_type __chunk_type; 00383 #else 00384 typedef _STLP_PRIV _Bvector_base<_Alloc >::allocator_type allocator_type; 00385 typedef _STLP_PRIV _Bvector_base<_Alloc >::__chunk_type __chunk_type; 00386 #endif 00387 00388 protected: 00389 00390 void _M_initialize(size_type __n) { 00391 __chunk_type* __q = this->_M_bit_alloc(__n); 00392 this->_M_end_of_storage._M_data = __q + _Base::_M_bits_to_chunks(__n); 00393 this->_M_start = iterator(__q, 0); 00394 this->_M_finish = this->_M_start + difference_type(__n); 00395 } 00396 void _M_insert_aux(iterator __position, bool __x) { 00397 if (this->_M_finish._M_p != this->_M_end_of_storage._M_data) { 00398 _STLP_PRIV __copy_backward(__position, this->_M_finish, this->_M_finish + 1, 00399 random_access_iterator_tag(), (difference_type*)0 ); 00400 *__position = __x; 00401 ++this->_M_finish; 00402 } 00403 else { 00404 size_type __len = size() ? 2 * size() : _STLP_WORD_BIT; 00405 __chunk_type* __q = this->_M_bit_alloc(__len); 00406 iterator __i = _STLP_STD::copy(begin(), __position, iterator(__q, 0)); 00407 *__i++ = __x; 00408 this->_M_finish = _STLP_STD::copy(__position, end(), __i); 00409 this->_M_deallocate(); 00410 this->_M_end_of_storage._M_data = __q + _Base::_M_bits_to_chunks(__len); 00411 this->_M_start = iterator(__q, 0); 00412 } 00413 } 00414 00415 #if defined (_STLP_MEMBER_TEMPLATES) 00416 template <class _InputIterator> 00417 void _M_initialize_range(_InputIterator __first, _InputIterator __last, 00418 const input_iterator_tag &) { 00419 this->_M_start = iterator(); 00420 this->_M_finish = iterator(); 00421 this->_M_end_of_storage._M_data = 0; 00422 for ( ; __first != __last; ++__first) 00423 push_back(*__first); 00424 } 00425 00426 template <class _ForwardIterator> 00427 void _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last, 00428 const forward_iterator_tag &) { 00429 size_type __n = _STLP_STD::distance(__first, __last); 00430 _M_initialize(__n); 00431 _STLP_STD::copy(__first, __last, this->_M_start); 00432 } 00433 00434 template <class _InputIterator> 00435 void _M_insert_range(iterator __pos, 00436 _InputIterator __first, _InputIterator __last, 00437 const input_iterator_tag &) { 00438 for ( ; __first != __last; ++__first) { 00439 __pos = insert(__pos, *__first); 00440 ++__pos; 00441 } 00442 } 00443 00444 template <class _ForwardIterator> 00445 void _M_insert_range(iterator __position, 00446 _ForwardIterator __first, _ForwardIterator __last, 00447 const forward_iterator_tag &) { 00448 if (__first != __last) { 00449 size_type __n = _STLP_STD::distance(__first, __last); 00450 if (capacity() - size() >= __n) { 00451 _STLP_PRIV __copy_backward(__position, end(), this->_M_finish + difference_type(__n), 00452 random_access_iterator_tag(), (difference_type*)0 ); 00453 _STLP_STD::copy(__first, __last, __position); 00454 this->_M_finish += difference_type(__n); 00455 } 00456 else { 00457 size_type __len = size() + (max)(size(), __n); 00458 __chunk_type* __q = this->_M_bit_alloc(__len); 00459 iterator __i = _STLP_STD::copy(begin(), __position, iterator(__q, 0)); 00460 __i = _STLP_STD::copy(__first, __last, __i); 00461 this->_M_finish = _STLP_STD::copy(__position, end(), __i); 00462 this->_M_deallocate(); 00463 this->_M_end_of_storage._M_data = __q + _Base::_M_bits_to_chunks(__len); 00464 this->_M_start = iterator(__q, 0); 00465 } 00466 } 00467 } 00468 00469 #endif /* _STLP_MEMBER_TEMPLATES */ 00470 00471 public: 00472 iterator begin() { return this->_M_start; } 00473 const_iterator begin() const { return this->_M_start; } 00474 iterator end() { return this->_M_finish; } 00475 const_iterator end() const { return this->_M_finish; } 00476 00477 reverse_iterator rbegin() { return reverse_iterator(end()); } 00478 const_reverse_iterator rbegin() const { 00479 return const_reverse_iterator(end()); 00480 } 00481 reverse_iterator rend() { return reverse_iterator(begin()); } 00482 const_reverse_iterator rend() const { 00483 return const_reverse_iterator(begin()); 00484 } 00485 00486 size_type size() const { return size_type(end() - begin()); } 00487 size_type max_size() const { return size_type(-1); } 00488 size_type capacity() const { 00489 return size_type(const_iterator(this->_M_end_of_storage._M_data, 0) - begin()); 00490 } 00491 bool empty() const { return begin() == end(); } 00492 reference operator[](size_type __n) 00493 { return *(begin() + difference_type(__n)); } 00494 const_reference operator[](size_type __n) const 00495 { return *(begin() + difference_type(__n)); } 00496 00497 void _M_range_check(size_type __n) const { 00498 if (__n >= this->size()) 00499 __stl_throw_range_error("vector<bool>"); 00500 } 00501 00502 reference at(size_type __n) 00503 { _M_range_check(__n); return (*this)[__n]; } 00504 const_reference at(size_type __n) const 00505 { _M_range_check(__n); return (*this)[__n]; } 00506 00507 explicit __BVECTOR(const allocator_type& __a = allocator_type()) 00508 : _STLP_PRIV _Bvector_base<_Alloc >(__a) {} 00509 00510 __BVECTOR(size_type __n, bool __val, 00511 const allocator_type& __a = allocator_type()) 00512 : _STLP_PRIV _Bvector_base<_Alloc >(__a) { 00513 _M_initialize(__n); 00514 fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __val ? ~0 : 0); 00515 } 00516 00517 explicit __BVECTOR(size_type __n) 00518 : _STLP_PRIV _Bvector_base<_Alloc >(allocator_type()) { 00519 _M_initialize(__n); 00520 fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), 0); 00521 } 00522 00523 __BVECTOR(const _Self& __x) 00524 : _STLP_PRIV _Bvector_base<_Alloc >(__x.get_allocator()) { 00525 _M_initialize(__x.size()); 00526 _STLP_STD::copy(__x.begin(), __x.end(), this->_M_start); 00527 } 00528 00529 #if defined (_STLP_MEMBER_TEMPLATES) 00530 template <class _Integer> 00531 void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type&) { 00532 _M_initialize(__n); 00533 fill(this->_M_start._M_p, this->_M_end_of_storage._M_data, __x ? ~0 : 0); 00534 } 00535 00536 template <class _InputIterator> 00537 void _M_initialize_dispatch(_InputIterator __first, _InputIterator __last, 00538 const __false_type&) { 00539 _M_initialize_range(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator)); 00540 } 00541 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS) 00542 // Check whether it's an integral type. If so, it's not an iterator. 00543 template <class _InputIterator> 00544 __BVECTOR(_InputIterator __first, _InputIterator __last) 00545 : _STLP_PRIV _Bvector_base<_Alloc >(allocator_type()) { 00546 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 00547 _M_initialize_dispatch(__first, __last, _Integral()); 00548 } 00549 # endif 00550 template <class _InputIterator> 00551 __BVECTOR(_InputIterator __first, _InputIterator __last, 00552 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL) 00553 : _STLP_PRIV _Bvector_base<_Alloc >(__a) { 00554 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 00555 _M_initialize_dispatch(__first, __last, _Integral()); 00556 } 00557 #else /* _STLP_MEMBER_TEMPLATES */ 00558 __BVECTOR(const_iterator __first, const_iterator __last, 00559 const allocator_type& __a = allocator_type()) 00560 : _STLP_PRIV _Bvector_base<_Alloc >(__a) { 00561 size_type __n = _STLP_STD::distance(__first, __last); 00562 _M_initialize(__n); 00563 _STLP_STD::copy(__first, __last, this->_M_start); 00564 } 00565 __BVECTOR(const bool* __first, const bool* __last, 00566 const allocator_type& __a = allocator_type()) 00567 : _STLP_PRIV _Bvector_base<_Alloc >(__a) { 00568 size_type __n = _STLP_STD::distance(__first, __last); 00569 _M_initialize(__n); 00570 _STLP_STD::copy(__first, __last, this->_M_start); 00571 } 00572 #endif /* _STLP_MEMBER_TEMPLATES */ 00573 00574 #if !defined (_STLP_NO_MOVE_SEMANTIC) 00575 __BVECTOR(__move_source<_Self> src) 00576 : _STLP_PRIV _Bvector_base<_Alloc >(__move_source<_Base>(src.get())) {} 00577 #endif 00578 00579 ~__BVECTOR() {} 00580 00581 __BVECTOR_QUALIFIED& operator=(const __BVECTOR_QUALIFIED& __x) { 00582 if (&__x == this) return *this; 00583 if (__x.size() > capacity()) { 00584 this->_M_deallocate(); 00585 _M_initialize(__x.size()); 00586 } 00587 _STLP_STD::copy(__x.begin(), __x.end(), begin()); 00588 this->_M_finish = begin() + difference_type(__x.size()); 00589 return *this; 00590 } 00591 00592 // assign(), a generalized assignment member function. Two 00593 // versions: one that takes a count, and one that takes a range. 00594 // The range version is a member template, so we dispatch on whether 00595 // or not the type is an integer. 00596 00597 void _M_fill_assign(size_t __n, bool __x) { 00598 if (__n > size()) { 00599 fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __x ? ~0 : 0); 00600 insert(end(), __n - size(), __x); 00601 } 00602 else { 00603 erase(begin() + __n, end()); 00604 fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __x ? ~0 : 0); 00605 } 00606 } 00607 void assign(size_t __n, bool __x) { _M_fill_assign(__n, __x); } 00608 00609 #if defined (_STLP_MEMBER_TEMPLATES) 00610 template <class _InputIterator> 00611 void assign(_InputIterator __first, _InputIterator __last) { 00612 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 00613 _M_assign_dispatch(__first, __last, _Integral()); 00614 } 00615 00616 template <class _Integer> 00617 void _M_assign_dispatch(_Integer __n, _Integer __val, const __true_type&) 00618 { _M_fill_assign((size_t) __n, (bool) __val); } 00619 00620 template <class _InputIter> 00621 void _M_assign_dispatch(_InputIter __first, _InputIter __last, const __false_type&) 00622 { _M_assign_aux(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter)); } 00623 00624 template <class _InputIterator> 00625 void _M_assign_aux(_InputIterator __first, _InputIterator __last, 00626 const input_iterator_tag &) { 00627 iterator __cur = begin(); 00628 for ( ; __first != __last && __cur != end(); ++__cur, ++__first) 00629 *__cur = *__first; 00630 if (__first == __last) 00631 erase(__cur, end()); 00632 else 00633 insert(end(), __first, __last); 00634 } 00635 00636 template <class _ForwardIterator> 00637 void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, 00638 const forward_iterator_tag &) { 00639 size_type __len = _STLP_STD::distance(__first, __last); 00640 if (__len < size()) 00641 erase(_STLP_STD::copy(__first, __last, begin()), end()); 00642 else { 00643 _ForwardIterator __mid = __first; 00644 _STLP_STD::advance(__mid, size()); 00645 _STLP_STD::copy(__first, __mid, begin()); 00646 insert(end(), __mid, __last); 00647 } 00648 } 00649 #endif /* _STLP_MEMBER_TEMPLATES */ 00650 00651 void reserve(size_type __n) { 00652 if (capacity() < __n) { 00653 if (max_size() < __n) 00654 __stl_throw_length_error("vector<bool>"); 00655 __chunk_type* __q = this->_M_bit_alloc(__n); 00656 _STLP_PRIV _Bit_iterator __z(__q, 0); 00657 this->_M_finish = _STLP_STD::copy(begin(), end(), __z); 00658 this->_M_deallocate(); 00659 this->_M_start = iterator(__q, 0); 00660 this->_M_end_of_storage._M_data = __q + _Base::_M_bits_to_chunks(__n); 00661 } 00662 } 00663 00664 reference front() { return *begin(); } 00665 const_reference front() const { return *begin(); } 00666 reference back() { return *(end() - 1); } 00667 const_reference back() const { return *(end() - 1); } 00668 void push_back(bool __x) { 00669 if (this->_M_finish._M_p != this->_M_end_of_storage._M_data) { 00670 *(this->_M_finish) = __x; 00671 ++this->_M_finish; 00672 } 00673 else 00674 _M_insert_aux(end(), __x); 00675 } 00676 void swap(__BVECTOR_QUALIFIED& __x) { 00677 _STLP_STD::swap(this->_M_start, __x._M_start); 00678 _STLP_STD::swap(this->_M_finish, __x._M_finish); 00679 this->_M_end_of_storage.swap(__x._M_end_of_storage); 00680 } 00681 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) 00682 void _M_swap_workaround(__BVECTOR_QUALIFIED& __x) { swap(__x); } 00683 #endif 00684 00685 iterator insert(iterator __position, bool __x = bool()) { 00686 difference_type __n = __position - begin(); 00687 if (this->_M_finish._M_p != this->_M_end_of_storage._M_data && __position == end()) { 00688 *(this->_M_finish) = __x; 00689 ++this->_M_finish; 00690 } 00691 else 00692 _M_insert_aux(__position, __x); 00693 return begin() + __n; 00694 } 00695 00696 #if defined (_STLP_MEMBER_TEMPLATES) 00697 00698 template <class _Integer> 00699 void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x, 00700 const __true_type&) { 00701 _M_fill_insert(__pos, (size_type) __n, (bool) __x); 00702 } 00703 00704 template <class _InputIterator> 00705 void _M_insert_dispatch(iterator __pos, 00706 _InputIterator __first, _InputIterator __last, 00707 const __false_type&) { 00708 _M_insert_range(__pos, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator)); 00709 } 00710 00711 // Check whether it's an integral type. If so, it's not an iterator. 00712 template <class _InputIterator> 00713 void insert(iterator __position, 00714 _InputIterator __first, _InputIterator __last) { 00715 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 00716 _M_insert_dispatch(__position, __first, __last, _Integral()); 00717 } 00718 #else /* _STLP_MEMBER_TEMPLATES */ 00719 void insert(iterator __position, 00720 const_iterator __first, const_iterator __last) { 00721 if (__first == __last) return; 00722 size_type __n = _STLP_STD::distance(__first, __last); 00723 if (capacity() - size() >= __n) { 00724 _STLP_PRIV __copy_backward(__position, end(), this->_M_finish + __n, 00725 random_access_iterator_tag(), (difference_type*)0 ); 00726 _STLP_STD::copy(__first, __last, __position); 00727 this->_M_finish += __n; 00728 } 00729 else { 00730 size_type __len = size() + (max)(size(), __n); 00731 __chunk_type* __q = this->_M_bit_alloc(__len); 00732 iterator __i = _STLP_STD::copy(begin(), __position, iterator(__q, 0)); 00733 __i = _STLP_STD::copy(__first, __last, __i); 00734 this->_M_finish = _STLP_STD::copy(__position, end(), __i); 00735 this->_M_deallocate(); 00736 this->_M_end_of_storage._M_data = __q + _Base::_M_bits_to_chunks(__len); 00737 this->_M_start = iterator(__q, 0); 00738 } 00739 } 00740 00741 void insert(iterator __position, const bool* __first, const bool* __last) { 00742 if (__first == __last) return; 00743 size_type __n = _STLP_STD::distance(__first, __last); 00744 if (capacity() - size() >= __n) { 00745 _STLP_PRIV __copy_backward(__position, end(), this->_M_finish + __n, 00746 random_access_iterator_tag(), (difference_type*)0 ); 00747 _STLP_STD::copy(__first, __last, __position); 00748 this->_M_finish += __n; 00749 } 00750 else { 00751 size_type __len = size() + (max)(size(), __n); 00752 __chunk_type* __q = this->_M_bit_alloc(__len); 00753 iterator __i = _STLP_STD::copy(begin(), __position, iterator(__q, 0)); 00754 __i = _STLP_STD::copy(__first, __last, __i); 00755 this->_M_finish = _STLP_STD::copy(__position, end(), __i); 00756 this->_M_deallocate(); 00757 this->_M_end_of_storage._M_data = __q + _Base::_M_bits_to_chunks(__len); 00758 this->_M_start = iterator(__q, 0); 00759 } 00760 } 00761 #endif /* _STLP_MEMBER_TEMPLATES */ 00762 00763 void _M_fill_insert(iterator __position, size_type __n, bool __x) { 00764 if (__n == 0) return; 00765 if (capacity() - size() >= __n) { 00766 _STLP_PRIV __copy_backward(__position, end(), this->_M_finish + difference_type(__n), 00767 random_access_iterator_tag(), (difference_type*)0 ); 00768 fill(__position, __position + difference_type(__n), __x); 00769 this->_M_finish += difference_type(__n); 00770 } 00771 else { 00772 size_type __len = size() + (max)(size(), __n); 00773 __chunk_type* __q = this->_M_bit_alloc(__len); 00774 iterator __i = _STLP_STD::copy(begin(), __position, iterator(__q, 0)); 00775 fill_n(__i, __n, __x); 00776 this->_M_finish = _STLP_STD::copy(__position, end(), __i + difference_type(__n)); 00777 this->_M_deallocate(); 00778 this->_M_end_of_storage._M_data = __q + _Base::_M_bits_to_chunks(__len); 00779 this->_M_start = iterator(__q, 0); 00780 } 00781 } 00782 00783 void insert(iterator __position, size_type __n, bool __x) { 00784 _M_fill_insert(__position, __n, __x); 00785 } 00786 00787 void pop_back() { 00788 --this->_M_finish; 00789 } 00790 iterator erase(iterator __position) { 00791 if (__position + 1 != end()) 00792 _STLP_STD::copy(__position + 1, end(), __position); 00793 --this->_M_finish; 00794 return __position; 00795 } 00796 iterator erase(iterator __first, iterator __last) { 00797 this->_M_finish = _STLP_STD::copy(__last, end(), __first); 00798 return __first; 00799 } 00800 void resize(size_type __new_size, bool __x = bool()) { 00801 if (__new_size < size()) 00802 erase(begin() + difference_type(__new_size), end()); 00803 else 00804 insert(end(), __new_size - size(), __x); 00805 } 00806 void flip() { 00807 for (__chunk_type* __p = this->_M_start._M_p; __p != this->_M_end_of_storage._M_data; ++__p) 00808 *__p = ~*__p; 00809 } 00810 00811 void clear() { erase(begin(), end()); } 00812 }; 00813 00814 #if defined (_STLP_NO_BOOL) || defined (__HP_aCC) // fixed soon (03/17/2000) 00815 # define _STLP_TEMPLATE_HEADER __BVEC_TMPL_HEADER 00816 # define _STLP_TEMPLATE_CONTAINER __BVECTOR_QUALIFIED 00817 # include <stl/_relops_cont.h> 00818 # undef _STLP_TEMPLATE_CONTAINER 00819 # undef _STLP_TEMPLATE_HEADER 00820 #endif /* NO_BOOL */ 00821 00822 #if defined (_STLP_DEBUG) && !defined (_STLP_NO_BOOL) 00823 _STLP_MOVE_TO_STD_NAMESPACE 00824 #endif 00825 00826 _STLP_END_NAMESPACE 00827 00828 #undef vector 00829 #undef _Alloc 00830 #undef _STLP_VECBOOL_TEMPLATE 00831 #undef __BVECTOR 00832 #undef __BVECTOR_QUALIFIED 00833 #undef __BVEC_TMPL_HEADER 00834 00835 #undef _STLP_WORD_BIT 00836 00837 #endif /* _STLP_INTERNAL_BVECTOR_H */ 00838 00839 // Local Variables: 00840 // mode:C++ 00841 // End: Generated on Sat May 26 2012 04:27:31 for ReactOS by
1.7.6.1
|