- Main Page
- Classes
- Files
- Directories
- Related Pages

# 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 #ifdef _MSC_VER
    00033 #pragma warning( disable : 4530 )
    00034 #pragma warning( disable : 4786 )
    00035 #endif
    00036
    00037 #include "../../grinliz/gldebug.h"
    00038
    00039 // The type of this must be a pointer.
    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;             // assume sentinel, again.
    00081         }
    00082
    00083         // Should be private, but I don't feel like fighting with
    00084         // making templates friends.
    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