-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArmaMatrix.cpp
174 lines (145 loc) · 3.62 KB
/
ArmaMatrix.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "ArmaMatrix.h"
ArmaMatrix::ArmaMatrix(AMDATATYPE dataType)
{
m_dataType = dataType;
switch (m_dataType) {
case AMDATATYPE_int:
m_pDataInt = new arma::Mat<int>();
break;
case AMDATATYPE_double:
m_pDataDouble = new arma::Mat<double>();
break;
case AMDATATYPE_float:
m_pDataFloat = new arma::Mat<float>();
break;
default:
// "not support data type of Q3TTableModel"
Q_ASSERT(false);
break;
}
}
ArmaMatrix::~ArmaMatrix()
{
switch (m_dataType) {
case AMDATATYPE_int:
delete m_pDataInt;
break;
case AMDATATYPE_double:
delete m_pDataDouble;
break;
case AMDATATYPE_float:
delete m_pDataFloat;
break;
default:
// "not support data type of Q3TTableModel"
Q_ASSERT(false);
break;
}
}
#define RUN_METHOD(_codes) \
switch (m_dataType) { \
case AMDATATYPE_int: \
m_pDataInt->_codes; \
break; \
case AMDATATYPE_double: \
m_pDataDouble->_codes; \
break; \
case AMDATATYPE_float: \
m_pDataFloat->_codes; \
break; \
default: \
Q_ASSERT(false); \
break; \
} \
#define RUN_METHOD_RETURN(_codes) \
switch (m_dataType) { \
case AMDATATYPE_int: \
return m_pDataInt->_codes; \
case AMDATATYPE_double: \
return m_pDataDouble->_codes; \
case AMDATATYPE_float: \
return m_pDataFloat->_codes; \
default: \
Q_ASSERT(false); \
break; \
} \
arma::uword ArmaMatrix::rowCount() const
{
RUN_METHOD_RETURN(n_rows)
return 0;
}
arma::uword ArmaMatrix::columnCount() const
{
RUN_METHOD_RETURN(n_cols)
return 0;
}
void ArmaMatrix::setSize(arma::uword rowCount, arma::uword columnCount)
{
RUN_METHOD(set_size(rowCount,columnCount))
RUN_METHOD(fill(0))
}
void ArmaMatrix::resize(arma::uword rowCount, arma::uword columnCount)
{
RUN_METHOD(resize(rowCount, columnCount))
RUN_METHOD(fill(0))
}
void ArmaMatrix::insertRows(arma::uword row, arma::uword count)
{
RUN_METHOD(insert_rows(row, count))
}
void ArmaMatrix::insertColumns(arma::uword column, arma::uword count)
{
RUN_METHOD(insert_cols(column, count))
}
bool ArmaMatrix::canConvert(const QVariant &value) const
{
QVariant valueTemp = value;
switch (m_dataType) {
case AMDATATYPE_int:
return valueTemp.convert(QVariant::Int);
case AMDATATYPE_double:
return valueTemp.convert(QVariant::Double);
case AMDATATYPE_float:
return valueTemp.convert(QMetaType::Float);
default:
// "not support data type of Q3TTableModel"
Q_ASSERT(false);
break;
}
return false;
}
QVariant ArmaMatrix::data(arma::uword row, arma::uword column) const
{
switch (m_dataType) {
case AMDATATYPE_int:
return QVariant((*m_pDataInt)(row, column));
case AMDATATYPE_double:
return QVariant((*m_pDataDouble)(row, column));
case AMDATATYPE_float:
return QVariant((*m_pDataFloat)(row, column));
default:
// "not support data type of Q3TTableModel"
Q_ASSERT(false);
break;
}
return QVariant(QVariant::Invalid);
}
bool ArmaMatrix::setData(arma::uword row, arma::uword column, const QVariant &value)
{
switch (m_dataType) {
case AMDATATYPE_int:
(*m_pDataInt)(row, column) = value.toInt();
break;
case AMDATATYPE_double:
(*m_pDataDouble)(row, column) = value.toDouble();
break;
case AMDATATYPE_float:
(*m_pDataFloat)(row, column) = value.toFloat();
break;
default:
// "not support data type of Q3TTableModel"
Q_ASSERT(false);
return false;
}
return true;
}