00001 #ifndef GSGL_DATA_QUEUE_H 00002 #define GSGL_DATA_QUEUE_H 00003 00004 // 00005 // $Id: queue.hpp 2 2008-03-01 20:58:50Z kulibali $ 00006 // 00007 // Copyright (c) 2008, The Periapsis Project. All rights reserved. 00008 // 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions are 00011 // met: 00012 // 00013 // * Redistributions of source code must retain the above copyright notice, 00014 // this list of conditions and the following disclaimer. 00015 // 00016 // * Redistributions in binary form must reproduce the above copyright 00017 // notice, this list of conditions and the following disclaimer in the 00018 // documentation and/or other materials provided with the distribution. 00019 // 00020 // * Neither the name of the The Periapsis Project nor the names of its 00021 // contributors may be used to endorse or promote products derived from 00022 // this software without specific prior written permission. 00023 // 00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00025 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 // 00036 00037 #include "data/data.h" 00038 #include "data/list.h" 00039 00040 namespace gsgl 00041 { 00042 00043 namespace data 00044 { 00045 00046 /// A queue is a FIFO structure. 00047 template <typename T> 00048 class queue 00049 : public list<T> 00050 { 00051 public: 00052 queue(); 00053 queue(const queue & q); 00054 queue & operator= (const queue & q); 00055 virtual ~queue(); 00056 00057 /// Returns the item at the head of the queue. 00058 const T & front() const; 00059 00060 /// Returns the item at the head of the queue. 00061 T & front(); 00062 00063 /// Adds an item on the back of the queue. 00064 void push(const T & a); 00065 00066 /// Removes the front item from the queue. 00067 void pop(); 00068 }; // class queue 00069 00070 // 00071 00072 template <typename T> queue<T>::queue() : list<T>() 00073 {} // queue<T>::queue() 00074 00075 template <typename T> queue<T>::queue(const queue & q) : lisT<T>(q) 00076 {} // queue<T>::queue() 00077 00078 template <typename T> queue<T> & queue<T>::operator= (const queue & q) 00079 { 00080 clear(); 00081 for (list_node *l = q.head; l; l = l->next) 00082 add(l->item); 00083 } // queue<T>::operator= () 00084 00085 template <typename T> 00086 queue<T>::~queue() 00087 { 00088 } // queue<T>::~queue() 00089 00090 template <typename T> const T & queue<T>::front() const 00091 { 00092 return head->item; 00093 } // queue<T>::front() 00094 00095 template <typename T> T & queue<T>::front() 00096 { 00097 return head->item; 00098 } // queue<T>::front() 00099 00100 template <typename T> void queue<T>::push(const T & item) 00101 { 00102 add(item); 00103 } // queue<T>::push() 00104 00105 template <typename T> void queue<T>::pop() 00106 { 00107 if (head) 00108 { 00109 list_node *temp = head; 00110 head = head->next; 00111 delete temp; 00112 } 00113 } // queue<T>::pop() 00114 00115 } // namespace data 00116 00117 } // namespace data 00118 00119 #endif