mud++0.26/etc/
mud++0.26/etc/guilds/
mud++0.26/log/
mud++0.26/mudC/
mud++0.26/player/
mud++0.26/src/unix/
/*
....[@@@..[@@@..............[@.................. 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-list@mailhost.net
------------------------------------------------------------------------------
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 * >

// Guaranteed to work with
// < struct T >
// < struct T * >
// < class T * >
// If you will use just < class T > you are on your own
// - Artur

#include "erratum.h"


template < class T >
void Array< T >::remove( int pos )
{
	if ( pos >= count )
		Error::outOfBounds();
	memmove( &table[pos], &table[pos+1], count - pos );
	count--;
}

template < class T >
void Array< T >::destroyList( )
{
	// nothing for now
	Error::unsupportedFunction();
}



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;
}