#ifndef MATRIXSTACK_H
#define MATRIXSTACK_H

#include "math/Matrix.h"
#include "utils/ArrayList.h"

template<int N>
class MatrixStack final {
    ArrayList<Matrix, N> 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<int L>
    void toString(StringBuffer<L>& s) const {
        s.append(stack);
    }
};

#endif