MatrixStack.hpp 1022 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef CORE_MATRIX_STACK_HPP
  2. #define CORE_MATRIX_STACK_HPP
  3. #include "data/ArrayList.hpp"
  4. #include "math/Matrix.hpp"
  5. namespace Core {
  6. template<int N>
  7. class MatrixStack final {
  8. ArrayList<Matrix, N> stack;
  9. public:
  10. MatrixStack() : stack() {
  11. (void)stack.add(Matrix());
  12. }
  13. check_return Error pop() {
  14. if(stack.getLength() <= 1) {
  15. return Error::INVALID_STATE;
  16. }
  17. return stack.removeLast();
  18. }
  19. check_return Error push() {
  20. return stack.add(peek());
  21. }
  22. Matrix& peek() {
  23. return stack[stack.getLength() - 1];
  24. }
  25. const Matrix& peek() const {
  26. return stack[stack.getLength() - 1];
  27. }
  28. void clear() {
  29. stack.clear();
  30. (void)stack.add(Matrix());
  31. }
  32. template<typename String>
  33. check_return Error toString(String& s) const {
  34. return s.append(stack);
  35. }
  36. };
  37. }
  38. #endif