Main Page   Class Hierarchy   Compound List   File List   Compound Members  

glinsidelist.h

00001 /*
00002 Copyright (c) 2000-2003 Lee Thomason (www.grinninglizard.com)
00003 
00004 Grinning Lizard Utilities. Note that software that uses the 
00005 utility package (including Lilith3D and Kyra) have more restrictive
00006 licences which applies to code outside of the utility package.
00007 
00008 
00009 This software is provided 'as-is', without any express or implied 
00010 warranty. In no event will the authors be held liable for any 
00011 damages arising from the use of this software.
00012 
00013 Permission is granted to anyone to use this software for any 
00014 purpose, including commercial applications, and to alter it and 
00015 redistribute it freely, subject to the following restrictions:
00016 
00017 1. The origin of this software must not be misrepresented; you must 
00018 not claim that you wrote the original software. If you use this 
00019 software in a product, an acknowledgment in the product documentation 
00020 would be appreciated but is not required.
00021 
00022 2. Altered source versions must be plainly marked as such, and 
00023 must not be misrepresented as being the original software.
00024 
00025 3. This notice may not be removed or altered from any source 
00026 distribution.
00027 */
00028 
00029 #ifndef INPLACE_IMAGENODE_INCLUDED
00030 #define INPLACE_IMAGENODE_INCLUDED
00031 
00032 #include "../util/gldebug.h"
00033 
00034 // The type of this must be a pointer.
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;             // assume sentinel, again.
00076         }
00077         
00078         // Should be private, but I don't feel like fighting with
00079         // making templates friends.
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

Generated on Mon Sep 15 12:01:10 2003 for Kyra by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001