-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatrixContainer.cpp
63 lines (55 loc) · 1.54 KB
/
MatrixContainer.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "MatrixContainer.h"
MatrixContainer::MatrixContainer(MatrixSize size)
{
this->_elements.resize(size.getISize());
for(size_t i=0; i<size.getISize(); i++) {
this->_elements[i].resize(size.getJSize());
}
this->_size = size;
}
MatrixSize MatrixContainer::getSize()
{
return _size;
}
MatrixContainer::MatrixContainer(Mtx_Mtx elements)
{
for(size_t i=0; i<elements.size(); i++) {
if(i+1 < elements.size() && elements[i].size() != elements[i+1].size()) {
throw new MatrixException(MatrixException::Container, "Error constructing matrix, vector isn't balanced");
}
}
this->_elements = elements;
this->_size = MatrixSize(elements.size(), elements[0].size());
}
Number& MatrixContainer::operator()(size_t i, size_t j)
{
if(i < _size.getISize() && j < _size.getJSize()) {
return _elements[i][j];
}
else {
throw new MatrixException(MatrixException::OutOfRange, "Index out of range");
}
}
MatrixContainer::~MatrixContainer()
{
}
MatrixContainer::MatrixContainer(const MatrixContainer& elements)
{
this->_elements = Mtx_Mtx(elements._elements);
this->_size = elements._size;
}
MatrixContainer::MatrixContainer()
{
this->_elements = Mtx_Mtx();
this->_size = MatrixSize(0,0);
}
void MatrixContainer::swapRows(size_t from, size_t to)
{
if(from >= this->_elements.size() || to >= this->_elements.size()) {
throw new MatrixException(MatrixException::OutOfRange, "Error swapping rows");
}
Mtx_Array tmp;
tmp = this->_elements[from];
this->_elements[from] = this->_elements[to];
this->_elements[to] = tmp;
}