void reserve(size_type _Count)
		{	// determine new minimum length of allocated storage
		if (max_size() < _Count)
			_Xlen();	// result too long
		else if (capacity() < _Count)
			{	// not enough room, reallocate
			pointer _Ptr = this->_Alval.allocate(_Count);

			_TRY_BEGIN
			_Umove(this->_Myfirst, this->_Mylast, _Ptr);
			_CATCH_ALL
			this->_Alval.deallocate(_Ptr, _Count);
			_RERAISE;
			_CATCH_END

			size_type _Size = size();
			if (this->_Myfirst != 0)
				{	// destroy and deallocate old array
				_Destroy(this->_Myfirst, this->_Mylast);
				this->_Alval.deallocate(this->_Myfirst,
					this->_Myend - this->_Myfirst);
				}

			this->_Orphan_all();
			this->_Myend = _Ptr + _Count;
			this->_Mylast = _Ptr + _Size;
			this->_Myfirst = _Ptr;
			}
		}
示例#2
0
文件: STRASC.CPP 项目: hkaiser/TRiAS
// assign a repeated char to a string
string &string :: assign (char ch, size_t n)
{
    if (n == NPOS) _Xlen();
    if (_Grow (n, 1)) {	// copy non-empty string
        memset (m_pPtr, ch, n);
        m_pPtr[m_iLen = n] = '\0';
    }

    return (*this);
}
示例#3
0
void PtrDynArray<T>::_NVMGrow(size_t n, void* const* s, Boolean Trim_)
{
  size_t Os_ = _Ptr == 0 ? 0:_Res;

  if (n == 0)
  {
    if (Trim_)
      _Tidy(1);
  }
  else if (n == Os_ || n == Os_ && !Trim_)
	;
  else if (n == SIZET_MAX)
    _Xlen();
  else
  {
    size_t i, m = _Ptr == 0 && n < _Res ? _Res:n;

    Boolean Active_ = MemMatrix::Matrix().IsNewHandlerActive();
    MemMatrix::Matrix().SetNewHandlerInactive();

#if OVERLOAD_NEW
    void** Np_ = (void**)MemMatrix::Matrix().Allocate(sizeof(void*) * m);
#else
    void** Np_ = new void*[m];
#endif

    if (Np_ == 0)
      MemMatrix::Matrix().NoMemory();

    if (Active_)
      MemMatrix::Matrix().SetNewHandlerActive();

    _Res = m, m = n < _Len ? n:_Len;

    for (i = 0; i < m; ++i)
      Np_[i] = _Ptr[i];

    if (s != 0)
      for (; i < _Res; ++i)
	Np_[i] = *s;

    _Tidy(1), _Ptr = Np_;
  }

  _Len = n;
}
示例#4
0
文件: STRINX.CPP 项目: hkaiser/TRiAS
// insert a substring into a string
string &string :: insert (size_t p0, const string &str, size_t pos, size_t ns)
{
	if (m_iLen < p0 || str.length() < pos) _Xran();
	
size_t n = str.length() - pos;

	if ( n < ns) ns = n;
	if (NPOS - m_iLen <= ns) _Xlen();

	if (0 < ns && _Grow (n = m_iLen + ns)) {
	// insert to make non-empty string
		memmove (m_pPtr + p0 + ns, m_pPtr + p0, m_iLen - p0);
		memcpy (m_pPtr + p0, &str.c_str()[pos], ns);
		m_pPtr[m_iLen = n] = '\0';
	}
	
return (*this);
}
示例#5
0
文件: STRREX.CPP 项目: hkaiser/TRiAS
// replace with a repeated char in a string
string &string :: replace (size_t p0, size_t n0, const string &str, 
			   size_t pos, size_t ns)
{
	if (m_iLen < p0 || str.length() < pos) _Xran();
	
size_t n = str.length() - pos;

	if (n < ns) ns = n;
	if (NPOS - ns <= m_iLen - n0) _Xlen();

size_t nm = m_iLen - n0 - p0;
	
	if (ns < n0)
		memmove (m_pPtr + p0 + ns, m_pPtr + p0 + n0, nm);
	if ((0 < ns || 0 < n0) && _Grow (n = m_iLen + ns - n0)) {
	// replace to make non-empty string
		if (n0 < ns)
			memmove (m_pPtr + p0 + ns, m_pPtr + p0 + n0, nm);
		memcpy (m_pPtr + p0, &str.c_str()[pos], ns);
		m_pPtr[m_iLen = n] = '\0';
	}
	
return (*this);
}