Logo Search packages:      
Sourcecode: ragel version File versions

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

Replace at position pos with len copies of an item.

If there are existing elements at the positions to be replaced, then destructors are called before the space is used. The copy constructor is used to place the element into this 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 354 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;
      for ( long i = 0; i < len; i++, dst++ )
            new(dst) T(val);

Generated by  Doxygen 1.6.0   Back to index