StRoot
1
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
RTS
include
UNIX
simpleQ.hh
1
#ifndef SIMPLEQ_HH
2
#define SIMPLEQ_HH
3
4
#include <sys/types.h>
5
6
template
<
class
T,
int
S>
class
simpleQ
7
{
8
public
:
9
simpleQ
();
10
11
void
clear();
12
int
put(T* a) ;
// returns 0 on success -1 if list is full (end of list)
13
int
prepend(T* a) ;
// beginning of list
14
int
get
(T* a) ;
// like first, but removes element
15
int
query(T* a) ;
16
17
int
entries()
// number of entries in List
18
{
19
return
in;
20
};
21
22
int
free()
// returns number of free entries
23
{
24
return
(S - in) ;
25
};
26
27
T* element(
int
i)
28
{
29
if
(i < S)
return
(&store[i]) ;
30
return
(NULL) ;
31
};
32
33
//private:
34
T store[S] ;
// array of allocated buffers
35
int
f ;
// index to first
36
int
l;
37
int
in;
38
};
39
40
//***********************************************
41
template
<
class
T,
int
S>
simpleQ<T,S>::simpleQ
()
42
{
43
f = l = 0 ;
44
in = 0 ;
45
};
46
47
template
<
class
T,
int
S>
void
simpleQ<T,S>::clear
()
48
{
49
in = 0 ;
50
l = f = 0 ;
51
};
52
53
template
<
class
T,
int
S>
int
simpleQ<T,S>::put
(T* a)
// inserts at end
54
{
55
if
(in == S)
return
(-1) ;
56
in++ ;
57
store[l++] = *a ;
58
if
(l == S) l = 0 ;
59
return
(0) ;
60
};
61
62
template
<
class
T,
int
S>
int
simpleQ<T,S>::get
(T* a)
// removes first element of list
63
{
64
if
(!in)
return
(-1) ;
// empty
65
in-- ;
66
*a = store[f++] ;
67
if
(f == S) f = 0 ;
68
return
(0) ;
69
};
70
71
template
<
class
T,
int
S>
int
simpleQ<T,S>::prepend
(T* a)
// adds element at the front
72
{
73
if
(in == S)
return
(-1) ;
74
in++ ;
75
76
f--;
77
if
(f<0) f = S - 1;
78
store[f] = *a;
79
80
return
0;
81
};
82
83
template
<
class
T,
int
S>
int
simpleQ<T,S>::query
(T* a)
84
{
85
int
i=f;
86
87
while
(i != l)
88
{
89
if
(memcmp(a,&store[i],
sizeof
(T)) == 0)
return
1;
90
i++;
91
if
(i==S) i=0;
92
}
93
94
return
0;
95
};
96
97
#endif
98
99
100
101
102
103
104
simpleQ
Definition:
simpleQ.hh:6
Generated by
1.8.5