List.h 960 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. uint getCapacity() const {
  24. return L;
  25. }
  26. T& operator[](uint index) {
  27. return data[index];
  28. }
  29. const T& operator[](uint index) const {
  30. return data[index];
  31. }
  32. const T* getData() {
  33. return data;
  34. }
  35. T* begin() {
  36. return data;
  37. }
  38. const T* begin() const {
  39. return data;
  40. }
  41. T* end() {
  42. return data + entries;
  43. }
  44. const T* end() const {
  45. return data + entries;
  46. }
  47. private:
  48. uint entries;
  49. T data[L];
  50. };
  51. #endif