From 7e84d664079d9c407bdf94861825bb05ccf1b0f7 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 8 Jun 2022 16:47:48 +0200 Subject: refactor: move matrix iterator to engine graphics folder --- src/engine/graphics/matrix.hpp | 2 +- src/engine/graphics/matrix_iterator.hpp | 65 +++++++++++++++ src/engine/graphics/matrix_iterator_impl.hpp | 115 +++++++++++++++++++++++++++ src/engine/matrix_iterator.hpp | 65 --------------- src/engine/matrix_iterator_impl.hpp | 115 --------------------------- src/interfaces/matrix.hpp | 2 +- 6 files changed, 182 insertions(+), 182 deletions(-) create mode 100644 src/engine/graphics/matrix_iterator.hpp create mode 100644 src/engine/graphics/matrix_iterator_impl.hpp delete mode 100644 src/engine/matrix_iterator.hpp delete mode 100644 src/engine/matrix_iterator_impl.hpp diff --git a/src/engine/graphics/matrix.hpp b/src/engine/graphics/matrix.hpp index fb08b29..7b4d037 100644 --- a/src/engine/graphics/matrix.hpp +++ b/src/engine/graphics/matrix.hpp @@ -4,7 +4,7 @@ #include "engine/data/bounds.hpp" #include "engine/data/vector2.hpp" -#include "engine/matrix_iterator.hpp" +#include "engine/graphics/matrix_iterator.hpp" #include diff --git a/src/engine/graphics/matrix_iterator.hpp b/src/engine/graphics/matrix_iterator.hpp new file mode 100644 index 0000000..70a59bf --- /dev/null +++ b/src/engine/graphics/matrix_iterator.hpp @@ -0,0 +1,65 @@ +#pragma once + +#include + +template +class MatrixRowIterator +{ +public: + using ColumnPtr = gsl::owner; + + explicit MatrixRowIterator(ColumnPtr column_ptr) noexcept; + + auto operator++() noexcept -> MatrixRowIterator &; + auto operator++(int) noexcept -> MatrixRowIterator; + + auto operator*() const noexcept -> Element &; + + auto operator==(const MatrixRowIterator &rhs) const noexcept -> bool; + auto operator!=(const MatrixRowIterator &rhs) const noexcept -> bool; + +private: + ColumnPtr _column_ptr; +}; + +template +class MatrixRow +{ +public: + using RowPtr = gsl::owner; + + explicit MatrixRow(RowPtr row_ptr, const uint32_t &column_cnt) noexcept; + + [[nodiscard]] auto begin() const noexcept -> MatrixRowIterator; + + [[nodiscard]] auto end() const noexcept -> MatrixRowIterator; + +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; + + auto operator++() noexcept -> MatrixIterator &; + auto operator++(int) noexcept -> MatrixIterator; + + auto operator*() const noexcept -> MatrixRow; + + auto operator==(const MatrixIterator &rhs) const noexcept -> bool; + auto operator!=(const MatrixIterator &rhs) const noexcept -> bool; + +private: + RowPtr _row_ptr; + + const uint32_t &_column_cnt; +}; + +#include "matrix_iterator_impl.hpp" diff --git a/src/engine/graphics/matrix_iterator_impl.hpp b/src/engine/graphics/matrix_iterator_impl.hpp new file mode 100644 index 0000000..4b2c785 --- /dev/null +++ b/src/engine/graphics/matrix_iterator_impl.hpp @@ -0,0 +1,115 @@ +#pragma once + +#include "matrix_iterator.hpp" + +// Matrix row iterator + +template +MatrixRowIterator::MatrixRowIterator(ColumnPtr column_ptr) noexcept + : _column_ptr(column_ptr) +{ +} + +template +auto MatrixRowIterator::operator++() noexcept -> MatrixRowIterator & +{ + ++_column_ptr; + + return *this; +} + +template +auto MatrixRowIterator::operator++(int) noexcept -> MatrixRowIterator +{ + auto copy = *this; + + ++(*this); + + return copy; +} + +template +auto MatrixRowIterator::operator*() const noexcept -> Element & +{ + return *_column_ptr; +} + +template +auto MatrixRowIterator::operator==(const MatrixRowIterator &rhs) const noexcept + -> bool +{ + return _column_ptr == rhs._column_ptr; +} + +template +auto MatrixRowIterator::operator!=(const MatrixRowIterator &rhs) const noexcept + -> bool +{ + return _column_ptr != rhs._column_ptr; +} + +// Matrix row + +template +MatrixRow::MatrixRow(RowPtr row_ptr, const uint32_t &column_cnt) noexcept + : _row_ptr(row_ptr), _column_cnt(column_cnt) +{ +} + +template +auto MatrixRow::begin() const noexcept -> MatrixRowIterator +{ + return MatrixRowIterator(_row_ptr); +} + +template +auto MatrixRow::end() const noexcept -> MatrixRowIterator +{ + return MatrixRowIterator(_row_ptr + _column_cnt); +} + +// Matrix iterator + +template +MatrixIterator::MatrixIterator( + RowPtr row_ptr, + const uint32_t &column_cnt) noexcept + : _row_ptr(row_ptr), _column_cnt(column_cnt) +{ +} + +template +auto MatrixIterator::operator++() noexcept -> MatrixIterator & +{ + ++_row_ptr; + + return *this; +} + +template +auto MatrixIterator::operator++(int) noexcept -> MatrixIterator +{ + auto copy = *this; + + ++(*this); + + return copy; +} + +template +auto MatrixIterator::operator*() const noexcept -> MatrixRow +{ + return MatrixRow(*_row_ptr, _column_cnt); +} + +template +auto MatrixIterator::operator==(const MatrixIterator &rhs) const noexcept -> bool +{ + return _row_ptr == rhs._row_ptr; +} + +template +auto MatrixIterator::operator!=(const MatrixIterator &rhs) const noexcept -> bool +{ + return _row_ptr != rhs._row_ptr; +} diff --git a/src/engine/matrix_iterator.hpp b/src/engine/matrix_iterator.hpp deleted file mode 100644 index 70a59bf..0000000 --- a/src/engine/matrix_iterator.hpp +++ /dev/null @@ -1,65 +0,0 @@ -#pragma once - -#include - -template -class MatrixRowIterator -{ -public: - using ColumnPtr = gsl::owner; - - explicit MatrixRowIterator(ColumnPtr column_ptr) noexcept; - - auto operator++() noexcept -> MatrixRowIterator &; - auto operator++(int) noexcept -> MatrixRowIterator; - - auto operator*() const noexcept -> Element &; - - auto operator==(const MatrixRowIterator &rhs) const noexcept -> bool; - auto operator!=(const MatrixRowIterator &rhs) const noexcept -> bool; - -private: - ColumnPtr _column_ptr; -}; - -template -class MatrixRow -{ -public: - using RowPtr = gsl::owner; - - explicit MatrixRow(RowPtr row_ptr, const uint32_t &column_cnt) noexcept; - - [[nodiscard]] auto begin() const noexcept -> MatrixRowIterator; - - [[nodiscard]] auto end() const noexcept -> MatrixRowIterator; - -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; - - auto operator++() noexcept -> MatrixIterator &; - auto operator++(int) noexcept -> MatrixIterator; - - auto operator*() const noexcept -> MatrixRow; - - auto operator==(const MatrixIterator &rhs) const noexcept -> bool; - auto operator!=(const MatrixIterator &rhs) const noexcept -> bool; - -private: - RowPtr _row_ptr; - - const uint32_t &_column_cnt; -}; - -#include "matrix_iterator_impl.hpp" diff --git a/src/engine/matrix_iterator_impl.hpp b/src/engine/matrix_iterator_impl.hpp deleted file mode 100644 index 4b2c785..0000000 --- a/src/engine/matrix_iterator_impl.hpp +++ /dev/null @@ -1,115 +0,0 @@ -#pragma once - -#include "matrix_iterator.hpp" - -// Matrix row iterator - -template -MatrixRowIterator::MatrixRowIterator(ColumnPtr column_ptr) noexcept - : _column_ptr(column_ptr) -{ -} - -template -auto MatrixRowIterator::operator++() noexcept -> MatrixRowIterator & -{ - ++_column_ptr; - - return *this; -} - -template -auto MatrixRowIterator::operator++(int) noexcept -> MatrixRowIterator -{ - auto copy = *this; - - ++(*this); - - return copy; -} - -template -auto MatrixRowIterator::operator*() const noexcept -> Element & -{ - return *_column_ptr; -} - -template -auto MatrixRowIterator::operator==(const MatrixRowIterator &rhs) const noexcept - -> bool -{ - return _column_ptr == rhs._column_ptr; -} - -template -auto MatrixRowIterator::operator!=(const MatrixRowIterator &rhs) const noexcept - -> bool -{ - return _column_ptr != rhs._column_ptr; -} - -// Matrix row - -template -MatrixRow::MatrixRow(RowPtr row_ptr, const uint32_t &column_cnt) noexcept - : _row_ptr(row_ptr), _column_cnt(column_cnt) -{ -} - -template -auto MatrixRow::begin() const noexcept -> MatrixRowIterator -{ - return MatrixRowIterator(_row_ptr); -} - -template -auto MatrixRow::end() const noexcept -> MatrixRowIterator -{ - return MatrixRowIterator(_row_ptr + _column_cnt); -} - -// Matrix iterator - -template -MatrixIterator::MatrixIterator( - RowPtr row_ptr, - const uint32_t &column_cnt) noexcept - : _row_ptr(row_ptr), _column_cnt(column_cnt) -{ -} - -template -auto MatrixIterator::operator++() noexcept -> MatrixIterator & -{ - ++_row_ptr; - - return *this; -} - -template -auto MatrixIterator::operator++(int) noexcept -> MatrixIterator -{ - auto copy = *this; - - ++(*this); - - return copy; -} - -template -auto MatrixIterator::operator*() const noexcept -> MatrixRow -{ - return MatrixRow(*_row_ptr, _column_cnt); -} - -template -auto MatrixIterator::operator==(const MatrixIterator &rhs) const noexcept -> bool -{ - return _row_ptr == rhs._row_ptr; -} - -template -auto MatrixIterator::operator!=(const MatrixIterator &rhs) const noexcept -> bool -{ - return _row_ptr != rhs._row_ptr; -} diff --git a/src/interfaces/matrix.hpp b/src/interfaces/matrix.hpp index 3ab102c..10a3590 100644 --- a/src/interfaces/matrix.hpp +++ b/src/interfaces/matrix.hpp @@ -2,7 +2,7 @@ #include "engine/data/bounds.hpp" #include "engine/data/vector2.hpp" -#include "engine/matrix_iterator.hpp" +#include "engine/graphics/matrix_iterator.hpp" #include -- cgit v1.2.3-18-g5258