From 55c93fe609888be73677317978959040cf35b2ff Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 19 Mar 2022 13:21:54 +0100 Subject: refactor: implement matrix iterator --- src/engine/matrix_iterator.hpp | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/engine/matrix_iterator.hpp (limited to 'src/engine/matrix_iterator.hpp') diff --git a/src/engine/matrix_iterator.hpp b/src/engine/matrix_iterator.hpp new file mode 100644 index 0000000..5d35052 --- /dev/null +++ b/src/engine/matrix_iterator.hpp @@ -0,0 +1,65 @@ +#pragma once + +#include + +template +class MatrixRowIterator +{ +public: + using ColumnPtr = gsl::owner; + + explicit MatrixRowIterator(ColumnPtr column_ptr) noexcept; + + MatrixRowIterator &operator++() noexcept; + MatrixRowIterator operator++(int) noexcept; + + Element &operator*() const noexcept; + + bool operator==(const MatrixRowIterator &rhs) const noexcept; + bool operator!=(const MatrixRowIterator &rhs) const noexcept; + +private: + ColumnPtr _column_ptr; +}; + +template +class MatrixRow +{ +public: + using RowPtr = gsl::owner; + + explicit MatrixRow(RowPtr row_ptr, const uint32_t &column_cnt) noexcept; + + [[nodiscard]] MatrixRowIterator begin() const noexcept; + + [[nodiscard]] MatrixRowIterator end() const noexcept; + +private: + RowPtr _row_ptr; + + const uint32_t &_column_cnt; +}; + +template +class MatrixIterator +{ +public: + using RowPtr = gsl::owner; + + explicit MatrixIterator(RowPtr row_ptr, const uint32_t &column_cnt) noexcept; + + MatrixIterator &operator++() noexcept; + MatrixIterator operator++(int) noexcept; + + MatrixRow operator*() const noexcept; + + bool operator==(const MatrixIterator &rhs) const noexcept; + bool operator!=(const MatrixIterator &rhs) const noexcept; + +private: + RowPtr _row_ptr; + + const uint32_t &_column_cnt; +}; + +#include "matrix_iterator.tpp" -- cgit v1.2.3-18-g5258