00001
00002
00003 #ifndef __J2K__DataType__AList_CPP__
00004 #define __J2K__DataType__AList_CPP__
00005
00006 #include <j2k/DataType/Link/AList.hpp>
00007
00008 #define LIST_SIZE 100
00009
00010 AList::AList()
00011 : msize( LIST_SIZE ), nbList( 0 ), curr( 0 )
00012 {
00013 listarray = new Elem[ LIST_SIZE ];
00014 }
00015
00016 AList::AList( ULONG sz )
00017 : msize( sz ), nbList( 0 ), curr( 0 )
00018 {
00019 listarray = new Elem[ sz ];
00020 }
00021
00022 AList::~AList()
00023 {
00024 delete [] listarray;
00025 }
00026
00027 void AList::clear()
00028 {
00029 nbList = 0;
00030 curr = 0;
00031 }
00032
00033
00034 void AList::insert( Elem item )
00035 {
00036
00037 assert( nbList < msize );
00038 assert( curr <= nbList );
00039
00040 for( ULONG i = nbList; i > curr; i-- )
00041 {
00042 listarray[ i ] = listarray[ i-1 ];
00043 }
00044
00045 listarray[ curr ] = item;
00046 nbList++;
00047 }
00048
00049 void AList::append( Elem item )
00050 {
00051 assert( nbList < msize );
00052 listarray[ nbList ] = item;
00053 nbList++;
00054 }
00055
00056 Elem AList::remove()
00057 {
00058 assert( !isEmpty() );
00059 assert( isInList() );
00060
00061 Elem temp = listarray[curr];
00062
00063 register ULONG i;
00064 for( i = curr; i < nbList-1; i++)
00065 {
00066 listarray[ i ] = listarray[ i + 1 ];
00067 }
00068
00069 nbList--;
00070
00071 return temp;
00072 }
00073
00074 inline void AList::setFirst()
00075 {
00076 curr = 0;
00077 }
00078
00079 inline void AList::prev()
00080 {
00081 if ( curr <= 0 ) return;
00082 curr--;
00083 }
00084
00085 inline void AList::next()
00086 {
00087 if ( curr >= msize-1 ) return;
00088 curr++;
00089 }
00090
00091 inline void AList::setPos( ULONG pos )
00092 {
00093 if ( pos > msize-1 ) return;
00094 curr = pos;
00095 }
00096
00097 inline long AList::getPos()
00098 {
00099 if ( isEmpty() ) return -1;
00100 return curr;
00101 }
00102
00103
00104 inline ULONG AList::length() const
00105 {
00106 return nbList;
00107 }
00108
00109 inline ULONG AList::getMaxSize() const
00110 {
00111 return msize;
00112 }
00113
00114 inline void AList::setValue( Elem item )
00115 {
00116 assert( isInList() );
00117 listarray[ curr ] = item;
00118 }
00119
00120 inline Elem AList::currValue() const
00121 {
00122 assert( isInList() );
00123 return listarray[ curr ];
00124 }
00125
00126 inline BOOL AList::isEmpty() const
00127 {
00128 return ( nbList == 0 && curr == 0 );
00129 }
00130
00131 inline BOOL AList::isInList() const
00132 {
00133 return ( nbList != 0 && curr >= 0 && curr < nbList );
00134 }
00135
00136 long AList::find( Elem item )
00137 {
00138 while( isInList() )
00139 {
00140 if ( listarray[ curr ] == item ) return getPos();
00141 next();
00142 }
00143
00144 return -1;
00145 }
00146
00147 void AList::display() const
00148 {
00149 register ULONG i = 0;
00150
00151 printf( "===========================================\n" );
00152
00153 for( ; i < nbList; i++ ) {
00154 printf( "%d \n ", listarray[i] );
00155 }
00156
00157 printf( "===========================================\n" );
00158 }
00159
00160 #endif // End of AList.cpp