MatrixStack.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef CORE_MATRIX_STACK_H
  2. #define CORE_MATRIX_STACK_H
  3. #include "data/ArrayList.h"
  4. #include "math/Matrix.h"
  5. namespace Core {
  6. template<int N>
  7. class MatrixStack final {
  8. ArrayList<Matrix, N> stack;
  9. public:
  10. MatrixStack() {
  11. (void)stack.add(Matrix());
  12. }
  13. // returns true on error and calls the error callback
  14. check_return bool pop() {
  15. if(stack.getLength() <= 1) {
  16. return CORE_ERROR(Error::NOT_FOUND);
  17. }
  18. return stack.removeLast();
  19. }
  20. // returns true on error and calls the error callback
  21. check_return bool push() {
  22. return stack.add(peek()) == nullptr;
  23. }
  24. Matrix& peek() {
  25. return stack[stack.getLength() - 1];
  26. }
  27. const Matrix& peek() const {
  28. return stack[stack.getLength() - 1];
  29. }
  30. void clear() {
  31. stack.clear();
  32. (void)stack.add(Matrix());
  33. }
  34. // returns true on error and calls the error callback
  35. template<int L>
  36. check_return bool toString(ArrayString<L>& s) const {
  37. return s.append(stack);
  38. }
  39. };
  40. }
  41. #endif