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 #ifndef GRINLIZ_INNER_CIRCLE_INCLUDED
00026 #define GRINLIZ_INNER_CIRCLE_INCLUDED
00027
00028 namespace grinliz
00029 {
00030
00031 template<class T>
00032 class InnerCircle
00033 {
00034 public:
00035 enum Sentinel
00036 {
00037 SENTINEL
00038 };
00039
00040 InnerCircle( Sentinel ) {
00041 next = prev = this;
00042 container = 0;
00043 }
00044
00045 InnerCircle( T* _container ) {
00046 GLASSERT( _container );
00047 this->container = _container;
00048 next = prev = 0;
00049 }
00050
00051 ~InnerCircle() {
00052 if ( !Sentinel() )
00053 Remove();
00054 container = 0;
00055 }
00056
00057 void Add( InnerCircle* addThis )
00058 {
00059 GLASSERT( addThis->next == 0 );
00060 GLASSERT( addThis->prev == 0 );
00061 GLASSERT( addThis->Sentinel() == false );
00062
00063 if ( next )
00064 {
00065 next->prev = addThis;
00066 addThis->next = next;
00067 }
00068 next = addThis;
00069 addThis->prev = this;
00070 }
00071
00072 void Remove() {
00073 GLASSERT( ( prev && next ) || (!prev && !next ) );
00074 GLASSERT( !Sentinel() );
00075 if ( prev ) {
00076 prev->next = next;
00077 next->prev = prev;
00078 prev = next = 0;
00079 }
00080 }
00081
00082 void RemoveAndDelete() {
00083 Remove();
00084 delete container;
00085 }
00086
00087 bool InList() {
00088 GLASSERT( !Sentinel() );
00089 GLASSERT( ( prev && next ) || (!prev && !next ) );
00090 return prev != 0;
00091 }
00092
00093 T* Container() { return container; }
00094 InnerCircle<T>* Next() { return next; }
00095 InnerCircle<T>* Prev() { return prev; }
00096 bool Sentinel() { return !container; }
00097
00098 private:
00099 InnerCircle *next, *prev;
00100 T* container;
00101 };
00102
00103
00104 };
00105
00106 #endif