00001 // SList.hpp - Class interface for a Single-Linked list node with freelist 00002 00003 #ifndef __J2K__SList_HPP__ 00004 #define __J2K__SList_HPP__ 00005 00006 #include <j2k/Fred/Standard.hpp> 00007 #include <j2k/DataType/Link/SLink.hpp> 00008 00009 ///////////////////////////////////////////////////////////////////////////// 00010 /// WARNING: curr->next is the OFFICIAL current element ! /// 00011 /// This is to avoid prev(), when adding or removing elements ! /// 00012 ///////////////////////////////////////////////////////////////////////////// 00013 00014 class SList { // Single-Linked list class 00015 public: 00016 SList(); // Default Constructor 00017 virtual ~SList(); // Destructor 00018 00019 void clear(); // Remove all Elems from list 00020 void insert( Elem item ); // Insert Elem at current pos 00021 void append( Elem item ); // Insert Elem at tail of list 00022 Elem remove(); // Remove + return current Elem 00023 void setFirst(); // Set curr to first position 00024 void next(); // Move curr to next position 00025 void prev(); // Move curr to previous pos ( COSTLY ) 00026 ULONG length() const; // Return current length of list 00027 void setPos( ULONG pos ); // Set curr to specified pos 00028 void setValue( Elem item ); // Set current Elem's value 00029 Elem currValue() const; // Return current Elem's value 00030 Elem getValue() const; // Return current Elem's value 00031 BOOL isEmpty() const; // Return TRUE if list is empty 00032 BOOL isInList() const; // TRUE if curr is within list 00033 long find( Elem item ); // Find value (from current pos) 00034 00035 void display(); 00036 00037 long getPos() const; 00038 long size() const; 00039 00040 inline void enqueue( Elem item ); 00041 inline Elem dequeue(); 00042 00043 private: 00044 SLink* head; // Pointer to list header 00045 SLink* tail; // Pointer to last Elem in list 00046 SLink* curr; // Position of "current" Elem 00047 00048 ULONG pos; 00049 ULONG nbElements; // Actual number of items in list 00050 }; 00051 00052 #endif