#if !defined(_INLINE)
static char cvsid[] = "@(#)$Id: RangedContainer.cpp,v 1.4 1999/05/22 13:00:34 philogelos Exp $";
static char debugFileId[] = __FILE__;
#endif
#include "containers/IndexPosition.hpp"
#include "containers/RangedContainer.hpp"
#include "iter/enumerations/RangedContainerEnumeration.hpp"
#include "Debug.hpp"
#include "OGuard.hpp"
#include "algorithms/enumerations/EnumerationAlgorithms.hpp"
boolean RangedContainer::isValidIndex( const Index anIndex ) const
{
return ( ( getLowBound() <= anIndex ) &&
( anIndex < getHighBound() ) );
}
RangedContainerEnumeration *RangedContainer::getRangedEnumeration() const
{
return new RangedContainerEnumeration( ( RangedContainer * ) this );
}
PositionEnumeration *RangedContainer::getEnumeration() const
{
return getMutableEnumeration();
}
MutablePositionEnumeration *RangedContainer::getMutableEnumeration() const
{
return getRangedEnumeration();
}
Index RangedContainer::findIndex( const Top *anObject ) const
{
preC_( contains( anObject ) );
return( EAlg::get() ->
findIndex( getEnumeration(), anObject,
getCardinality() ) );
}
Index RangedContainer::getCardinality() const
{
return ( getHighBound() - getLowBound() );
}
IndexPosition *RangedContainer::getFirstPosition() const
{
return new IndexPosition( getLowBound(),
( IndexableContainer * ) this );
}
IndexPosition *RangedContainer::getLastPosition() const
{
return new IndexPosition( getHighBound() - 1,
( IndexableContainer * ) this );
}
MutablePosition *RangedContainer::getAlwaysFirstPosition() const
{
return new RangedContainer::RContainerFirstPosition( this );
}
MutablePosition *RangedContainer::getAlwaysLastPosition() const
{
return new RangedContainer::RContainerLastPosition( this );
}
RangedContainer::BeyondRange::BeyondRange( String aMessage, const Top *const aSource ) :
InvalidIndex( aMessage, aSource ),
Exception( aMessage, aSource )
{}
String RangedContainer::BeyondRange::getDescription() const
{
return InvalidIndex::getDescription() +
String( ": Index is beyond the valid range", false );
}
String RangedContainer::BeyondRange::getClassName() const
{
return "BeyondRange";
}
RangedContainer::AfterLast::AfterLast( String aMessage, const Top *const aSource ) :
BeyondRange( aMessage, aSource ),
Exception( aMessage, aSource )
{}
String RangedContainer::AfterLast::getDescription() const
{
return BeyondRange::getDescription() +
String( ": index is after the last valid index", false );
}
String RangedContainer::AfterLast::getClassName() const
{
return "AfterLast";
}
RangedContainer::BeforeFirst::BeforeFirst( String aMessage, const Top *const aSource ) :
BeyondRange( aMessage, aSource ),
Exception( aMessage, aSource )
{}
String RangedContainer::BeforeFirst::getDescription() const
{
return BeyondRange::getDescription() +
String( ": index is before the first valid index", false );
}
String RangedContainer::BeforeFirst::getClassName() const
{
return "BeforeFirst";
}
RangedContainer::RContainerFirstPosition::RContainerFirstPosition( const RangedContainer *aContainer ) :
MutablePositionAdapter( ( MutableContainer * ) aContainer )
{}
RangedContainer::RContainerFirstPosition::~RContainerFirstPosition()
{}
Top *RangedContainer::RContainerFirstPosition::setValue( Top *aNewValue )
{
preC_( isValid() );
OGuard _container( getContainer(), this );
return DCAST( getContainer(), RangedContainer ) ->
setAt( DCAST( getContainer(), RangedContainer ) -> getLowBound(),
aNewValue );
}
boolean RangedContainer::RContainerFirstPosition::isValid() const
{
return( ( dynamic_cast< RangedContainer * >( getContainer() ) ) -> isEmpty() );
}
Top *RangedContainer::RContainerFirstPosition::getValue() const
{
preC_( isValid() );
OGuard _container( getContainer(), this );
return ( dynamic_cast< RangedContainer * >( getContainer() ) )
-> getAt( ( dynamic_cast< RangedContainer * >( getContainer() ) ) -> getLowBound() );
}
RangedContainer::RContainerLastPosition::RContainerLastPosition( const RangedContainer *aContainer ) :
MutablePositionAdapter( ( MutableContainer * ) aContainer )
{}
RangedContainer::RContainerLastPosition::~RContainerLastPosition()
{}
Top *RangedContainer::RContainerLastPosition::setValue( Top *aNewValue )
{
preC_( isValid() );
OGuard _container( getContainer(), this );
return ( dynamic_cast< RangedContainer * >( getContainer() ) )
-> setAt( ( dynamic_cast< RangedContainer * >( getContainer() ) ) -> getHighBound(),
aNewValue );
}
boolean RangedContainer::RContainerLastPosition::isValid() const
{
return( ( dynamic_cast< RangedContainer * >( getContainer() ) ) -> isEmpty() );
}
Top *RangedContainer::RContainerLastPosition::getValue() const
{
preC_( isValid() );
OGuard _container( getContainer(), this );
return ( dynamic_cast< RangedContainer * >( getContainer() ) )
-> getAt( ( dynamic_cast< RangedContainer * >( getContainer() ) ) -> getHighBound() );
}
#if defined(_INLINE)
#include "../src/Debug.ipp"
#endif