Logo Search packages:      
Sourcecode: ragel version File versions

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

Replace len elements at position pos.

If there are existing elements at the positions to be replaced, then destructors are called before the space is used. Copy constructors are used to place the elements into the vector. It is allowable for the pos and length to specify a replacement that overwrites existing elements and creates new ones. 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 288 of file vector.h.

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

      long endPos, i;
      T *item;

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

      /* The end is the one past the last item that we want
       * to write to. */
      endPos = pos + len;

      /* Make sure we have enough space. */
      if ( endPos > BaseTable::tabLen ) {
            upResize( endPos );

            /* Delete any objects we need to delete. */
            item = BaseTable::data + pos;
            for ( i = pos; i < BaseTable::tabLen; i++, item++ )
            /* We are extending the vector, set the new data length. */
            BaseTable::tabLen = endPos;
      else {
            /* Delete any objects we need to delete. */
            item = BaseTable::data + pos;
            for ( i = pos; i < endPos; i++, item++ )

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

Generated by  Doxygen 1.6.0   Back to index