List.h 635 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef LIST_H
  2. #define LIST_H
  3. #include "common/utils/Types.h"
  4. template<typename T, uint L>
  5. class List final {
  6. public:
  7. List() : entries(0) {
  8. }
  9. List& add(const T& t) {
  10. if(entries >= L) {
  11. return *this;
  12. }
  13. data[entries++] = t;
  14. return *this;
  15. }
  16. List& clear() {
  17. entries = 0;
  18. return *this;
  19. }
  20. uint getLength() const {
  21. return entries;
  22. }
  23. T& operator[](uint index) {
  24. return data[index];
  25. }
  26. const T& operator[](uint index) const {
  27. return data[index];
  28. }
  29. private:
  30. uint entries;
  31. T data[L];
  32. };
  33. #endif