Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
fifo.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2005 by Jorrit Tyberghein 00003 (C) 2005 by Frank Richter 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_CSUTIL_FIFO_H__ 00021 #define __CS_CSUTIL_FIFO_H__ 00022 00027 #include "csutil/array.h" 00028 00033 template <class T, class ElementHandler = csArrayElementHandler<T>, 00034 class MemoryAllocator = csArrayMemoryAllocator<T> > 00035 class csFIFO 00036 { 00037 csArray<T, ElementHandler, MemoryAllocator> a1, a2; 00038 public: 00043 csFIFO (size_t icapacity = 0, size_t ithreshold = 0) 00044 : a1 (icapacity, ithreshold), a2 (icapacity, ithreshold) { } 00045 00049 T PopTop () 00050 { 00051 CS_ASSERT ((a1.Length() > 0) || (a2.Length() > 0)); 00052 if (a2.Length() == 0) 00053 { 00054 size_t n = a1.Length(); 00055 while (n-- > 0) 00056 { 00057 a2.Push (a1[n]); 00058 } 00059 a1.Empty(); 00060 } 00061 return a2.Pop(); 00062 } 00063 00067 void Push (T const& what) 00068 { 00069 a1.Push (what); 00070 } 00071 00073 size_t Length() 00074 { 00075 return a1.Length() + a2.Length(); 00076 } 00077 00082 bool Delete (T const& what) 00083 { 00084 return (a1.Delete (what) || a2.Delete (what)); 00085 } 00086 00088 void DeleteAll () 00089 { 00090 a1.DeleteAll(); 00091 a2.DeleteAll(); 00092 } 00093 }; 00094 00095 #endif // __CS_CSUTIL_FIFO_H__
Generated for Crystal Space by doxygen 1.4.4