mud++0.35/etc/
mud++0.35/etc/guilds/
mud++0.35/help/propert/
mud++0.35/mudC/
mud++0.35/player/
mud++0.35/src/interface/
mud++0.35/src/os/cygwin32/
mud++0.35/src/os/win32/
mud++0.35/src/os/win32/bcppbuilder/
mud++0.35/src/osaddon/
mud++0.35/src/util/
/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project.  All 
................................................ contributions are welcome. 
....Copyright(C).1995.Melvin.Smith.............. Enjoy. 
------------------------------------------------------------------------------
Melvin Smith (aka Fusion)         msmith@hom.net
MUD++ development mailing list    mudpp@van.ml.org
------------------------------------------------------------------------------
array.cc
*/

// TEMPLATE FILE

// Growable array class
// It is different from LList and HashTable - they use pointers to objects
// this class use Objects themselves
// Example: to get functionality of LList< NPC > you have to declare
// Array< NPC * >

template < class T >
void Array< T >::remove( int pos )
{
#ifdef DEBUG_ARRAY
	if ( pos >= count )
		Error::dumpf("Array index %d out of bounds(count = %d)", pos, count);
#endif
	memmove( &table[pos], &table[pos+1], count - pos );
	count--;
}

template < class T >
void Array< T >::destroyList( )
{
	// nothing for now
	Error::dump("Usupported function called: Array::destroyList");
}



template < class T >
void Array< T >::insert( int pos, const T & obj )
{
	count++;
	ensureCapacity();
	memmove( &table[pos+1], &table[pos], count - pos );
	table[pos] = obj;
}

template < class T >
void Array< T >::trim()
{
	if (count == size)
		return;

	T * ntable = new T[count];
	memcpy( ntable, table, count * sizeof(T) );
	delete table;
	table = ntable;
	size = count;
}

template < class T >
void Array< T >::grow( int s )
{
	if ( s <= size )
		return;

	T * ntable = new T[s];
	memcpy( ntable, table, count * sizeof(T) );
	delete table;
	table = ntable;
	size = s;
}


template < class T >
int Array< T >::readFrom( StaticInput & inf)
{
	int fsize;
	inf.read( &fsize, sizeof(int) );
	grow(fsize);
	inf.read( table, fsize * sizeof( T ) );
	count = fsize;
	return 0;
}

template < class T >
int Array< T >::writeTo( Output & outf) const
{
	outf.write( &count, sizeof(int) );
	outf.write( table, count * sizeof(T) );
	return 0;
}