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.tpp | |
parent | 020303df1410d10546f53d0bfee4f48797d4f067 (diff) |
refactor: implement matrix iterator
Diffstat (limited to 'src/engine/matrix_iterator.tpp')
-rw-r--r-- | src/engine/matrix_iterator.tpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/engine/matrix_iterator.tpp b/src/engine/matrix_iterator.tpp new file mode 100644 index 0000000..52952c9 --- /dev/null +++ b/src/engine/matrix_iterator.tpp @@ -0,0 +1,112 @@ +#pragma once + +#include "matrix_iterator.hpp" + +// Matrix row iterator + +template <typename Element> +MatrixRowIterator<Element>::MatrixRowIterator(ColumnPtr column_ptr) noexcept + : _column_ptr(column_ptr) +{ +} + +template <typename Element> +MatrixRowIterator<Element> &MatrixRowIterator<Element>::operator++() noexcept +{ + ++_column_ptr; + + return *this; +} + +template <typename Element> +MatrixRowIterator<Element> MatrixRowIterator<Element>::operator++(int) noexcept +{ + auto copy = *this; + + ++(*this); + + return copy; +} + +template <typename Element> +Element &MatrixRowIterator<Element>::operator*() const noexcept +{ + return *_column_ptr; +} + +template <typename Element> +bool MatrixRowIterator<Element>::operator==(const MatrixRowIterator &rhs) const noexcept +{ + return _column_ptr == rhs._column_ptr; +} + +template <typename Element> +bool MatrixRowIterator<Element>::operator!=(const MatrixRowIterator &rhs) const noexcept +{ + return _column_ptr != rhs._column_ptr; +} + +// Matrix row + +template <typename Element> +MatrixRow<Element>::MatrixRow(RowPtr row_ptr, const uint32_t &column_cnt) noexcept + : _row_ptr(row_ptr), _column_cnt(column_cnt) +{ +} + +template <typename Element> +MatrixRowIterator<Element> MatrixRow<Element>::begin() const noexcept +{ + return MatrixRowIterator<Element>(_row_ptr); +} + +template <typename Element> +MatrixRowIterator<Element> MatrixRow<Element>::end() const noexcept +{ + return MatrixRowIterator<Element>(_row_ptr + _column_cnt); +} + +// Matrix iterator + +template <typename Element> +MatrixIterator<Element>::MatrixIterator(RowPtr row_ptr, + const uint32_t &column_cnt) noexcept + : _row_ptr(row_ptr), _column_cnt(column_cnt) +{ +} + +template <typename Element> +MatrixIterator<Element> &MatrixIterator<Element>::operator++() noexcept +{ + ++_row_ptr; + + return *this; +} + +template <typename Element> +MatrixIterator<Element> MatrixIterator<Element>::operator++(int) noexcept +{ + auto copy = *this; + + ++(*this); + + return copy; +} + +template <typename Element> +MatrixRow<Element> MatrixIterator<Element>::operator*() const noexcept +{ + return MatrixRow(*_row_ptr, _column_cnt); +} + +template <typename Element> +bool MatrixIterator<Element>::operator==(const MatrixIterator &rhs) const noexcept +{ + return _row_ptr == rhs._row_ptr; +} + +template <typename Element> +bool MatrixIterator<Element>::operator!=(const MatrixIterator &rhs) const noexcept +{ + return _row_ptr != rhs._row_ptr; +} |