aboutsummaryrefslogtreecommitdiffstats
path: root/include/YAGE/Math/matrix.hpp
blob: 76c90c16b148a6536544886349aeee83887126cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef YAGE_MATH_MATRIX_HPP
#define YAGE_MATH_MATRIX_HPP

#include <memory>
#include <vector>

namespace yage
{

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:
	std::shared_ptr<Matrix<Rows, Cols, Type>> parent_;
	int index_;

public:
	Row<Rows, Cols, Type>(std::shared_ptr<Matrix<Rows, Cols, Type>> parent, int index) :
		parent_(parent), index_(index)
	{}

	Type &operator[](int col)
	{
		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) {}

	Row<Rows, Cols, Type> operator[](int row)
	{
		return Row<Rows, Cols, Type>(std::make_shared<Matrix<Rows, Cols, Type>>(*this), row);
	}
};

} // yage

#endif