SSP21-CPP
ICollection.h
1 
2 #ifndef SSP21_ICOLLECTION_H
3 #define SSP21_ICOLLECTION_H
4 
5 #include <cstdint>
6 
7 namespace ssp21
8 {
9  /**
10  *
11  * A unmodifiable collection of some abstract type T
12  *
13  */
14  template <class T>
16  {
17 
18  public:
19 
20  virtual uint32_t count() const = 0;
21 
22  virtual T const* get(uint32_t i) const = 0;
23 
24  bool is_empty() const
25  {
26  return this->count() == 0;
27  }
28 
29  bool is_not_empty() const
30  {
31  return this->count() != 0;
32  }
33 
34  virtual T const* last() const
35  {
36  if (this->is_empty())
37  {
38  return nullptr;
39  }
40  else
41  {
42  return this->get(this->count() - 1);
43  }
44  }
45 
46  template <class Action>
47  void foreach(const Action& action) const
48  {
49  for (uint32_t i = 0; i < count(); ++i)
50  {
51  action(*this->get(i));
52  }
53  }
54  };
55 }
56 
57 #endif
SSP21-cpp main namespace.
Definition: BufferTypes.h:12