From 7578eb6f79afbb421298088ee53da620eb04037f Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 2 Jun 2022 20:50:28 +0200 Subject: refactor: rename .tpp files to end with _impl.hpp --- src/engine/graphics/matrix.hpp | 2 +- src/engine/graphics/matrix.tpp | 156 ------------------------------------ src/engine/graphics/matrix_impl.hpp | 156 ++++++++++++++++++++++++++++++++++++ src/engine/matrix_iterator.hpp | 2 +- src/engine/matrix_iterator.tpp | 115 -------------------------- src/engine/matrix_iterator_impl.hpp | 115 ++++++++++++++++++++++++++ 6 files changed, 273 insertions(+), 273 deletions(-) delete mode 100644 src/engine/graphics/matrix.tpp create mode 100644 src/engine/graphics/matrix_impl.hpp delete mode 100644 src/engine/matrix_iterator.tpp create mode 100644 src/engine/matrix_iterator_impl.hpp (limited to 'src/engine') diff --git a/src/engine/graphics/matrix.hpp b/src/engine/graphics/matrix.hpp index 5a7d893..fb08b29 100644 --- a/src/engine/graphics/matrix.hpp +++ b/src/engine/graphics/matrix.hpp @@ -51,4 +51,4 @@ private: void _copy_matrix_from(const Matrix &source) noexcept; }; -#include "matrix.tpp" +#include "matrix_impl.hpp" diff --git a/src/engine/graphics/matrix.tpp b/src/engine/graphics/matrix.tpp deleted file mode 100644 index 527c61f..0000000 --- a/src/engine/graphics/matrix.tpp +++ /dev/null @@ -1,156 +0,0 @@ -#pragma once - -#include "matrix.hpp" - -template -Matrix::Matrix(const Bounds &bounds) noexcept - : _matrix(new Element *[bounds.get_height()]), - _row_cnt(bounds.get_height()), - _column_cnt(bounds.get_width()) -{ - for (gsl::owner row = _matrix; row != _matrix + _row_cnt; row++) - { - *row = static_cast>(new Element[bounds.get_width()]); - } -}; - -template -Matrix::Matrix(const Matrix &matrix) noexcept - : _matrix(new Element *[matrix._row_cnt]), - _row_cnt(matrix._row_cnt), - _column_cnt(matrix._column_cnt) -{ - _copy_matrix_from(matrix); -} - -template -Matrix::Matrix(Matrix &&matrix) noexcept - : _matrix(matrix._matrix), _row_cnt(matrix._row_cnt), _column_cnt(matrix._column_cnt) -{ - matrix._matrix = nullptr; -} - -template -Matrix::~Matrix() noexcept -{ - _delete_matrix(); -} - -template -void Matrix::fill(Element element) noexcept -{ - for (auto row : *this) - { - for (auto &col : row) - { - col = element; - } - } -} - -template -auto Matrix::get(const Vector2 &pos) const noexcept -> Element -{ - - auto x = static_cast(pos.get_x()); - auto y = static_cast(pos.get_y()); - - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - return _matrix[y][x]; -} - -template -void Matrix::set(const Vector2 &pos, Element element) noexcept -{ - auto x = static_cast(pos.get_x()); - auto y = static_cast(pos.get_y()); - - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - _matrix[y][x] = element; -} - -template -auto Matrix::get_row_cnt() const noexcept -> uint32_t -{ - return _row_cnt; -} - -template -auto Matrix::get_column_cnt() const noexcept -> uint32_t -{ - return _column_cnt; -} - -template -auto Matrix::begin() const noexcept -> MatrixIterator -{ - return MatrixIterator(_matrix, _column_cnt); -} - -template -auto Matrix::end() const noexcept -> MatrixIterator -{ - return MatrixIterator(_matrix + _row_cnt, _column_cnt); -} - -template -auto Matrix::operator=(const Matrix &rhs) noexcept -> Matrix & -{ - if (&rhs != this) - { - _delete_matrix(); - - // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) - _matrix = nullptr; - - _matrix = new Element *[rhs._row_cnt]; - _copy_matrix_from(rhs); - } - - return *this; -} - -template -auto Matrix::operator=(Matrix &&rhs) noexcept -> Matrix & -{ - if (&rhs != this) - { - _delete_matrix(); - - // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) - _matrix = rhs._matrix; - - rhs._matrix = nullptr; - } - - return *this; -} - -template -void Matrix::_delete_matrix() noexcept -{ - for (gsl::owner row = _matrix; row != _matrix + _row_cnt; row++) - { - delete[](*row); - } - - delete[] _matrix; -} - -template -void Matrix::_copy_matrix_from(const Matrix &source) noexcept -{ - // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) - gsl::owner source_row = source._matrix; - - for (gsl::owner row = _matrix; row != _matrix + _row_cnt; - row++, source_row++) - { - *row = static_cast>(new Element[_column_cnt]); - - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto *end = *source_row + _column_cnt; - - std::copy(*source_row, end, *row); - } -} diff --git a/src/engine/graphics/matrix_impl.hpp b/src/engine/graphics/matrix_impl.hpp new file mode 100644 index 0000000..527c61f --- /dev/null +++ b/src/engine/graphics/matrix_impl.hpp @@ -0,0 +1,156 @@ +#pragma once + +#include "matrix.hpp" + +template +Matrix::Matrix(const Bounds &bounds) noexcept + : _matrix(new Element *[bounds.get_height()]), + _row_cnt(bounds.get_height()), + _column_cnt(bounds.get_width()) +{ + for (gsl::owner row = _matrix; row != _matrix + _row_cnt; row++) + { + *row = static_cast>(new Element[bounds.get_width()]); + } +}; + +template +Matrix::Matrix(const Matrix &matrix) noexcept + : _matrix(new Element *[matrix._row_cnt]), + _row_cnt(matrix._row_cnt), + _column_cnt(matrix._column_cnt) +{ + _copy_matrix_from(matrix); +} + +template +Matrix::Matrix(Matrix &&matrix) noexcept + : _matrix(matrix._matrix), _row_cnt(matrix._row_cnt), _column_cnt(matrix._column_cnt) +{ + matrix._matrix = nullptr; +} + +template +Matrix::~Matrix() noexcept +{ + _delete_matrix(); +} + +template +void Matrix::fill(Element element) noexcept +{ + for (auto row : *this) + { + for (auto &col : row) + { + col = element; + } + } +} + +template +auto Matrix::get(const Vector2 &pos) const noexcept -> Element +{ + + auto x = static_cast(pos.get_x()); + auto y = static_cast(pos.get_y()); + + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + return _matrix[y][x]; +} + +template +void Matrix::set(const Vector2 &pos, Element element) noexcept +{ + auto x = static_cast(pos.get_x()); + auto y = static_cast(pos.get_y()); + + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + _matrix[y][x] = element; +} + +template +auto Matrix::get_row_cnt() const noexcept -> uint32_t +{ + return _row_cnt; +} + +template +auto Matrix::get_column_cnt() const noexcept -> uint32_t +{ + return _column_cnt; +} + +template +auto Matrix::begin() const noexcept -> MatrixIterator +{ + return MatrixIterator(_matrix, _column_cnt); +} + +template +auto Matrix::end() const noexcept -> MatrixIterator +{ + return MatrixIterator(_matrix + _row_cnt, _column_cnt); +} + +template +auto Matrix::operator=(const Matrix &rhs) noexcept -> Matrix & +{ + if (&rhs != this) + { + _delete_matrix(); + + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) + _matrix = nullptr; + + _matrix = new Element *[rhs._row_cnt]; + _copy_matrix_from(rhs); + } + + return *this; +} + +template +auto Matrix::operator=(Matrix &&rhs) noexcept -> Matrix & +{ + if (&rhs != this) + { + _delete_matrix(); + + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) + _matrix = rhs._matrix; + + rhs._matrix = nullptr; + } + + return *this; +} + +template +void Matrix::_delete_matrix() noexcept +{ + for (gsl::owner row = _matrix; row != _matrix + _row_cnt; row++) + { + delete[](*row); + } + + delete[] _matrix; +} + +template +void Matrix::_copy_matrix_from(const Matrix &source) noexcept +{ + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) + gsl::owner source_row = source._matrix; + + for (gsl::owner row = _matrix; row != _matrix + _row_cnt; + row++, source_row++) + { + *row = static_cast>(new Element[_column_cnt]); + + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + auto *end = *source_row + _column_cnt; + + std::copy(*source_row, end, *row); + } +} diff --git a/src/engine/matrix_iterator.hpp b/src/engine/matrix_iterator.hpp index 674216f..70a59bf 100644 --- a/src/engine/matrix_iterator.hpp +++ b/src/engine/matrix_iterator.hpp @@ -62,4 +62,4 @@ private: const uint32_t &_column_cnt; }; -#include "matrix_iterator.tpp" +#include "matrix_iterator_impl.hpp" diff --git a/src/engine/matrix_iterator.tpp b/src/engine/matrix_iterator.tpp deleted file mode 100644 index 4b2c785..0000000 --- a/src/engine/matrix_iterator.tpp +++ /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/engine/matrix_iterator_impl.hpp b/src/engine/matrix_iterator_impl.hpp new file mode 100644 index 0000000..4b2c785 --- /dev/null +++ b/src/engine/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; +} -- cgit v1.2.3-18-g5258