Logo Search packages:      
Sourcecode: ragel version File versions

template<class T, class Resize>
void Vector< T, Resize >::setAsNew ( long  len  )  [inline]

Set the vector to exactly len new items.

The vector becomes len elements in length. Destructors are called on any existing elements in the vector. Default constructors are used to init the new items.

Definition at line 243 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;      
      
      /* Create items using default constructor. */
      T *dst = BaseTable::data;
      for ( long i = 0; i < len; i++, dst++ )
            new(dst) T();
}


Generated by  Doxygen 1.6.0   Back to index