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 #ifdef _MSC_VER
00033 #pragma warning( disable : 4530 )
00034 #pragma warning( disable : 4786 )
00035 #endif
00036
00037 #include "../../grinliz/gldebug.h"
00038
00039
00040 template <class T>
00041 class GlInsideNode
00042 {
00043 public:
00045 GlInsideNode() { next = this; prev = this; data = 0; }
00046
00048 GlInsideNode( T _data ) { next = this; prev = this; data = _data; }
00049
00050 virtual ~GlInsideNode() {}
00051
00052 bool IsSentinel() const { return !data; }
00053 bool InList() const { return !(( next == this ) && ( prev == this )); }
00054
00056 void InsertBefore( GlInsideNode<T>* addMe )
00057 {
00058 GLASSERT( !addMe->IsSentinel() );
00059 addMe->prev = prev;
00060 prev->next = addMe;
00061 prev = addMe;
00062 addMe->next = this;
00063 }
00064
00066 void InsertAfter( GlInsideNode<T>* addMe )
00067 {
00068 GLASSERT( !addMe->IsSentinel() );
00069 addMe->prev = this;
00070 addMe->next = next;
00071 next->prev = addMe;
00072 next = addMe;
00073 }
00074
00076 void Remove()
00077 {
00078 prev->next = next;
00079 next->prev = prev;
00080 prev = next = this;
00081 }
00082
00083
00084
00085
00086 GlInsideNode<T>* next;
00087 GlInsideNode<T>* prev;
00088 T data;
00089 };
00090
00091
00092 template <class T>
00093 class GlInsideNodeIt
00094 {
00095 public:
00096 GlInsideNodeIt( GlInsideNode<T>& _sentinel )
00097 : sentinel( &_sentinel ), current( 0 )
00098 {
00099 GLASSERT( sentinel->IsSentinel() );
00100 }
00101
00102 GlInsideNode<T>* CurrentNode() { return current; }
00103 T CurrentData() { return current->data; }
00104 void SetCurrent( GlInsideNode<T>* c ) { current = c; }
00105
00106 void Begin() { current = sentinel->next; }
00107 void Last() { current = sentinel->prev; }
00108 void Next() { current = current->next; }
00109 void Prev() { current = current->prev; }
00110 bool Done() { return current->IsSentinel(); }
00111
00112 void InsertBefore( GlInsideNode<T>& addMe ) { current->InsertBefore( &addMe ); }
00113 void InsertAfter( GlInsideNode<T>& addMe ) { current->InsertAfter( &addMe ); }
00114
00115 private:
00116 GlInsideNode<T>* sentinel;
00117 GlInsideNode<T>* current;
00118 };
00119
00120
00121 #endif