MatrixStack.hpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef CORE_MATRIX_STACK_HPP
  2. #define CORE_MATRIX_STACK_HPP
  3. #include "core/data/ArrayList.hpp"
  4. #include "core/math/Matrix.hpp"
  5. namespace Core {
  6. template<size_t N>
  7. class MatrixStack final {
  8. ArrayList<Matrix, N> stack;
  9. public:
  10. MatrixStack() : stack() {
  11. (void)stack.add(Matrix());
  12. }
  13. void pop() {
  14. assert(stack.getLength() > 0);
  15. return stack.removeLast();
  16. }
  17. check_return Error push() {
  18. return stack.add(peek());
  19. }
  20. Matrix& peek() {
  21. assert(stack.getLength() > 0);
  22. return stack[stack.getLength() - 1];
  23. }
  24. const Matrix& peek() const {
  25. assert(stack.getLength() > 0);
  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