MatrixStack.hpp 962 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. stack.add(Matrix());
  12. }
  13. void pop() {
  14. assert(stack.getLength() > 0);
  15. stack.removeLast();
  16. }
  17. void push() {
  18. 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. stack.add(Matrix());
  31. }
  32. void toString(BufferString& s) const {
  33. s.append(stack);
  34. }
  35. };
  36. }
  37. #endif