Logo Search packages:      
Sourcecode: ragel version File versions

template<class T, class Resize>
void Vector< T, Resize >::setAsDup ( const T &  item,
long  len 
) [inline]

Set the vector to len copies of item.

The vector becomes len elements in length. Destructors are called on any existing elements in the vector. The element's copy constructor is used to copy the item into the vector.

Definition at line 205 of file vector.h.

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

{
      /* Call All destructors. */
      T *pos = BaseTable::data;
      for ( long i = 0; i < BaseTable::tabLen; pos++, i++ )
            pos->~T();

      /* Adjust the allocated length. */
      if ( len < BaseTable::tabLen )
            downResize( len );
      else if ( len > BaseTable::tabLen )
            upResize( len );

      /* Set the new data length to exactly len. */
      BaseTable::tabLen = len;      
      
      /* Copy item in one spot at a time. */
      T *dst = BaseTable::data;
      for ( long i = 0; i < len; i++, dst++ )
            new(dst) T(item);
}


Generated by  Doxygen 1.6.0   Back to index