00001 #ifndef __J2K__ArrayBased_Stack_HPP__
00002 #define __J2K__ArrayBased_Stack_HPP__
00003
00004 #include <j2k/Fred/Basic.hpp>
00005
00006 #define LIST_SIZE 100
00007
00008 class ArrayStack {
00009 public:
00010
00011 inline ArrayStack()
00012 : size( LIST_SIZE ), top( 0 )
00013 {
00014 listarray = new Elem[ LIST_SIZE ];
00015 }
00016
00017 inline ArrayStack( unsigned long sz )
00018 : size( LIST_SIZE ), top( 0 )
00019 {
00020 listarray = new Elem[sz];
00021 }
00022
00023 inline virtual ~ArrayStack()
00024 {
00025 delete [] listarray;
00026 }
00027
00028 inline void clear()
00029 {
00030 top = 0;
00031 memset( listarray, 0, ( sizeof( Elem ) * LIST_SIZE ) );
00032 }
00033
00034 inline void push( const Elem item )
00035 {
00036 assert(top < size);
00037 listarray[top] = item;
00038 top++;
00039 }
00040
00041 inline Elem pop()
00042 {
00043 assert( !isEmpty() );
00044 --top;
00045 return listarray[ top ];
00046 }
00047
00048 inline Elem topValue() const
00049 {
00050 assert( !isEmpty() );
00051 return listarray[ top-1 ];
00052 }
00053
00054 inline BOOL isEmpty() const
00055 {
00056 return (top == 0);
00057 }
00058
00059 inline BOOL isFilled() const
00060 {
00061 return (top != 0);
00062 }
00063
00064 private:
00065 unsigned long size;
00066 unsigned long top;
00067 Elem *listarray;
00068 };
00069
00070 #endif // End of ArrayStack.hpp