/home/ntakagi/work/STLport-5.1.5/stlport/stl/_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 typename _Alloc_traits<bool, _Alloc>::allocator_type allocator_type;
00273   typedef unsigned int __chunk_type;
00274   typedef typename _Alloc_traits<__chunk_type,
00275           _Alloc>::allocator_type __chunk_allocator_type;
00276   allocator_type get_allocator() const {
00277     return _STLP_CONVERT_ALLOCATOR((const __chunk_allocator_type&)_M_end_of_storage, bool);
00278   }
00279   static allocator_type __get_dfl_allocator() { return allocator_type(); }
00280 
00281   _Bvector_base(const allocator_type& __a)
00282     : _M_start(), _M_finish(), _M_end_of_storage(_STLP_CONVERT_ALLOCATOR(__a, __chunk_type),
00283                                                  (__chunk_type*)0)
00284   {}
00285   _Bvector_base(__move_source<_Self> src)
00286     : _M_start(src.get()._M_start), _M_finish(src.get()._M_finish),
00287       _M_end_of_storage(src.get()._M_end_of_storage) {
00288     //Make the source destroyable
00289     src.get()._M_start._M_p = 0;
00290   }
00291 
00292   ~_Bvector_base() {
00293     _M_deallocate();
00294   }
00295 
00296 protected:
00297 
00298   unsigned int* _M_bit_alloc(size_t __n) {
00299     return _M_end_of_storage.allocate((__n + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT);
00300   }
00301   void _M_deallocate() {
00302     if (_M_start._M_p)
00303       _M_end_of_storage.deallocate(_M_start._M_p,
00304                                    _M_end_of_storage._M_data - _M_start._M_p);
00305   }
00306 
00307   _Bit_iterator _M_start;
00308   _Bit_iterator _M_finish;
00309   _STLP_alloc_proxy<__chunk_type*, __chunk_type, __chunk_allocator_type> _M_end_of_storage;
00310 };
00311 
00312 
00313 // The next few lines are confusing.  What we're doing is declaring a
00314 //  partial specialization of vector<T, Alloc> if we have the necessary
00315 //  compiler support.  Otherwise, we define a class bit_vector which uses
00316 //  the default allocator.
00317 
00318 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_NO_BOOL) && !defined (__SUNPRO_CC)
00319 #  define _STLP_VECBOOL_TEMPLATE
00320 #  define __BVEC_TMPL_HEADER template <class _Alloc>
00321 #else
00322 #  undef _STLP_VECBOOL_TEMPLATE
00323 #  ifdef _STLP_NO_BOOL
00324 #    define __BVEC_TMPL_HEADER
00325 #  else
00326 #    define __BVEC_TMPL_HEADER _STLP_TEMPLATE_NULL
00327 #  endif
00328 #  if !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__)))      //*TY 12/17/2000 -
00329 #    define _Alloc _STLP_DEFAULT_ALLOCATOR(bool)
00330 #  else
00331 #    define _Alloc allocator<bool>
00332 #  endif
00333 #endif
00334 
00335 #if defined (_STLP_DEBUG)
00336 #  define vector _STLP_NON_DBG_NAME(vector)
00337 #endif
00338 
00339 #ifdef _STLP_NO_BOOL
00340 #  define __BVECTOR_QUALIFIED bit_vector
00341 #  define __BVECTOR           bit_vector
00342 #else
00343 #  ifdef _STLP_VECBOOL_TEMPLATE
00344 #    define __BVECTOR_QUALIFIED vector<bool, _Alloc>
00345 #  else
00346 #    define __BVECTOR_QUALIFIED vector<bool, allocator<bool> >
00347 #  endif
00348 #  if defined (_STLP_PARTIAL_SPEC_NEEDS_TEMPLATE_ARGS)
00349 #    define __BVECTOR __BVECTOR_QUALIFIED
00350 #  else
00351 #    define __BVECTOR vector
00352 #  endif
00353 #endif
00354 
00355 #if !defined (_STLP_DEBUG) || defined (_STLP_NO_BOOL)
00356 _STLP_MOVE_TO_STD_NAMESPACE
00357 #endif
00358 
00359 __BVEC_TMPL_HEADER
00360 class __BVECTOR_QUALIFIED : public _STLP_PRIV _Bvector_base<_Alloc >
00361 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_DEBUG)
00362                           , public __stlport_class< __BVECTOR_QUALIFIED >
00363 #endif
00364 {
00365   typedef _STLP_PRIV _Bvector_base<_Alloc > _Base;
00366   typedef __BVECTOR_QUALIFIED _Self;
00367 public:
00368   typedef bool value_type;
00369   typedef size_t size_type;
00370   typedef ptrdiff_t difference_type;
00371   typedef _STLP_PRIV _Bit_reference reference;
00372   typedef bool const_reference;
00373   typedef _STLP_PRIV _Bit_reference* pointer;
00374   typedef const bool* const_pointer;
00375   typedef random_access_iterator_tag _Iterator_category;
00376 
00377   typedef _STLP_PRIV _Bit_iterator          iterator;
00378   typedef _STLP_PRIV _Bit_const_iterator    const_iterator;
00379 
00380   _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
00381 
00382 #ifdef _STLP_VECBOOL_TEMPLATE
00383   typedef typename _STLP_PRIV _Bvector_base<_Alloc >::allocator_type allocator_type;
00384   typedef typename _STLP_PRIV _Bvector_base<_Alloc >::__chunk_type __chunk_type;
00385 #else
00386   typedef _STLP_PRIV _Bvector_base<_Alloc >::allocator_type allocator_type;
00387   typedef _STLP_PRIV _Bvector_base<_Alloc >::__chunk_type __chunk_type;
00388 #endif
00389 
00390 protected:
00391 
00392   void _M_initialize(size_type __n) {
00393     unsigned int* __q = this->_M_bit_alloc(__n);
00394     this->_M_end_of_storage._M_data = __q + (__n + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT;
00395     this->_M_start = iterator(__q, 0);
00396     this->_M_finish = this->_M_start + difference_type(__n);
00397   }
00398   void _M_insert_aux(iterator __position, bool __x) {
00399     if (this->_M_finish._M_p != this->_M_end_of_storage._M_data) {
00400       _STLP_PRIV __copy_backward(__position, this->_M_finish, this->_M_finish + 1,
00401                                  random_access_iterator_tag(), (difference_type*)0 );
00402       *__position = __x;
00403       ++this->_M_finish;
00404     }
00405     else {
00406       size_type __len = size() ? 2 * size() : _STLP_WORD_BIT;
00407       unsigned int* __q = this->_M_bit_alloc(__len);
00408       iterator __i = copy(begin(), __position, iterator(__q, 0));
00409       *__i++ = __x;
00410       this->_M_finish = copy(__position, end(), __i);
00411       this->_M_deallocate();
00412       this->_M_end_of_storage._M_data = __q + (__len + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT;
00413       this->_M_start = iterator(__q, 0);
00414     }
00415   }
00416 
00417 #if defined (_STLP_MEMBER_TEMPLATES)
00418   template <class _InputIterator>
00419   void _M_initialize_range(_InputIterator __first, _InputIterator __last,
00420                            const input_iterator_tag &) {
00421     this->_M_start = iterator();
00422     this->_M_finish = iterator();
00423     this->_M_end_of_storage._M_data = 0;
00424     for ( ; __first != __last; ++__first)
00425       push_back(*__first);
00426   }
00427 
00428   template <class _ForwardIterator>
00429   void _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
00430                            const forward_iterator_tag &) {
00431     size_type __n = distance(__first, __last);
00432     _M_initialize(__n);
00433     copy(__first, __last, this->_M_start);
00434   }
00435 
00436   template <class _InputIterator>
00437   void _M_insert_range(iterator __pos,
00438                        _InputIterator __first, _InputIterator __last,
00439                        const input_iterator_tag &) {
00440     for ( ; __first != __last; ++__first) {
00441       __pos = insert(__pos, *__first);
00442       ++__pos;
00443     }
00444   }
00445 
00446   template <class _ForwardIterator>
00447   void _M_insert_range(iterator __position,
00448                        _ForwardIterator __first, _ForwardIterator __last,
00449                        const forward_iterator_tag &) {
00450     if (__first != __last) {
00451       size_type __n = distance(__first, __last);
00452       if (capacity() - size() >= __n) {
00453         _STLP_PRIV __copy_backward(__position, end(), this->_M_finish + difference_type(__n),
00454                                    random_access_iterator_tag(), (difference_type*)0 );
00455         copy(__first, __last, __position);
00456         this->_M_finish += difference_type(__n);
00457       }
00458       else {
00459         size_type __len = size() + (max)(size(), __n);
00460         unsigned int* __q = this->_M_bit_alloc(__len);
00461         iterator __i = copy(begin(), __position, iterator(__q, 0));
00462         __i = copy(__first, __last, __i);
00463         this->_M_finish = copy(__position, end(), __i);
00464         this->_M_deallocate();
00465         this->_M_end_of_storage._M_data = __q + (__len + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT;
00466         this->_M_start = iterator(__q, 0);
00467       }
00468     }
00469   }
00470 
00471 #endif /* _STLP_MEMBER_TEMPLATES */
00472 
00473 public:
00474   iterator begin() { return this->_M_start; }
00475   const_iterator begin() const { return this->_M_start; }
00476   iterator end() { return this->_M_finish; }
00477   const_iterator end() const { return this->_M_finish; }
00478 
00479   reverse_iterator rbegin() { return reverse_iterator(end()); }
00480   const_reverse_iterator rbegin() const {
00481     return const_reverse_iterator(end());
00482   }
00483   reverse_iterator rend() { return reverse_iterator(begin()); }
00484   const_reverse_iterator rend() const {
00485     return const_reverse_iterator(begin());
00486   }
00487 
00488   size_type size() const { return size_type(end() - begin()); }
00489   size_type max_size() const { return size_type(-1); }
00490   size_type capacity() const {
00491     return size_type(const_iterator(this->_M_end_of_storage._M_data, 0) - begin());
00492   }
00493   bool empty() const { return begin() == end(); }
00494   reference operator[](size_type __n)
00495   { return *(begin() + difference_type(__n)); }
00496   const_reference operator[](size_type __n) const
00497   { return *(begin() + difference_type(__n)); }
00498 
00499   void _M_range_check(size_type __n) const {
00500     if (__n >= this->size())
00501       __stl_throw_range_error("vector<bool>");
00502   }
00503 
00504   reference at(size_type __n)
00505     { _M_range_check(__n); return (*this)[__n]; }
00506   const_reference at(size_type __n) const
00507     { _M_range_check(__n); return (*this)[__n]; }
00508 
00509   explicit __BVECTOR(const allocator_type& __a = allocator_type())
00510     : _STLP_PRIV _Bvector_base<_Alloc >(__a) {}
00511 
00512   __BVECTOR(size_type __n, bool __val,
00513             const allocator_type& __a = allocator_type())
00514     : _STLP_PRIV _Bvector_base<_Alloc >(__a) {
00515     _M_initialize(__n);
00516     fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __val ? ~0 : 0);
00517   }
00518 
00519   explicit __BVECTOR(size_type __n)
00520     : _STLP_PRIV _Bvector_base<_Alloc >(allocator_type()) {
00521     _M_initialize(__n);
00522     fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), 0);
00523   }
00524 
00525   __BVECTOR(const _Self& __x)
00526     : _STLP_PRIV _Bvector_base<_Alloc >(__x.get_allocator()) {
00527     _M_initialize(__x.size());
00528     copy(__x.begin(), __x.end(), this->_M_start);
00529   }
00530 
00531 #if defined (_STLP_MEMBER_TEMPLATES)
00532   template <class _Integer>
00533   void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type&) {
00534     _M_initialize(__n);
00535     fill(this->_M_start._M_p, this->_M_end_of_storage._M_data, __x ? ~0 : 0);
00536   }
00537 
00538   template <class _InputIterator>
00539   void _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
00540                               const __false_type&) {
00541     _M_initialize_range(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
00542   }
00543 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
00544   // Check whether it's an integral type.  If so, it's not an iterator.
00545   template <class _InputIterator>
00546   __BVECTOR(_InputIterator __first, _InputIterator __last)
00547     : _STLP_PRIV _Bvector_base<_Alloc >(allocator_type()) {
00548     typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
00549     _M_initialize_dispatch(__first, __last, _Integral());
00550   }
00551 #  endif
00552   template <class _InputIterator>
00553   __BVECTOR(_InputIterator __first, _InputIterator __last,
00554             const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
00555     : _STLP_PRIV _Bvector_base<_Alloc >(__a) {
00556     typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
00557     _M_initialize_dispatch(__first, __last, _Integral());
00558   }
00559 #else /* _STLP_MEMBER_TEMPLATES */
00560   __BVECTOR(const_iterator __first, const_iterator __last,
00561             const allocator_type& __a = allocator_type())
00562     : _STLP_PRIV _Bvector_base<_Alloc >(__a) {
00563     size_type __n = distance(__first, __last);
00564     _M_initialize(__n);
00565     copy(__first, __last, this->_M_start);
00566   }
00567   __BVECTOR(const bool* __first, const bool* __last,
00568             const allocator_type& __a = allocator_type())
00569     : _STLP_PRIV _Bvector_base<_Alloc >(__a) {
00570     size_type __n = distance(__first, __last);
00571     _M_initialize(__n);
00572     copy(__first, __last, this->_M_start);
00573   }
00574 #endif /* _STLP_MEMBER_TEMPLATES */
00575 
00576   __BVECTOR(__move_source<_Self> src)
00577     : _STLP_PRIV _Bvector_base<_Alloc >(__move_source<_Base>(src.get())) {}
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     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 = distance(__first, __last);
00640     if (__len < size())
00641       erase(copy(__first, __last, begin()), end());
00642     else {
00643       _ForwardIterator __mid = __first;
00644       advance(__mid, size());
00645       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       unsigned int* __q = this->_M_bit_alloc(__n);
00656       _STLP_PRIV _Bit_iterator __z(__q, 0);
00657       this->_M_finish = copy(begin(), end(), __z);
00658       this->_M_deallocate();
00659       this->_M_start = iterator(__q, 0);
00660       this->_M_end_of_storage._M_data = __q + (__n + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT;
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   iterator insert(iterator __position, bool __x = bool()) {
00682     difference_type __n = __position - begin();
00683     if (this->_M_finish._M_p != this->_M_end_of_storage._M_data && __position == end()) {
00684       *(this->_M_finish) = __x;
00685       ++this->_M_finish;
00686     }
00687     else
00688       _M_insert_aux(__position, __x);
00689     return begin() + __n;
00690   }
00691 
00692 #if defined (_STLP_MEMBER_TEMPLATES)
00693 
00694   template <class _Integer>
00695   void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
00696                           const __true_type&) {
00697     _M_fill_insert(__pos, (size_type) __n, (bool) __x);
00698   }
00699 
00700   template <class _InputIterator>
00701   void _M_insert_dispatch(iterator __pos,
00702                           _InputIterator __first, _InputIterator __last,
00703                           const __false_type&) {
00704     _M_insert_range(__pos, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
00705   }
00706 
00707   // Check whether it's an integral type.  If so, it's not an iterator.
00708   template <class _InputIterator>
00709   void insert(iterator __position,
00710               _InputIterator __first, _InputIterator __last) {
00711     typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
00712     _M_insert_dispatch(__position, __first, __last, _Integral());
00713   }
00714 #else /* _STLP_MEMBER_TEMPLATES */
00715   void insert(iterator __position,
00716               const_iterator __first, const_iterator __last) {
00717     if (__first == __last) return;
00718     size_type __n = distance(__first, __last);
00719     if (capacity() - size() >= __n) {
00720       _STLP_PRIV __copy_backward(__position, end(), this->_M_finish + __n,
00721                                  random_access_iterator_tag(), (difference_type*)0 );
00722       copy(__first, __last, __position);
00723       this->_M_finish += __n;
00724     }
00725     else {
00726       size_type __len = size() + (max)(size(), __n);
00727       unsigned int* __q = this->_M_bit_alloc(__len);
00728       iterator __i = copy(begin(), __position, iterator(__q, 0));
00729       __i = copy(__first, __last, __i);
00730       this->_M_finish = copy(__position, end(), __i);
00731       this->_M_deallocate();
00732       this->_M_end_of_storage._M_data = __q + (__len + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT;
00733       this->_M_start = iterator(__q, 0);
00734     }
00735   }
00736 
00737   void insert(iterator __position, const bool* __first, const bool* __last) {
00738     if (__first == __last) return;
00739     size_type __n = distance(__first, __last);
00740     if (capacity() - size() >= __n) {
00741       _STLP_PRIV __copy_backward(__position, end(), this->_M_finish + __n,
00742                                  random_access_iterator_tag(), (difference_type*)0 );
00743       copy(__first, __last, __position);
00744       this->_M_finish += __n;
00745     }
00746     else {
00747       size_type __len = size() + (max)(size(), __n);
00748       unsigned int* __q = this->_M_bit_alloc(__len);
00749       iterator __i = copy(begin(), __position, iterator(__q, 0));
00750       __i = copy(__first, __last, __i);
00751       this->_M_finish = copy(__position, end(), __i);
00752       this->_M_deallocate();
00753       this->_M_end_of_storage._M_data = __q + (__len + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT;
00754       this->_M_start = iterator(__q, 0);
00755     }
00756   }
00757 #endif /* _STLP_MEMBER_TEMPLATES */
00758 
00759   void _M_fill_insert(iterator __position, size_type __n, bool __x) {
00760     if (__n == 0) return;
00761     if (capacity() - size() >= __n) {
00762       _STLP_PRIV __copy_backward(__position, end(), this->_M_finish + difference_type(__n),
00763                                  random_access_iterator_tag(), (difference_type*)0 );
00764       fill(__position, __position + difference_type(__n), __x);
00765       this->_M_finish += difference_type(__n);
00766     }
00767     else {
00768       size_type __len = size() + (max)(size(), __n);
00769       unsigned int* __q = this->_M_bit_alloc(__len);
00770       iterator __i = copy(begin(), __position, iterator(__q, 0));
00771       fill_n(__i, __n, __x);
00772       this->_M_finish = copy(__position, end(), __i + difference_type(__n));
00773       this->_M_deallocate();
00774       this->_M_end_of_storage._M_data = __q + (__len + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT;
00775       this->_M_start = iterator(__q, 0);
00776     }
00777   }
00778 
00779   void insert(iterator __position, size_type __n, bool __x) {
00780     _M_fill_insert(__position, __n, __x);
00781   }
00782 
00783   void pop_back() {
00784     --this->_M_finish;
00785   }
00786   iterator erase(iterator __position) {
00787     if (__position + 1 != end())
00788       copy(__position + 1, end(), __position);
00789       --this->_M_finish;
00790     return __position;
00791   }
00792   iterator erase(iterator __first, iterator __last) {
00793     this->_M_finish = copy(__last, end(), __first);
00794     return __first;
00795   }
00796   void resize(size_type __new_size, bool __x = bool()) {
00797     if (__new_size < size())
00798       erase(begin() + difference_type(__new_size), end());
00799     else
00800       insert(end(), __new_size - size(), __x);
00801   }
00802   void flip() {
00803     for (unsigned int* __p = this->_M_start._M_p; __p != this->_M_end_of_storage._M_data; ++__p)
00804       *__p = ~*__p;
00805   }
00806 
00807   void clear() { erase(begin(), end()); }
00808 };
00809 
00810 #if defined  (_STLP_NO_BOOL) || defined (__HP_aCC) // fixed soon (03/17/2000)
00811 #  define _STLP_TEMPLATE_HEADER __BVEC_TMPL_HEADER
00812 #  define _STLP_TEMPLATE_CONTAINER __BVECTOR_QUALIFIED
00813 #  include <stl/_relops_cont.h>
00814 #  undef _STLP_TEMPLATE_CONTAINER
00815 #  undef _STLP_TEMPLATE_HEADER
00816 #endif /* NO_BOOL */
00817 
00818 #if defined (_STLP_DEBUG) && !defined (_STLP_NO_BOOL)
00819 _STLP_MOVE_TO_STD_NAMESPACE
00820 #endif
00821 
00822 _STLP_END_NAMESPACE
00823 
00824 #undef vector
00825 #undef _Alloc
00826 #undef _STLP_VECBOOL_TEMPLATE
00827 #undef __BVECTOR
00828 #undef __BVECTOR_QUALIFIED
00829 #undef __BVEC_TMPL_HEADER
00830 
00831 #undef _STLP_WORD_BIT
00832 
00833 #endif /* _STLP_INTERNAL_BVECTOR_H */
00834 
00835 // Local Variables:
00836 // mode:C++
00837 // End:



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