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/graphics/string_matrix.hpp | |
parent | 020303df1410d10546f53d0bfee4f48797d4f067 (diff) |
refactor: implement matrix iterator
Diffstat (limited to 'src/engine/graphics/string_matrix.hpp')
-rw-r--r-- | src/engine/graphics/string_matrix.hpp | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/src/engine/graphics/string_matrix.hpp b/src/engine/graphics/string_matrix.hpp index 40fbb11..ff0939c 100644 --- a/src/engine/graphics/string_matrix.hpp +++ b/src/engine/graphics/string_matrix.hpp @@ -4,58 +4,49 @@ #include "engine/data/bounds.hpp" #include "engine/data/vector2.hpp" +#include "engine/matrix_iterator.hpp" +#include <gsl/pointers> +#include <memory> #include <string_view> #include <vector> -/** - * A Matrix. - */ class StringMatrix : public IMatrix<std::string_view> { public: - /** - * Creates a matrix. - * - * @param bounds The bounds of the matrix - */ explicit StringMatrix(const Bounds &bounds) noexcept; - /** - * Fills the matrix with a element. - * - * @param element A element - */ + StringMatrix(const StringMatrix &string_matrix) noexcept; + + StringMatrix(StringMatrix &&string_matrix) noexcept; + + ~StringMatrix() noexcept override; + void fill(std::string_view element) noexcept override; - /** - * Returns a element of the matrix. - * - * @param pos The position of a element - */ [[nodiscard]] std::string_view get(const Vector2 &pos) const noexcept override; - /** - * Sets a element of the matrix. - * - * @param pos The position of a element - * @param element A new element - */ void set(const Vector2 &pos, std::string_view element) noexcept override; - /** - * Returns the number of rows the matrix has. - */ - [[nodiscard]] uint32_t rows() const noexcept override; + [[nodiscard]] uint32_t get_row_cnt() const noexcept override; + + [[nodiscard]] uint32_t get_column_cnt() const noexcept override; + + [[nodiscard]] MatrixIterator<std::string_view> begin() const noexcept override; - /** - * Returns the number of columns the matrix has. - */ - [[nodiscard]] uint32_t columns() const noexcept override; + [[nodiscard]] MatrixIterator<std::string_view> end() const noexcept override; + + StringMatrix &operator=(const StringMatrix &rhs) noexcept; + + StringMatrix &operator=(StringMatrix &&rhs) noexcept; private: - std::vector<std::vector<std::string_view>> _matrix; + gsl::owner<std::string_view **> _matrix; + + uint32_t _row_cnt; + uint32_t _column_cnt; + + void _delete_matrix() noexcept; - uint32_t _rows; - uint32_t _columns; + void _copy_matrix_from(const StringMatrix &source) noexcept; }; |