#ifndef CORE_MATRIX_STACK_H #define CORE_MATRIX_STACK_H #include "data/ArrayList.h" #include "math/Matrix.h" namespace Core { template class MatrixStack final { ArrayList stack; public: MatrixStack() { (void)stack.add(Matrix()); } // returns true on error and calls the error callback check_return bool pop() { if(stack.getLength() <= 1) { return CORE_ERROR(Error::NOT_FOUND); } return stack.removeLast(); } // returns true on error and calls the error callback check_return bool push() { return stack.add(peek()) == nullptr; } Matrix& peek() { return stack[stack.getLength() - 1]; } const Matrix& peek() const { return stack[stack.getLength() - 1]; } void clear() { stack.clear(); (void)stack.add(Matrix()); } // returns true on error and calls the error callback template check_return bool toString(ArrayString& s) const { return s.append(stack); } }; } #endif