Logo Search packages:      
Sourcecode: ragel version File versions

template<class T, class Resize>
void Vector< T, Resize >::insert ( long  pos,
const T *  val,
long  len 
) [inline]

Insert len elements at position pos.

Elements in the vector from pos onward are shifted len spaces to the right. The copy constructor is used to place the elements into this vector. If pos is greater than the length of the vector then undefined behaviour results. If pos is negative then it is treated as an offset relative to the length of the vector.

Definition at line 531 of file vector.h.

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

{
      /* If we are given a negative position to insert at then
       * treat it as a position relative to the length. */
      if ( pos < 0 )
            pos = BaseTable::tabLen + pos;
      
      /* Calculate the new length. */
      long newLen = BaseTable::tabLen + len;

      /* Up resize, we are growing. */
      upResize( newLen );

      /* Shift over data at insert spot if needed. */
      if ( len > 0 && pos < BaseTable::tabLen ) {
            memmove(BaseTable::data + pos + len, BaseTable::data + pos,
                        sizeof(T)*(BaseTable::tabLen-pos));
      }

      /* Copy data in element by element. */
      T *dst = BaseTable::data + pos;
      const T *src = val;
      for ( long i = 0; i < len; i++, dst++, src++ )
            new(dst) T(*src);

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


Generated by  Doxygen 1.6.0   Back to index