-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix.h
executable file
·55 lines (44 loc) · 952 Bytes
/
matrix.h
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
#ifndef MATRIX_H
#define MATRIX_H
#include <QVector>
#include <cstdarg>
template<class T>
class Matrix {
QVector< QVector<T> > data;
int h, w;
public:
Matrix() {h = 0; w = 0;}
Matrix(int lh, int lw) {
w = lw;
h = lh;
data.fill(QVector<T>(w), h);
}
Matrix(bool init, int lh, int lw, ...) {
w = lw;
h = lh;
data.fill(QVector<T>(w), h);
if (init) {
va_list vl;
va_start(vl, lw);
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
data[i][j] = va_arg(vl, T);
va_end(vl);
}
}
void fill(T val) {
foreach (QVector<T> line, data) {
line.fill(val);
}
}
T& operator () (int i, int j) {
return data[i][j];
}
int height() {
return h;
}
int width() {
return w;
}
};
#endif // MATRIX_H