-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
MiniMatrix.h
60 lines (48 loc) · 1.77 KB
/
MiniMatrix.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
56
57
58
59
60
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2023, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+
/*
* This file is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// Prevents processing this includes file for the second time.
#ifndef MINIMATRIX_MQH
#define MINIMATRIX_MQH
template <typename T>
class MiniMatrix2d {
public:
T data[];
int size_x;
int size_y;
MiniMatrix2d() {}
MiniMatrix2d(int _size_x, int _size_y) : size_x(_size_x), size_y(_size_y) { Resize(_size_x, _size_y); }
void Resize(int _size_x, int _size_y) {
ArrayResize(data, _size_x * _size_y);
size_x = _size_x;
size_y = _size_y;
}
T Get(int _x, int _y) { return data[(size_x * _y) + _x]; }
void Set(int _x, int _y, T _value) {
int index = (size_x * _y) + _x;
if (index < 0 || index >= (size_x * size_y)) {
Alert("Array out of range!");
}
data[index] = _value;
}
int SizeX() { return size_x; }
int SizeY() { return size_y; }
};
#endif