コード例 #1
0
void APSizedArrayBase<_ElementType>::insert_all(
  const tAPArrayBase & array,
  uint32_t             pos
  )
  {
  APARRAY_BOUNDS_LENGTH(pos);

  uint32_t count      = array.get_length();
  uint32_t new_length = this->m_count + count;

  if (this->m_size < new_length)  // Needs more space
    {
    _ElementType ** old_array_pp = this->m_array_p;

    this->m_size    = AMemory::request_pointer_count(new_length);
    this->m_array_p = tAPArrayBase::alloc_array(this->m_size);
    ::memcpy(this->m_array_p, old_array_pp, pos * sizeof(_ElementType *));
    ::memcpy(this->m_array_p + pos + count, old_array_pp + pos, (this->m_count - pos) * sizeof(_ElementType *));
    tAPArrayBase::free_array(old_array_pp);
    }
  else  // enough size in existing array
    {
    ::memmove(this->m_array_p + pos + count, this->m_array_p + pos, (this->m_count - pos) * sizeof(_ElementType *));
    }

  this->m_count = new_length;
  ::memcpy(this->m_array_p + pos, array.get_array(), count * sizeof(_ElementType *));
  }
コード例 #2
0
void APSizedArrayBase<_ElementType>::insert(
  const _ElementType & elem,
  uint32_t             pos // = 0
  )
  {
  APARRAY_BOUNDS_LENGTH(pos);

  if (this->m_size < this->m_count + 1u)  // Needs more space
    {
    _ElementType ** old_array_p = this->m_array_p;

    this->m_size    = AMemory::request_pointer_count_expand(this->m_count + 1u);
    this->m_array_p = tAPArrayBase::alloc_array(this->m_size);
    ::memcpy(this->m_array_p, old_array_p, pos * sizeof(_ElementType *));
    ::memcpy(this->m_array_p + pos + 1u, old_array_p + pos, (this->m_count - pos) * sizeof(_ElementType *));
    tAPArrayBase::free_array(old_array_p);
    }
  else  // enough size in existing array
    {
    ::memmove(this->m_array_p + pos + 1u, this->m_array_p + pos, (this->m_count - pos) * sizeof(_ElementType *));
    }

  this->m_array_p[pos] = const_cast<_ElementType *>(&elem);  // insert element
  this->m_count++;
  }
コード例 #3
0
void APCompactArrayBase<_ElementType>::free_all_last(uint32_t elem_count)
  {
  if (elem_count)
    {
    APARRAY_BOUNDS_LENGTH(elem_count);

    // Realloc array
    _ElementType ** old_array_p = this->m_array_p;
    _ElementType ** array_end_p = old_array_p + this->m_count;
    _ElementType ** array_p     = array_end_p - elem_count;
    uint32_t        length      = this->m_count - elem_count;

    if (length)
      {
      this->m_array_p = tAPArrayBase::alloc_array(length);

      ::memcpy(this->m_array_p, old_array_p, length * sizeof(_ElementType *));
      }
    else
      {
      this->m_array_p = nullptr;
      }

    this->m_count -= elem_count;

    // Then free elements
    for (; array_p < array_end_p; array_p++)
      {
      delete (*array_p);
      }

    tAPArrayBase::free_array(old_array_p);
    }
  }
コード例 #4
0
inline void APSizedArrayBase<_ElementType>::free_all_last(uint32_t elem_count)
  {
  if (elem_count)
    {
    APARRAY_BOUNDS_LENGTH(elem_count);

    _ElementType ** array_end_p = this->m_array_p + this->m_count;
    _ElementType ** array_p     = array_end_p - elem_count;

    // Remove elements first
    this->m_count -= elem_count;

    // Then delete them
    for (; array_p < array_end_p; array_p++)
      {
      delete (*array_p);
      }
    }
  }
コード例 #5
0
void APSizedArrayBase<_ElementType>::insert(
  const _ElementType & elem,
  uint32_t             pos,
  uint32_t             count
  )
  {
  APARRAY_BOUNDS_LENGTH(pos);

  uint32_t new_length = this->m_count + count;

  if (this->m_size < new_length)  // Needs more space
    {
    _ElementType ** old_array_pp = this->m_array_p;

    this->m_size    = AMemory::request_pointer_count(new_length);
    this->m_array_p = tAPArrayBase::alloc_array(this->m_size);
    ::memcpy(this->m_array_p, old_array_pp, pos * sizeof(_ElementType *));
    ::memcpy(this->m_array_p + pos + count, old_array_pp + pos, (this->m_count - pos) * sizeof(_ElementType *));
    tAPArrayBase::free_array(old_array_pp);
    }
  else  // enough size in existing array
    {
    ::memmove(this->m_array_p + pos + count, this->m_array_p + pos, (this->m_count - pos) * sizeof(_ElementType *));
    }

  this->m_count = new_length;

  _ElementType *  elem_p       = const_cast<_ElementType *>(&elem);
  _ElementType ** array_pp     = this->m_array_p + pos;
  _ElementType ** array_end_pp = array_pp + count;

  for (; array_pp < array_end_pp; array_pp++)
    {
    *array_pp = elem_p;
    }
  }
コード例 #6
0
inline void APSizedArrayBase<_ElementType>::remove_all_last(uint32_t elem_count)
  {
  APARRAY_BOUNDS_LENGTH(elem_count);

  this->m_count -= elem_count;
  }