MatrixStack.h 777 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef MATRIXSTACK_H
  2. #define MATRIXSTACK_H
  3. #include "utils/Stack.h"
  4. #include "math/Matrix.h"
  5. template<int N>
  6. class MatrixStack final {
  7. Stack<Matrix, N> stack;
  8. public:
  9. MatrixStack() {
  10. stack.push(Matrix());
  11. }
  12. bool pop() {
  13. stack.pop();
  14. if(stack.isEmpty()) {
  15. stack.push(Matrix());
  16. return true;
  17. }
  18. return false;
  19. }
  20. bool push() {
  21. return stack.push(stack.peek());
  22. }
  23. Matrix& peek() {
  24. return stack.peek();
  25. }
  26. const Matrix& peek() const {
  27. return stack.peek();
  28. }
  29. void clear() {
  30. stack.clear();
  31. stack.push(Matrix());
  32. }
  33. template<int L>
  34. void toString(StringBuffer<L>& s) const {
  35. s.append(stack);
  36. }
  37. };
  38. #endif