00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef INPLACE_IMAGENODE_INCLUDED
00030 #define INPLACE_IMAGENODE_INCLUDED
00031
00032 #include "../util/gldebug.h"
00033
00034
00035 template <class T>
00036 class GlInsideNode
00037 {
00038 public:
00040 GlInsideNode() { next = this; prev = this; data = 0; }
00041
00043 GlInsideNode( T _data ) { next = this; prev = this; data = _data; }
00044
00045 virtual ~GlInsideNode() {}
00046
00047 bool IsSentinel() const { return !data; }
00048 bool InList() const { return !(( next == this ) && ( prev == this )); }
00049
00051 void InsertBefore( GlInsideNode<T>* addMe )
00052 {
00053 GLASSERT( !addMe->IsSentinel() );
00054 addMe->prev = prev;
00055 prev->next = addMe;
00056 prev = addMe;
00057 addMe->next = this;
00058 }
00059
00061 void InsertAfter( GlInsideNode<T>* addMe )
00062 {
00063 GLASSERT( !addMe->IsSentinel() );
00064 addMe->prev = this;
00065 addMe->next = next;
00066 next->prev = addMe;
00067 next = addMe;
00068 }
00069
00071 void Remove()
00072 {
00073 prev->next = next;
00074 next->prev = prev;
00075 prev = next = this;
00076 }
00077
00078
00079
00080
00081 GlInsideNode<T>* next;
00082 GlInsideNode<T>* prev;
00083 T data;
00084 };
00085
00086
00087 template <class T>
00088 class GlInsideNodeIt
00089 {
00090 public:
00091 GlInsideNodeIt( GlInsideNode<T>& _sentinel )
00092 : sentinel( &_sentinel ), current( 0 )
00093 {
00094 GLASSERT( sentinel->IsSentinel() );
00095 }
00096
00097 GlInsideNode<T>* CurrentNode() { return current; }
00098 T CurrentData() { return current->data; }
00099 void SetCurrent( GlInsideNode<T>* c ) { current = c; }
00100
00101 void Begin() { current = sentinel->next; }
00102 void Last() { current = sentinel->prev; }
00103 void Next() { current = current->next; }
00104 void Prev() { current = current->prev; }
00105 bool Done() { return current->IsSentinel(); }
00106
00107 void InsertBefore( GlInsideNode<T>& addMe ) { current->InsertBefore( &addMe ); }
00108 void InsertAfter( GlInsideNode<T>& addMe ) { current->InsertAfter( &addMe ); }
00109
00110 private:
00111 GlInsideNode<T>* sentinel;
00112 GlInsideNode<T>* current;
00113 };
00114
00115
00116 #endif