/
class_double_array.cpp
44 lines (39 loc) · 1.05 KB
/
class_double_array.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
#include "class_double_array.h"
#include <cstdlib>
class_double_array::class_double_array() {
width = 0;
height = 0;
value = nullptr;
}
class_double_array::class_double_array(const class_double_array &cda2) {
width = cda2.width;
height = cda2.height;
value = nullptr;
if(cda2.value != nullptr) {
value = (double*) calloc(height * width, sizeof(double));
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
value[j + i * height] = cda2.value[j + i * height];
}
}
}
}
//First row filled from left to right..and so on for other rows
void class_double_array::reset() {
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
value[j + i * height] = 0.0;
}
}
}
void class_double_array::alloc(const int &h, const int &w) {
width = w;
height = h;
value = (double *) calloc(h * w, sizeof(double));
}
void class_double_array::free() {
width = 0;
height = 0;
::free(value);
value = nullptr;
}