Logo Search packages:      
Sourcecode: ragel version File versions

template<class T, class Resize>
Vector< T, Resize >::Vector ( const Vector< T, Resize > &  v  )  [inline]

Perform a deep copy of the vector.

The contents of the other vector are copied into this vector. This vector gets the same allocation size as the other vector. All items are copied using the element's copy constructor.

Definition at line 97 of file vector.h.

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

{
      BaseTable::tabLen = v.tabLen;
      BaseTable::allocLen = v.allocLen;

      if ( BaseTable::allocLen > 0 ) {
            /* Allocate needed space. */
            BaseTable::data = (T*) malloc(sizeof(T) * BaseTable::allocLen);
            if ( BaseTable::data == 0 )
                  throw std::bad_alloc();

            /* If there are any items in the src data, copy them in. */
            T *dst = BaseTable::data, *src = v.data;
            for (long pos = 0; pos < BaseTable::tabLen; pos++, dst++, src++ )
                  new(dst) T(*src);
      }
      else {
            /* Nothing allocated. */
            BaseTable::data = 0;
      }
}


Generated by  Doxygen 1.6.0   Back to index