#ifndef MATRIXSTACK_H #define MATRIXSTACK_H #include "data/ArrayList.h" #include "math/Matrix.h" template class MatrixStack final { ArrayList stack; public: MatrixStack() { stack.add(Matrix()); } bool pop() { stack.remove(stack.getLength() - 1); if(stack.getLength() == 0) { stack.add(Matrix()); return true; } return false; } bool push() { return stack.add(peek()); } Matrix& peek() { return stack[stack.getLength() - 1]; } const Matrix& peek() const { return stack[stack.getLength() - 1]; } void clear() { stack.clear(); stack.add(Matrix()); } template void toString(StringBuffer& s) const { s.append(stack); } }; #endif