_bvector.h

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

Generated on Mon Jun 5 10:20:45 2006 for Intelligence.kdevelop by  doxygen 1.4.6