PedestrainCounting
Pool.h
1 
6 #ifndef POOL_HEADER
7 #define POOL_HEADER
8 
9 #include "GlobalHeader.h"
10 
11 template<typename T> class Pool {
12 public:
13  // The size of the pool.
14  int size;
15  // Data container.
16  std::vector<T> data;
17 
18  // Constructor.
19  Pool(int sz = 0) : size(sz) { data = std::vector<T>(sz); }
20 
21  // Overload the operator.
22  T &operator[](uint index) {
23  return data[index];
24  }
25 
26  const T &operator[](uint index) const {
27  return data[index];
28  }
29 
30  void Push(const T &t) {
31  if (size == data.size())
32  data.push_back(t);
33  else
34  data[size] = t;
35  size++;
36  }
37 
38  // Reset the pool;
39  void clear() {
40  size = 0;
41  }
42 
43  void Resize(int sz) {
44  if (sz > size) {
45  data.resize(sz);
46  }
47  size = sz;
48  }
49 };
50 
51 #endif
Definition: Pool.h:11