00001 00006 #ifndef LIST_H_INCLUDED 00007 #define LIST_H_INCLUDED 00008 00009 00010 extern const unsigned int MarkAlive; 00011 extern const unsigned int MarkDead; 00012 00013 #include <cstdlib> 00014 00015 typedef enum { 00016 ListOk, ListNoMemory, ListInvalidRange, ListInvalidPos 00017 } ListStatus; 00018 00019 typedef struct _Node { 00020 unsigned int signature; 00021 void * content; 00022 struct _Node * next; 00023 struct _Node * prev; 00024 } Node; 00025 00026 typedef Node * Position; 00027 00028 typedef struct _List { 00029 unsigned int signature; 00030 00032 Position first; 00034 Position last; 00035 } * List; 00036 00043 void advanceListPos(List l, Position &pos, int delta); 00044 00051 inline 00052 bool isValidList(List l) 00053 { return ( l != NULL && l->signature == MarkAlive ); } 00054 00055 00061 inline 00062 bool isListEmpty(List l) 00063 { return ( isValidList( l ) && l->first == NULL ); } 00064 00068 List createList(); 00069 00073 void destroyList(List l); 00074 00080 void deleteListRange(List l, Position beg, Position end); 00081 00087 Position deleteListElement(List l, Position pos); 00088 00089 00095 ListStatus getListStatus(); 00096 00104 bool isValidPos(List l, Position p); 00105 00111 inline 00112 Position getListLastPos(List l) 00113 { return ( isValidList( l ) ? l->last : NULL ); } 00114 00120 inline 00121 Position getListFirstPos(List l) 00122 { return ( isValidList( l ) ? l->first : NULL ); } 00123 00130 Position getListNextPos(List l, Position pos); 00131 00138 Position getListPreviousPos(List l, Position pos); 00139 00146 void * getListPosContent(List l, Position p); 00147 00154 void setListPosContent(List l, Position p, void * data); 00155 00162 Position insertListElement(List l, Position pos, void * data); 00163 00164 #endif // LIST_H_INCLUDED