Logo Search packages:      
Sourcecode: ragel version File versions

template<class T, class Resize>
void Vector< T, Resize >::remove ( long  pos,
long  len 
) [inline]

Remove len elements at position pos.

Destructor is called on all elements removed. Elements to the right of pos are shifted len spaces to the left to take up the free space. If pos is greater than or equal to the length of the vector then undefined behavior results. If pos is negative then it is treated as an offset relative to the length of the vector.

Definition at line 475 of file vector.h.

References Table< T >::data, and Table< T >::tabLen.

{
      long newLen, lenToSlideOver, endPos;
      T *dst, *item;

      /* If we are given a negative position to remove at then
       * treat it as a position relative to the length. */
      if ( pos < 0 )
            pos = BaseTable::tabLen + pos;

      /* The first position after the last item deleted. */
      endPos = pos + len;

      /* The new data length. */
      newLen = BaseTable::tabLen - len;

      /* The place in the data we are deleting at. */
      dst = BaseTable::data + pos;

      /* Call Destructors. */
      item = dst;
      for ( long i = 0; i < len; i += 1, item += 1 )
            item->~T();
      
      /* Shift data over if necessary. */
      lenToSlideOver = BaseTable::tabLen - endPos;    
      if ( len > 0 && lenToSlideOver > 0 )
            memmove(dst, dst + len, sizeof(T)*lenToSlideOver);

      /* Shrink the data if necessary. */
      downResize( newLen );

      /* Set the new data length. */
      BaseTable::tabLen = newLen;
}


Generated by  Doxygen 1.6.0   Back to index