diff options
author | HampusM <hampus@hampusmat.com> | 2022-03-19 13:21:54 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:56 +0200 |
commit | 55c93fe609888be73677317978959040cf35b2ff (patch) | |
tree | 41ee53961eb5667136432b69773ef7acf3ad8259 /src/engine/matrix_iterator.hpp | |
parent | 020303df1410d10546f53d0bfee4f48797d4f067 (diff) |
refactor: implement matrix iterator
Diffstat (limited to 'src/engine/matrix_iterator.hpp')
-rw-r--r-- | src/engine/matrix_iterator.hpp | 65 |
1 files changed, 65 insertions, 0 deletions
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 <gsl/pointers> + +template <typename Element> +class MatrixRowIterator +{ +public: + using ColumnPtr = gsl::owner<Element *>; + + 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 <typename Element> +class MatrixRow +{ +public: + using RowPtr = gsl::owner<Element *>; + + explicit MatrixRow(RowPtr row_ptr, const uint32_t &column_cnt) noexcept; + + [[nodiscard]] MatrixRowIterator<Element> begin() const noexcept; + + [[nodiscard]] MatrixRowIterator<Element> end() const noexcept; + +private: + RowPtr _row_ptr; + + const uint32_t &_column_cnt; +}; + +template <typename Element> +class MatrixIterator +{ +public: + using RowPtr = gsl::owner<Element **>; + + explicit MatrixIterator(RowPtr row_ptr, const uint32_t &column_cnt) noexcept; + + MatrixIterator &operator++() noexcept; + MatrixIterator operator++(int) noexcept; + + MatrixRow<Element> 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" |