#if !defined(_INLINE)
static char cvsid[] = "@(#)$Id: CArray.cpp,v 1.4 1999/03/03 19:09:40 philogelos Exp $";
static char debugFileId[] = __FILE__;
#endif
#include "containers/arrays/CArray.hpp"
#include "String.hpp"
#include "Debug.hpp"
#include "OGuard.hpp"
#include "LinkManager.hpp"
#include "containers/Empty.hpp"
#include "containers/Singleton.hpp"
#include "containers/MutablePositionEnumeration.hpp"
#include "containers/MutablePosition.hpp"
CArray::CArray( Index aBase, Index aLength )
{
preC_( aLength >= 0 );
base = aBase;
length = aLength;
core = new const Top * [ length ];
}
CArray::~CArray()
{
clearAll();
delete []core;
}
void CArray::clearAll()
{
for( Index i = getLowBound() ; i < getHighBound() ; ++i )
{
if( getAt( i ) != nil )
{
LinkManager::free( this, getAt( i ) );
core[ i - base ] = nil;
}
}
}
String CArray::getClassName() const
{
return "CArray";
}
Index CArray::getLowBound() const
{
return getBase();
}
Index CArray::getHighBound() const
{
return ( getBase() + getLength() );
}
Index CArray::getBase() const
{
return base;
}
Index CArray::getLength() const
{
return length;
}
Top *CArray::getAt( const Index anIndex ) const
{
preC_( isValidIndex( anIndex ) );
return( ( Top * ) core[ anIndex - base ] );
}
Top *CArray::setAt( const Index anIndex, Top *aNewValue )
{
preC_( isValidIndex( anIndex ) );
Top *oldValue = getAt( anIndex );
core[ anIndex - base ] = aNewValue;
LinkManager::move( this, oldValue, aNewValue );
return oldValue;
}
PositionEnumeration *CArray::getEnumeration() const
{
return RangedContainer::getEnumeration();
}
MutablePositionEnumeration *CArray::getMutableEnumeration() const
{
return RangedContainer::getMutableEnumeration();
}
Index CArray::getCardinality() const
{
return RangedContainer::getCardinality();
}
boolean CArray::isValid( const Position *aPosition ) const
{
return IndexableContainer::isValid( aPosition );
}
#if defined( TESTING )
boolean CArray::tester( int ) const
{
CArray *array;
array = new CArray( 0, 4 );
OGuard _( array, this );
array -> setAt( 0, new String( "0" ) );
array -> setAt( 1, new String( "1" ) );
array -> setAt( 2, new Empty() );
array -> setAt( 3, new Singleton( new String( "3" ) ) );
Debug::getLogger() -> logObject( array, &Top::getString );
array -> setAt( 0, new String( "!" ) );
Debug::getLogger() -> logObject( array, &Top::getString );
MutablePositionEnumeration *en = array -> getMutableEnumeration();
int k = 100;
OGuard __( en, this );
while( en -> hasMoreElements() )
{
MutablePosition *pos;
pos = en -> getNextMutablePosition();
OGuard _pos( pos, this );
pos -> setValue( new String( k++, 0x10 ) );
}
Debug::getLogger() -> logObject( array, &Top::getString );
return array -> invariant();
}
#endif
#if defined(_INLINE)
#include "../src/Debug.ipp"
#endif
#if defined(_INLINE)
#include "../src/String.ipp"
#endif