From d5b26e1a9428f7dd951dbf8ea08a5035620fa2e5 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Tue, 6 Jun 2017 11:10:29 +0100 Subject: Building matrix --- include/YAGE/Math/matrix.hpp | 39 +++++++++++++++++++++++++++------------ test/matrix_test.cpp | 6 +++--- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp index b6807c09..76c90c16 100644 --- a/include/YAGE/Math/matrix.hpp +++ b/include/YAGE/Math/matrix.hpp @@ -1,29 +1,44 @@ #ifndef YAGE_MATH_MATRIX_HPP #define YAGE_MATH_MATRIX_HPP +#include +#include + namespace yage { -template class Matrix +template class Matrix; + +template class Row { + friend class Matrix; private: - Type x[Cols][Rows]; + std::shared_ptr> parent_; + int index_; public: - Matrix() + Row(std::shared_ptr> parent, int index) : + parent_(parent), index_(index) + {} + + Type &operator[](int col) { - for(int i=0; idata_[index_*Cols+col]; } +}; + +template class Matrix +{ +private: + std::vector data_; + +public: + Matrix() : data_(Rows*Cols) {} + Matrix(int rows, int cols) : data_(rows*cols) {} - Type get(int i, int j) const + Row operator[](int row) { - return x[i][j]; + return Row(std::make_shared>(*this), row); } }; diff --git a/test/matrix_test.cpp b/test/matrix_test.cpp index 8f09ad38..ba1f0d4a 100644 --- a/test/matrix_test.cpp +++ b/test/matrix_test.cpp @@ -4,10 +4,10 @@ int main() { - yage::Matrix matrix; - - int x=matrix.get(5, 2); + yage::Matrix<4, 4, int> matrix; + int x=matrix[2][2]; + std::cout<<"at: "<