forked from zpb1992/ReentryTrajectoryGuide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Array3.h
129 lines (112 loc) · 2.38 KB
/
Array3.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#pragma once
// 没有bool的都是浅拷贝 我感觉数据量有些大 25000*300个double
template<typename T>
class Array3
{
public:
Array3(T **array, unsigned *column, unsigned row, bool deepCopy = false);
Array3(T **array, unsigned column, unsigned row, bool deepCopy = false);
Array3(const Array3 &a);
Array3(Array3 &&a) noexcept;
Array3 &operator =(const Array3 &a);
Array3 &operator =(Array3 &&a);
~Array3();
public:
T **_array;
unsigned *_column;
unsigned _row;
private:
bool _deepCopy;
private:
bool create(T **array, unsigned *column, unsigned row, bool deepCopy = false);
};
template<typename T>
inline Array3<T>::Array3(T ** array, unsigned * column, unsigned row, bool deepCopy)
{
create(array, column, row, deepCopy);
}
template<typename T>
inline Array3<T>::Array3(T ** array, unsigned column, unsigned row, bool deepCopy)
{
unsigned *col = new unsigned[row];
for (unsigned i = 0; i < row; ++i)
{
col[i] = column;
}
create(array, col, row, deepCopy);
//delete col;
}
template<typename T>
inline Array3<T>::~Array3()
{
if (_deepCopy)
{
delete _column;
for (unsigned i = 0; i < _row; ++i)
{
delete _array[i];
}
delete _array;
}
}
template<typename T>
inline Array3<T>::Array3(const Array3 & a) :Array3(a._array, a._column, a._row, false)
{
}
template<typename T>
inline Array3<T>::Array3(Array3 && a) noexcept
{
_deepCopy = true;
_array = a._array;
_column = a._column;
_row = a._row;
a._array = nullptr;
a._column = a._column;
a._row = 0;
}
template<typename T>
inline Array3<T> & Array3<T>::operator=(const Array3 & a)
{
// TODO: insert return statement here
create(a._array, a._column, a._row, false);
return *this;
}
template<typename T>
inline Array3<T> & Array3<T>::operator=(Array3 && a)
{
// TODO: insert return statement here
_deepCopy = true;
_array = a._array;
_column = a._column;
_row = a._row;
a._array = nullptr;
a._column = a._column;
a._row = 0;
}
template<typename T>
inline bool Array3<T>::create(T ** array, unsigned * column, unsigned row, bool deepCopy)
{
_deepCopy = deepCopy;
if (deepCopy)
{
_row = row;
_column = new unsigned[row];
_array = new T *[row];
for (unsigned i = 0; i < row; ++i)
{
_column[i] = column[i];
_array[i] = new T[_column[i]];
for (unsigned j = 0; j < _column[i]; ++j)
{
_array[i][j] = array[i][j];
}
}
}
else
{
_row = row;
_column = column;
_array = array;
}
return true;
}