Logo Search packages:      
Sourcecode: ragel version File versions

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

Set the contents of the vector to be len elements exactly.

The vector becomes len elements in length. Destructors are called on any existing elements in the vector. Copy constructors are used to place the new elements in the vector.

Definition at line 165 of file vector.h.

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

{
      /* Call All destructors. */
      long i;
      T *pos = BaseTable::data;
      for ( 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 data in. */
      T *dst = BaseTable::data;
      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