lists.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2001  The Exult Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef _LISTS_H_
00020 #define _LISTS_H_
00021 
00022 // TODO: merge lists.h and vec.h into one file?!
00023 
00024 #include <list>
00025 #include "exceptions.h"
00026 
00027 class Actor;
00028 
00029 template <class T>
00030 class Exult_queue
00031 {
00032 public:
00033   typedef typename std::list<T>::size_type    size_type;
00034   typedef typename std::list<T>::const_iterator const_iterator;
00035 
00036 protected:
00037   std::list<T> data;
00038 
00039 public:
00040   // exception class for illegal operations on an empty queue
00041   class empty_queue_exception : public exult_exception
00042   {
00043   public:
00044     empty_queue_exception () : exult_exception("attempt to read an empty queue") {  }
00045   };
00046 
00047   // number of elements
00048   size_type size() const
00049     { return data.size(); }
00050 
00051   // queue empty?
00052   bool empty() const
00053     { return data.empty(); }
00054 
00055   // insert element into the queue
00056   void push (const T& obj)
00057     { data.push_back(obj); }
00058 
00059   // insert element at the front of the queue
00060   void push_front (const T& obj)
00061     { data.push_front(obj); }
00062 
00063   // pop element out of the queue and return its value
00064   T pop ()
00065   {
00066     if (data.empty())
00067       throw empty_queue_exception();
00068     T obj(data.front());
00069     data.pop_front();
00070     return obj;
00071   }
00072 
00073   // return value of next element
00074   T& front ()
00075   {
00076     if (data.empty())
00077       throw empty_queue_exception();
00078     return data.back();
00079   }
00080   
00081   // remove an element from the queue
00082   void remove(const T& obj)
00083     { data.remove(obj); }
00084   
00085   // clear the queue
00086   void clear()
00087     { data.clear(); }
00088 
00089   // iterators:
00090   const_iterator         begin() const
00091     { return data.begin(); }
00092   const_iterator         end() const
00093     { return data.end(); }
00094 };
00095 
00096 typedef Exult_queue<Actor*> Actor_queue;
00097 
00098 
00099 #endif

Generated on Mon Jul 9 14:42:47 2007 for ExultEngine by  doxygen 1.5.1