diff options
author | Nao Pross <naopross@thearcway.org> | 2019-10-05 17:59:32 +0200 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2019-10-05 17:59:32 +0200 |
commit | cbcb6aeb1510ee1bd2d67d9d0b285df67f7088b5 (patch) | |
tree | e2e73adfbb34f1ce43986635429f7207519c2815 /include/mm/view.hpp | |
parent | Implicit convertion to basic_vec to vec2 or vec3 (diff) | |
download | libmm-cbcb6aeb1510ee1bd2d67d9d0b285df67f7088b5.tar.gz libmm-cbcb6aeb1510ee1bd2d67d9d0b285df67f7088b5.zip |
New matrix data model (breaks everything)
Diffstat (limited to 'include/mm/view.hpp')
-rw-r--r-- | include/mm/view.hpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/include/mm/view.hpp b/include/mm/view.hpp new file mode 100644 index 0000000..910c16a --- /dev/null +++ b/include/mm/view.hpp @@ -0,0 +1,66 @@ +#pragma once + +#include <mmmatrix.hpp> + + +namespace mm::alg { + + template < + template<typename, std::size_t, std::size_t> typename Matrix, + typename T, std::size_t Rows, std::size_t Cols + > + struct visitor + { + using type = T; + + // copy constructible + visitor(const visitor& other) = default; + + T& operator()(const Matrix<T, Rows, Cols>& m, index row, index col) { + return m.at(row, col); + } + + const T& operator()(const Matrix<T, Rows, Cols>& m, index row, index col) { + return operator()(m, row, col); + } + }; + + template < + template<typename, std::size_t, std::size_t> typename Matrix, + typename T, std::size_t Rows, std::size_t Cols + > + struct transpose : public visitor<Matrix, T, Rows, Cols> + { + T& operator()(const Matrix<T, Rows, Cols> m, index row, index col) { + // assert(col < Rows) + // assert(row < Cols) + return m.at(col, row); + } + }; +} + +namespace mm { + template < + template<typename, std::size_t, std::size_t> typename Matrix, + typename T, std::size_t Rows, std::size_t Cols + > + struct view + { + Matrix<T, Rows, Cols>& m; + // std::stack<std::unique_ptr<alg::visitor>> visitors; + std::unique_ptr<alg::visitor> visitor; + + T& at(index row, index col) { + return visitor(m, row, col); + } + + view& operator|=(const alg::visitor& other) { + // visitors.push(std::move(std::make_unique<alg::visitor>(other))); + visitor = std::make_unique<alg::visistor>(other); + } + }; + + view operator|(const view& left, const alg::visitor& right) { + return left |= right; + } +} |