source: golgotha/src/i4/memory/que.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 1.4 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef I4_QUE_HH
10#define I4_QUE_HH
11
12#include "arch.hh"
13
14template <class T, w32 SIZE>
15class i4_fixed_que
16{
17protected:
18  T data[SIZE];
19  w32 head, tail;
20 
21public:
22  void reset() { head=tail=0; }
23
24  i4_fixed_que() { reset(); }
25
26  i4_bool empty() { return (i4_bool)(head==tail); }
27
28  i4_bool full() { return (i4_bool)((head==SIZE-1 && tail==0) || head+1==tail); }
29
30  i4_bool que(const T &object)
31  {
32    w32 next_head=(head+1);
33    if (next_head==SIZE)
34      next_head=0;
35
36    if (next_head==tail)
37      return i4_F;
38
39    data[head]=object;
40    head=next_head;
41    return i4_T;
42  }
43
44  i4_bool deque(T &object)
45  {
46    if (empty())
47      return i4_F;
48
49    object=data[tail];
50    tail++;
51    if (tail==SIZE)
52      tail=0;   
53    return i4_T;
54  }
55
56  i4_bool front(T &object)
57  {
58    if (empty())
59      return i4_F;
60
61    object=data[tail];
62    return i4_T;
63  }
64};
65
66#endif
Note: See TracBrowser for help on using the repository browser.