Main Page   Class Hierarchy   Compound List   File List   Compound Members  

gllist.h

00001 /*--License:
00002         Kyra Sprite Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2002
00004         www.grinninglizard.com/kyra
00005         www.sourceforge.net/projects/kyra
00006 
00007         Kyra is provided under 2 licenses:
00008 
00009         - The GPL, with no additional restrictions.
00010         - The LGPL, provided you display the Kyra splash screen, described below.
00011 
00012 
00013 --- GPL License --
00014         This program is free software; you can redistribute it and/or
00015         modify it under the terms of the GNU General Public License
00016         as published by the Free Software Foundation; either version 2
00017         of the License, or (at your option) any later version.
00018 
00019         This program is distributed in the hope that it will be useful,
00020         but WITHOUT ANY WARRANTY; without even the implied warranty of
00021         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022         GNU General Public License for more details.
00023 
00024         You should have received a copy of the GNU General Public License
00025         along with this program; if not, write to the Free Software
00026         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 
00028         The full text of the license can be found in license.txt
00029 
00030 
00031 --- LGPL License --
00032   **Provided you kindly display the Kyra splash screen (details below), 
00033         you     may use the LGPL license:**
00034 
00035     This library is free software; you can redistribute it and/or
00036     modify it under the terms of the GNU Lesser General Public
00037     License as published by the Free Software Foundation; either
00038     version 2.1 of the License, or (at your option) any later version.
00039 
00040     This library is distributed in the hope that it will be useful,
00041     but WITHOUT ANY WARRANTY; without even the implied warranty of
00042     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00043     Lesser General Public License for more details.
00044 
00045     You should have received a copy of the GNU Lesser General Public
00046     License along with this library; if not, write to the Free Software
00047     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00048 
00049         The full text of the license can be found in lgpl.txt
00050 
00051 
00052 --- Kyra Splash Screen.
00053 
00054         It would be appreciate if you display the Kyra splash screen when using
00055         either license, however it is only required for the LGPL. All the
00056         resources for the splash are compiled into the library, and it can be
00057         accessed through the following API:
00058 
00059                 KrEngine::StartSplash
00060                 KrEngine::UpdateSplash
00061                 KrEngine::EndSplash
00062 
00063         Full documentation is provided with the KrEngine class. The splash screen
00064         should be displayed for 2 seconds.
00065 
00066         Thank you.
00067 */
00068 
00069 #ifndef KYRA_LIST_INCLUDED
00070 #define KYRA_LIST_INCLUDED
00071 
00072 #include "gldebug.h"
00073 
00074 
00077 template <class T>
00078 struct GlSListNode
00079 {
00080         GlSListNode* next;      
00081         T data;                         
00082 };
00083 
00084 
00089 template <class T>
00090 class GlSList
00091 {
00092   public:
00093         GlSList()               { root = 0; }
00094         ~GlSList()              { Clear(); }
00095 
00097         int  Size() const               { return Count(); }
00099         int  Count() const              {       GlSListNode<T>* node;
00100                                                                 int count = 0;
00101                                                                 for( node = root; node; node = node->next )
00102                                                                         ++count;
00103                                                                 return count;
00104                                                         }
00106         bool Empty() const              { return root == 0; }
00108         T&       Front() const          { return root->data; }
00110         GlSListNode<T>*  FrontNode() const              { return root; }
00111 
00113         void Clear()    {       GlSListNode<T>* temp;
00114 
00115                                                 while( root )
00116                                                 {
00117                                                         temp = root;
00118                                                         root = root->next;
00119                                                         delete temp;
00120                                                 }
00121                                         }
00122 
00124         void PushFront( const T& insert )
00125                                         {
00126                                                 GlSListNode<T>* node = new GlSListNode<T>;
00127                                                 node->data = insert;
00128                                                 node->next = root;
00129                                                 root = node;
00130                                         }
00131 
00133         void PushBack( const T& insert )
00134         {
00135                 GlSListNode<T>* end;
00136                 for ( end=root; end && end->next; end = end->next )
00137                 {}
00138 
00139                 if ( !end )
00140                 {
00141                         PushFront( insert );
00142                 }
00143                 else
00144                 {
00145                         GlSListNode<T>* node = new GlSListNode<T>;
00146                         node->data = insert;
00147                         node->next = 0;
00148                         end->next = node;
00149                 }
00150         }
00151 
00154         void PopFront()
00155         {
00156                 if ( root )
00157                 {
00158                         GlSListNode<T>* temp = root->next;
00159                         delete root;
00160                         root = temp;
00161                 }
00162         }
00163 
00167         void Pop( const T& thisone )
00168         {
00169                 GlSListNode<T>* node;
00170                 GlSListNode<T>* prev;
00171 
00172                 for( node = root, prev = 0;
00173                          node;
00174                          prev = node, node = node->next )
00175                 {
00176                         if ( node->data == thisone )
00177                         {
00178                                 if ( prev )
00179                                 {
00180                                         prev->next = node->next;
00181                                 }
00182                                 else
00183                                 {
00184                                         root = node->next;
00185                                 }
00186                                 delete node;
00187                                 break;
00188                         }
00189                 }
00190         }
00191 
00193         GlSListNode<T>* Find( const T& findthis )
00194         {
00195                 GlSListNode<T>* node;
00196                 for( node=root; node; node=node->next )
00197                 {
00198                         if ( node->data == findthis )
00199                                 return node;
00200                 }       
00201                 return 0;
00202         }
00203                 
00205         bool FindAndDelete( const T& findthis )
00206         {
00207                 GlSListNode<T>* node;
00208                 GlSListNode<T>* prev;
00209 
00210                 for(    node=root, prev = 0; 
00211                                 node; 
00212                                 prev = node, node=node->next )
00213                 {
00214                         if ( node->data == findthis )
00215                         {
00216                                 if ( prev )
00217                                         prev->next = node->next;
00218                                 else
00219                                         root = node->next;
00220                                 delete node;
00221                                 return true;
00222                         }
00223                 }       
00224                 return false;
00225         }
00226 
00227 
00228   private:
00229         GlSListNode<T>* root;
00230         GlSList( const GlSList& that );
00231         GlSList operator=( const GlSList& that );
00232 };
00233 
00234 
00237 template <class T>
00238 class GlSListIterator
00239 {
00240   public:
00241         GlSListIterator( const GlSList<T>& _list ) : current( 0 ), list( &_list )       {}
00242 
00243         void Begin()            { current = list->FrontNode(); }
00244         void Next()                     { current = current->next; }
00245         bool Done()                     { return ( current == 0 ); }
00246 
00248         T& Current()                                    { return (current->data); }
00249 
00250         GlSListNode<T>* CurrentNode()   { return current; }
00251 
00252   private:
00253         GlSListNode<T>* current;        
00254         const GlSList<T>* list;
00255 };
00256 
00257 
00258 #endif

Generated on Fri Feb 7 20:44:20 2003 for Kyra by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001