From 5c1c672e018e41e5c87a0263a851684a52d9c1fb Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 27 Mar 2022 19:21:22 +0200 Subject: refactor: replace string matrix with template matrix --- src/engine/graphics/string_matrix.cpp | 140 ---------------------------------- 1 file changed, 140 deletions(-) delete mode 100644 src/engine/graphics/string_matrix.cpp (limited to 'src/engine/graphics/string_matrix.cpp') diff --git a/src/engine/graphics/string_matrix.cpp b/src/engine/graphics/string_matrix.cpp deleted file mode 100644 index 3920b8e..0000000 --- a/src/engine/graphics/string_matrix.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include "string_matrix.hpp" - -#include -#include - -StringMatrix::StringMatrix(const Bounds &bounds) noexcept - : _matrix(new std::string_view *[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 std::string_view[bounds.get_width()]); - } -}; - -StringMatrix::StringMatrix(const StringMatrix &string_matrix) noexcept - : _matrix(new std::string_view *[string_matrix._row_cnt]), - _row_cnt(string_matrix._row_cnt), - _column_cnt(string_matrix._column_cnt) -{ - _copy_matrix_from(string_matrix); -} - -StringMatrix::StringMatrix(StringMatrix &&string_matrix) noexcept - : _matrix(string_matrix._matrix), - _row_cnt(string_matrix._row_cnt), - _column_cnt(string_matrix._column_cnt) -{ - string_matrix._matrix = nullptr; -} - -StringMatrix::~StringMatrix() noexcept -{ - _delete_matrix(); -} - -void StringMatrix::fill(std::string_view element) noexcept -{ - for (auto row : *this) - { - for (auto &col : row) - { - col = element; - } - } -} - -std::string_view StringMatrix::get(const Vector2 &pos) const noexcept -{ - - auto x = static_cast(pos.get_x()); - auto y = static_cast(pos.get_y()); - - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - return _matrix[y][x]; -} - -void StringMatrix::set(const Vector2 &pos, std::string_view 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; -} - -uint32_t StringMatrix::get_row_cnt() const noexcept -{ - return _row_cnt; -} - -uint32_t StringMatrix::get_column_cnt() const noexcept -{ - return _column_cnt; -} - -MatrixIterator StringMatrix::begin() const noexcept -{ - return MatrixIterator(_matrix, _column_cnt); -} - -MatrixIterator StringMatrix::end() const noexcept -{ - return MatrixIterator(_matrix + _row_cnt, _column_cnt); -} - -StringMatrix &StringMatrix::operator=(const StringMatrix &rhs) noexcept -{ - if (&rhs != this) - { - _delete_matrix(); - _matrix = nullptr; - - _matrix = new std::string_view *[rhs._row_cnt]; - _copy_matrix_from(rhs); - } - - return *this; -} - -StringMatrix &StringMatrix::operator=(StringMatrix &&rhs) noexcept -{ - if (&rhs != this) - { - _delete_matrix(); - _matrix = rhs._matrix; - rhs._matrix = nullptr; - } - - return *this; -} - -void StringMatrix::_delete_matrix() noexcept -{ - for (gsl::owner row = _matrix; row != _matrix + _row_cnt; row++) - { - delete[](*row); - } - - delete[] _matrix; -} - -void StringMatrix::_copy_matrix_from(const StringMatrix &source) noexcept -{ - gsl::owner source_row = source._matrix; - - for (gsl::owner row = _matrix; row != _matrix + _row_cnt; - row++, source_row++) - { - *row = static_cast>( - new std::string_view[_column_cnt]); - - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto *end = *source_row + _column_cnt; - - std::copy(*source_row, end, *row); - } -} -- cgit v1.2.3-18-g5258