aboutsummaryrefslogtreecommitdiff
path: root/src/engine/graphics/matrix.hpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-27 19:21:22 +0200
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:57 +0200
commit5c1c672e018e41e5c87a0263a851684a52d9c1fb (patch)
tree815a067fb558fe3c55b19842402d68e0dc0953f2 /src/engine/graphics/matrix.hpp
parent15c7a8fda742cc393310d75e0e1be89c3042eac0 (diff)
refactor: replace string matrix with template matrix
Diffstat (limited to 'src/engine/graphics/matrix.hpp')
-rw-r--r--src/engine/graphics/matrix.hpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/engine/graphics/matrix.hpp b/src/engine/graphics/matrix.hpp
new file mode 100644
index 0000000..2c9ba81
--- /dev/null
+++ b/src/engine/graphics/matrix.hpp
@@ -0,0 +1,53 @@
+#pragma once
+
+#include "interfaces/matrix.hpp"
+
+#include "engine/data/bounds.hpp"
+#include "engine/data/vector2.hpp"
+#include "engine/matrix_iterator.hpp"
+
+#include <gsl/pointers>
+#include <memory>
+
+template <typename Element>
+class Matrix : public IMatrix<Element>
+{
+public:
+ explicit Matrix(const Bounds &bounds) noexcept;
+
+ Matrix(const Matrix &matrix) noexcept;
+
+ Matrix(Matrix &&matrix) noexcept;
+
+ ~Matrix() noexcept override;
+
+ void fill(Element element) noexcept override;
+
+ [[nodiscard]] Element get(const Vector2 &pos) const noexcept override;
+
+ void set(const Vector2 &pos, Element element) noexcept override;
+
+ [[nodiscard]] uint32_t get_row_cnt() const noexcept override;
+
+ [[nodiscard]] uint32_t get_column_cnt() const noexcept override;
+
+ [[nodiscard]] MatrixIterator<Element> begin() const noexcept override;
+
+ [[nodiscard]] MatrixIterator<Element> end() const noexcept override;
+
+ Matrix &operator=(const Matrix &rhs) noexcept;
+
+ Matrix &operator=(Matrix &&rhs) noexcept;
+
+private:
+ gsl::owner<Element **> _matrix;
+
+ uint32_t _row_cnt;
+ uint32_t _column_cnt;
+
+ void _delete_matrix() noexcept;
+
+ void _copy_matrix_from(const Matrix &source) noexcept;
+};
+
+#include "matrix.tpp"