#ifndef __SWAP_ARRAY_H__ #define __SWAP_ARRAY_H__ #include #ifndef TOOLS //#include "../../memory/srrmemory.h" #endif #define ASSSERT(s) rTuneAssert(s) template class SwapArray { public: ///////////////////////////////////////// // Constructors/Destructors ///////////////////////////////////////// ~SwapArray() { Clear(); } SwapArray() : mUseSize(0), mpData(NULL) { } SwapArray( int iSize ) : mUseSize(0), mpData(NULL) { Allocate( iSize ); } ///////////////////////////////////////// // Main Methods ///////////////////////////////////////// void Remove( int iIndex ) { //A pointer safe swap-out ASSSERT( (iIndex=mUseSize)&&(iIndex=mUseSize)&&(iIndex -1)); return mpData[iIndex]; } const T& operator[]( int iIndex )const { ASSSERT( (iIndex < mUseSize) && (iIndex > -1)); return mpData[iIndex]; } void Reserve( int iCount ) { // UseSize is used during the // unallocated state to count the reservations ASSSERT( !IsSetUp() ); mUseSize += iCount; } void Allocate() { ASSSERT( !IsSetUp() ); if( mUseSize == 0 ) { mSize = mUseSize; mpData = NULL; } else { mSize = mUseSize; mpData = new T[mSize]; ASSSERT(mSize>0); ASSSERT(mpData!=NULL); mUseSize = 0; } } void Allocate( int iSize ) { ASSSERT( mUseSize == 0 ); //TODO: wha? if( !IsSetUp() ) iSize += mUseSize; Clear(); mSize = iSize; mpData = new T[mSize]; ASSSERT(mSize>0); ASSSERT(mpData!=NULL); } void Clear() { if( mpData != NULL ) { delete[] mpData; } mpData = NULL; mUseSize = 0; } bool IsSetUp() { if( mpData == NULL ) return false; else return true; } ///////////////////////////////////////// // Data ///////////////////////////////////////// int mSize; int mUseSize; T* mpData; T mSwapT; protected: private: ///////////////////////////////////////// // Currently Disallowed Functions // -Not implemented // -Not accessible // -Use will error at Compile ///////////////////////////////////////// SwapArray( const SwapArray& iSource ); SwapArray& operator=( const SwapArray& iSource ); }; template class NodeSwapArray { public: ///////////////////////////////////////// // Constructors/Destructors ///////////////////////////////////////// ~NodeSwapArray() { Clear(); } NodeSwapArray() : mUseSize(0), mpData(NULL) { } NodeSwapArray( int iSize ) : mUseSize(0), mpData(NULL) { Allocate( iSize ); } ///////////////////////////////////////// // Main Methods ///////////////////////////////////////// void Remove( int iIndex ) { //A pointer safe swap-out ASSSERT( (iIndex=mUseSize)&&(iIndex=mUseSize)&&(iIndex=mSize) return false; mpData[mUseSize] = irVal; mUseSize++; return true; } T& operator[]( int iIndex ) { ASSSERT( (iIndex < mUseSize) && (iIndex > -1)); return mpData[iIndex]; } const T& operator[]( int iIndex )const { ASSSERT( (iIndex < mUseSize) && (iIndex > -1)); return mpData[iIndex]; } void Reserve( int iCount ) { // UseSize is used during the // unallocated state to count the reservations ASSSERT( !IsSetUp() ); mUseSize += iCount; } void Allocate() { ASSSERT( !IsSetUp() ); if( mUseSize == 0 ) { mSize = mUseSize; mpData = NULL; } else { mSize = mUseSize; mpData = new T[mSize]; ASSSERT(mSize>0); ASSSERT(mpData!=NULL); mUseSize = 0; } } void Allocate( int iSize ) { ASSSERT( mUseSize == 0 ); //TODO: wha? if( !IsSetUp() ) iSize += mUseSize; Clear(); mSize = iSize; mpData = new T[mSize]; ASSSERT(mSize>0); ASSSERT(mpData!=NULL); } void Clear() { if( mpData != NULL ) { delete[] mpData; } mpData = NULL; mUseSize = 0; } bool IsSetUp() { if( mpData == NULL ) return false; else return true; } ///////////////////////////////////////// // Data ///////////////////////////////////////// int mSize; int mUseSize; T* mpData; T mSwapT; protected: private: ///////////////////////////////////////// // Currently Disallowed Functions // -Not implemented // -Not accessible // -Use will error at Compile ///////////////////////////////////////// NodeSwapArray( const NodeSwapArray& iSource ); NodeSwapArray& operator=( const NodeSwapArray& iSource ); }; #endif