root = other.root;
#ifdef WALKABLE
- BASELIST::shallowCopy( other );
+ BASELIST::head = other.BASELIST::head;
+ BASELIST::tail = other.BASELIST::tail;
+ BASELIST::listLen = other.BASELIST::listLen;
#else
head = other.head;
tail = other.tail;
root = other.root;
#ifdef WALKABLE
- BASELIST::shallowCopy( other );
+ BASELIST::head = other.BASELIST::head;
+ BASELIST::tail = other.BASELIST::tail;
+ BASELIST::listLen = other.BASELIST::listLen;
#else
head = other.head;
tail = other.tail;
/* Shallow copy. */
SVector( const SVector &v );
- /* Shallow copy. */
- SVector(STabHead *head);
-
/**
* \brief Free all memory used by the vector.
*
/* Perform a shallow copy of another vector. */
SVector &operator=( const SVector &v );
- /* Perform a shallow copy of another vector by the header. */
- SVector &operator=( STabHead *head );
-
/*@{*/
/**
void downResizeDup(long len);
};
-#if 0
-/* Create a vector with an intial number of elements and size. */
-template <class T, class Resize> SVector<T, Resize>::
- SVector( long size, long allocLen )
-{
- /* Allocate the space if we are given a positive allocLen. */
- if ( allocLen > 0 ) {
- /* Allocate the data needed. */
- STabHead *head = (STabHead*) malloc( sizeof(STabHead) +
- sizeof(T) * allocLen );
- if ( head == 0 )
- throw std::bad_alloc();
-
- /* Set up the header and save the data pointer. */
- head->refCount = 1;
- head->allocLen = allocLen;
- head->tabLen = 0;
- BaseTable::data = (T*) (head + 1);
- }
-
- /* Grow to the size specified. If we did not have enough space
- * allocated that is ok. Table will be grown to the right size. */
- setAsNew( size );
-}
-#endif
-
/**
* \brief Perform a shallow copy of the vector.
*
}
}
-#if 0
-/**
- * \brief Perform a shallow copy of the vector from only the header.
- *
- * Takes a reference to the contents specified by the header.
- */
-template <class T, class Resize> SVector<T, Resize>::
- SVector(STabHead *head)
-{
- /* Take a reference to other, if the header is no-null. */
- if ( head == 0 )
- BaseTable::data = 0;
- else {
- head->refCount += 1;
- BaseTable::data = (T*) (head + 1);
- }
-}
-#endif
-
-
/**
* \brief Shallow copy another vector into this vector.
*
return *this;
}
-/**
- * \brief Shallow copy another vector into this vector from only the header.
- *
- * Takes a reference to the other header vector. The contents of this vector
- * are first emptied.
- *
- * \returns A reference to this.
- */
-template <class T, class Resize> SVector<T, Resize> &
- SVector<T, Resize>::operator=( STabHead *head )
-{
- /* First clean out the current contents. */
- empty();
-
- /* Take a reference to other, if the header is no-null. */
- if ( head == 0 )
- BaseTable::data = 0;
- else {
- head->refCount += 1;
- BaseTable::data = (T*) (head + 1);
- }
- return *this;
-}
-
/* Init a vector iterator with just a vector. */
template <class T, class Resize> SVector<T, Resize>::
Iter::Iter( const SVector &v )
/* Abandon the contents of the vector without deleteing. */
void abandon();
- /* Performs a shallow copy of another vector into this vector. If this
- * vector is non-empty then its contents are lost (not freed). */
- void shallowCopy( const Vector &v );
+ /* Transfers the elements of another vector into this vector. First emptys
+ * the current vector. */
+ void transfer( Vector &v );
/* Perform a deep copy of another vector into this vector. */
Vector &operator=( const Vector &v );
void downResize(long len);
};
-#if 0
-/* Create a vector with an intial number of elements and size. */
-template<class T, class Resize> Vector<T, Resize>::
- Vector( long size, long allocLen )
-{
- /* Allocate the space if we are given a positive allocLen. */
- BaseTable::allocLen = allocLen;
- if ( allocLen > 0 ) {
- BaseTable::data = (T*) malloc(sizeof(T) * BaseTable::allocLen);
- if ( BaseTable::data == 0 )
- throw std::bad_alloc();
- }
-
- /* Grow to the size specified. If we did not have enough space
- * allocated that is ok. Table will be grown to right size. */
- setAsNew( size );
-}
-#endif
-
/* Init a vector iterator with just a vector. */
template <class T, class Resize> Vector<T, Resize>::Iter::Iter( const Vector &v )
{
}
/**
- * \brief Shallow copy another vector into this vector.
+ * \brief Transfer the contents of another vector into this vector.
*
- * The dynamic array of the other vector is copied into this vector by
- * reference. If this vector is non-empty then its contents are lost. This
- * routine must be used with care. After a shallow copy one vector should
- * abandon its contents to prevent both destructors from attempting to free
- * the common array.
+ * The dynamic array of the other vector is moved into this vector by
+ * reference. If this vector is non-empty then its contents are first deleted.
+ * Afterward the other vector will be empty.
*/
template<class T, class Resize> void Vector<T, Resize>::
- shallowCopy( const Vector &v )
+ transfer( Vector &v )
{
+ empty();
+
BaseTable::data = v.data;
BaseTable::tabLen = v.tabLen;
BaseTable::allocLen = v.allocLen;
+
+ v.abandon();
}
/**
}
/* Save off the range we just created into the state's range. */
- state->outRange.shallowCopy( outRange );
- outRange.abandon();
+ state->outRange.transfer( outRange );
/* Store the default. */
state->defTrans = defTrans;