home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / stl / _vector.c < prev    next >
C/C++ Source or Header  |  2002-02-02  |  4KB  |  138 lines

  1. /*
  2.  *
  3.  *
  4.  * Copyright (c) 1994
  5.  * Hewlett-Packard Company
  6.  *
  7.  * Copyright (c) 1996,1997
  8.  * Silicon Graphics Computer Systems, Inc.
  9.  *
  10.  * Copyright (c) 1997
  11.  * Moscow Center for SPARC Technology
  12.  *
  13.  * Copyright (c) 1999 
  14.  * Boris Fomitchev
  15.  *
  16.  * This material is provided "as is", with absolutely no warranty expressed
  17.  * or implied. Any use is at your own risk.
  18.  *
  19.  * Permission to use or copy this software for any purpose is hereby granted 
  20.  * without fee, provided the above notices are retained on all copies.
  21.  * Permission to modify the code and to distribute modified code is granted,
  22.  * provided the above notices are retained, and a notice that the code was
  23.  * modified is included with the above copyright notice.
  24.  *
  25.  */
  26. #ifndef _STLP_VECTOR_C
  27. #define _STLP_VECTOR_C
  28.  
  29. # if !defined (_STLP_INTERNAL_VECTOR_H)
  30. #  include <stl/_vector.h>
  31. # endif
  32.  
  33. # if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
  34. #  define iterator       _Tp*
  35. #  define size_type           size_t
  36. # endif
  37.  
  38. #  undef  vector
  39. #  define vector __WORKAROUND_DBG_RENAME(vector)
  40.  
  41. _STLP_BEGIN_NAMESPACE
  42.  
  43. template <class _Tp, class _Alloc>
  44. void 
  45. __vector__<_Tp, _Alloc>::reserve(size_type __n) {
  46.   if (capacity() < __n) {
  47.     const size_type __old_size = size();
  48.     pointer __tmp;
  49.     if (this->_M_start) {
  50.       __tmp = _M_allocate_and_copy(__n, this->_M_start, this->_M_finish);
  51.       _M_clear();
  52.     } else {
  53.       __tmp = this->_M_end_of_storage.allocate(__n);
  54.     }
  55.     _M_set(__tmp, __tmp + __old_size, __tmp + __n);
  56.   }
  57. }
  58.  
  59. template <class _Tp, class _Alloc>
  60. void 
  61. __vector__<_Tp, _Alloc>::_M_fill_insert(
  62.                     iterator __position, 
  63.                     size_type __n, const _Tp& __x) {
  64.   if (__n != 0) {
  65.     if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n) {
  66.       _Tp __x_copy = __x;
  67.       const size_type __elems_after = this->_M_finish - __position;
  68.       pointer __old_finish = this->_M_finish;
  69.       if (__elems_after > __n) {
  70.         __uninitialized_copy(this->_M_finish - __n, this->_M_finish, this->_M_finish, _IsPODType());
  71.         this->_M_finish += __n;
  72.         __copy_backward_ptrs(__position, __old_finish - __n, __old_finish, _TrivialAss());
  73.         _STLP_STD::fill(__position, __position + __n, __x_copy);
  74.       }
  75.       else {
  76.         uninitialized_fill_n(this->_M_finish, __n - __elems_after, __x_copy);
  77.         this->_M_finish += __n - __elems_after;
  78.         __uninitialized_copy(__position, __old_finish, this->_M_finish, _IsPODType());
  79.         this->_M_finish += __elems_after;
  80.         _STLP_STD::fill(__position, __old_finish, __x_copy);
  81.       }
  82.     }
  83.     else 
  84.       _M_insert_overflow(__position, __x, _IsPODType(), __n);
  85.   }
  86. }
  87.  
  88. template <class _Tp, class _Alloc>
  89. __vector__<_Tp,_Alloc>& 
  90. __vector__<_Tp,_Alloc>::operator=(const __vector__<_Tp, _Alloc>& __x)
  91. {
  92.   if (&__x != this) {
  93.     const size_type __xlen = __x.size();
  94.     if (__xlen > capacity()) {
  95.       pointer __tmp = _M_allocate_and_copy(__xlen, (const_pointer)__x._M_start+0, (const_pointer)__x._M_finish+0);
  96.       _M_clear();
  97.       this->_M_start = __tmp;
  98.       this->_M_end_of_storage._M_data = this->_M_start + __xlen;
  99.     }
  100.     else if (size() >= __xlen) {
  101.       pointer __i = __copy_ptrs((const_pointer)__x._M_start+0, (const_pointer)__x._M_finish+0, (pointer)this->_M_start, _TrivialAss());
  102.       _Destroy(__i, this->_M_finish);
  103.     }
  104.     else {
  105.       __copy_ptrs((const_pointer)__x._M_start, (const_pointer)__x._M_start + size(), (pointer)this->_M_start, _TrivialAss());
  106.       __uninitialized_copy((const_pointer)__x._M_start + size(), (const_pointer)__x._M_finish+0, this->_M_finish, _IsPODType());
  107.     }
  108.     this->_M_finish = this->_M_start + __xlen;
  109.   }
  110.   return *this;
  111. }
  112.  
  113. template <class _Tp, class _Alloc>
  114. void __vector__<_Tp, _Alloc>::_M_fill_assign(size_t __n, const _Tp& __val) {
  115.   if (__n > capacity()) {
  116.     __vector__<_Tp, _Alloc> __tmp(__n, __val, get_allocator());
  117.     __tmp.swap(*this);
  118.   }
  119.   else if (__n > size()) {
  120.     fill(begin(), end(), __val);
  121.     this->_M_finish = _STLP_STD::uninitialized_fill_n(this->_M_finish, __n - size(), __val);
  122.   }
  123.   else
  124.     erase(_STLP_STD::fill_n(begin(), __n, __val), end());
  125. }
  126.  
  127. _STLP_END_NAMESPACE
  128.  
  129. # undef size_type
  130. # undef iterator
  131. # undef vector
  132.  
  133. #endif /*  _STLP_VECTOR_C */
  134.  
  135.       // Local Variables:
  136.     // mode:C++
  137.     // End:
  138.