aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-06-06 11:10:29 +0100
committerYann Herklotz <ymherklotz@gmail.com>2017-06-06 11:10:29 +0100
commitd5b26e1a9428f7dd951dbf8ea08a5035620fa2e5 (patch)
tree90dad18c94ebb4269a3aa164c0cc0afedf277efb /include
parent4c16cca26bdae09525c04665b536da98beb4c76f (diff)
downloadYAGE-d5b26e1a9428f7dd951dbf8ea08a5035620fa2e5.tar.gz
YAGE-d5b26e1a9428f7dd951dbf8ea08a5035620fa2e5.zip
Building matrix
Diffstat (limited to 'include')
-rw-r--r--include/YAGE/Math/matrix.hpp39
1 files changed, 27 insertions, 12 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 <memory>
+#include <vector>
+
namespace yage
{
-template<typename Type, int Cols, int Rows> class Matrix
+template<int Rows, int Cols, class Type> class Matrix;
+
+template<int Rows, int Cols, class Type> class Row
{
+ friend class Matrix<Rows, Cols, Type>;
private:
- Type x[Cols][Rows];
+ std::shared_ptr<Matrix<Rows, Cols, Type>> parent_;
+ int index_;
public:
- Matrix()
+ Row<Rows, Cols, Type>(std::shared_ptr<Matrix<Rows, Cols, Type>> parent, int index) :
+ parent_(parent), index_(index)
+ {}
+
+ Type &operator[](int col)
{
- for(int i=0; i<Cols; ++i)
- {
- for(int j=0; j<Rows; ++j)
- {
- x[i][j]=5;
- }
- }
+ return parent_->data_[index_*Cols+col];
}
+};
+
+template<int Rows=4, int Cols=4, class Type=double> class Matrix
+{
+private:
+ std::vector<Type> data_;
+
+public:
+ Matrix<Rows, Cols, Type>() : data_(Rows*Cols) {}
+ Matrix<Rows, Cols, Type>(int rows, int cols) : data_(rows*cols) {}
- Type get(int i, int j) const
+ Row<Rows, Cols, Type> operator[](int row)
{
- return x[i][j];
+ return Row<Rows, Cols, Type>(std::make_shared<Matrix<Rows, Cols, Type>>(*this), row);
}
};