49 #include <QDataStream>
50 #include <QRegularExpression>
62 using namespace Eigen;
63 using namespace UTILSLIB;
69 qint32 IOUtils::fread3(QDataStream &p_qStream)
71 char* bytes =
new char[3];
72 p_qStream.readRawData(bytes, 3);
73 qint32 int3 = (((
unsigned char) bytes[0]) << 16) + (((
unsigned char) bytes[1]) << 8) + ((
unsigned char) bytes[2]);
80 qint32 IOUtils::fread3(std::iostream& stream)
82 char* bytes =
new char[3];
83 stream.read(bytes, 3);
84 qint32 int3 = (((
unsigned char) bytes[0]) << 16) + (((
unsigned char) bytes[1]) << 8) + ((
unsigned char) bytes[2]);
91 VectorXi IOUtils::fread3_many(QDataStream &p_qStream, qint32 count)
95 for(qint32 i = 0; i < count; ++i)
96 res[i] = IOUtils::fread3(p_qStream);
103 VectorXi IOUtils::fread3_many(std::iostream& stream, qint32 count)
107 for(qint32 i = 0; i < count; ++i)
108 res[i] = IOUtils::fread3(stream);
115 qint16 IOUtils::swap_short(qint16 source)
117 unsigned char *csource = (
unsigned char *)(&source);
119 unsigned char *cresult = (
unsigned char *)(&result);
121 cresult[0] = csource[1];
122 cresult[1] = csource[0];
128 qint32 IOUtils::swap_int(qint32 source)
130 unsigned char *csource = (
unsigned char *)(&source);
132 unsigned char *cresult = (
unsigned char *)(&result);
134 cresult[0] = csource[3];
135 cresult[1] = csource[2];
136 cresult[2] = csource[1];
137 cresult[3] = csource[0];
143 void IOUtils::swap_intp(qint32 *source)
146 unsigned char *csource = (
unsigned char *)(source);
151 csource[3] = csource[0];
154 csource[2] = csource[1];
162 qint64 IOUtils::swap_long(qint64 source)
164 unsigned char *csource = (
unsigned char *)(&source);
166 unsigned char *cresult = (
unsigned char *)(&result);
168 cresult[0] = csource[7];
169 cresult[1] = csource[6];
170 cresult[2] = csource[5];
171 cresult[3] = csource[4];
172 cresult[4] = csource[3];
173 cresult[5] = csource[2];
174 cresult[6] = csource[1];
175 cresult[7] = csource[0];
181 void IOUtils::swap_longp(qint64 *source)
183 unsigned char *csource = (
unsigned char *)(source);
187 csource[0] = csource[7];
191 csource[1] = csource[6];
195 csource[2] = csource[5];
199 csource[3] = csource[4];
207 float IOUtils::swap_float(
float source)
209 unsigned char *csource = (
unsigned char *)(&source);
211 unsigned char *cresult = (
unsigned char *)(&result);
213 cresult[0] = csource[3];
214 cresult[1] = csource[2];
215 cresult[2] = csource[1];
216 cresult[3] = csource[0];
222 void IOUtils::swap_floatp(
float *source)
225 unsigned char *csource = (
unsigned char *)(source);
229 csource[3] = csource[0];
232 csource[2] = csource[1];
240 void IOUtils::swap_doublep(
double *source)
243 unsigned char *csource = (
unsigned char *)(source);
247 csource[7] = csource[0];
251 csource[6] = csource[1];
255 csource[5] = csource[2];
259 csource[4] = csource[3];
267 QStringList IOUtils::get_new_chnames_conventions(
const QStringList& chNames)
270 QString replaceString;
272 for(
int i = 0; i < chNames.size(); ++i) {
273 replaceString = chNames.at(i);
274 replaceString.replace(
" ",
"");
275 result.append(replaceString);
283 std::vector<std::string> IOUtils::get_new_chnames_conventions(
const std::vector<std::string>& chNames)
285 std::vector<std::string> result;
287 for(
auto channelName : chNames){
288 std::remove(channelName.begin(), channelName.end(),
' ');
289 result.push_back(std::move(channelName));
297 QStringList IOUtils::get_old_chnames_conventions(
const QStringList& chNames)
299 QStringList result, xList;
300 QString replaceString;
301 QRegularExpression xRegExp;
303 for(
int i = 0; i < chNames.size(); ++i) {
304 xRegExp = QRegularExpression(
"[0-9]{1,100}");
305 QRegularExpressionMatch match = xRegExp.match(chNames.at(i));
306 xList = match.capturedTexts();
308 for(
int k = 0;
k < xList.size(); ++
k) {
309 replaceString = chNames.at(i);
310 replaceString.replace(xList.at(
k),QString(
"%1%2").arg(
" ").arg(xList.at(
k)));
311 result.append(replaceString);
320 std::vector<std::string> IOUtils::get_old_chnames_conventions(
const std::vector<std::string>& chNames)
322 std::vector<std::string> result;
324 for(
auto channelName : chNames){
325 std::regex_replace(channelName, std::regex(
"[0-9]{1,100}"),
" $&");
326 result.push_back(std::move(channelName));
334 bool IOUtils::check_matching_chnames_conventions(
const QStringList& chNamesA,
const QStringList& chNamesB,
bool bCheckForNewNamingConvention)
336 bool bMatching =
false;
338 if(chNamesA.isEmpty()) {
339 qWarning(
"Warning in IOUtils::check_matching_chnames_conventions - chNamesA list is empty. Nothing to compare");
342 if(chNamesB.isEmpty()) {
343 qWarning(
"Warning in IOUtils::check_matching_chnames_conventions - chNamesB list is empty. Nothing to compare");
346 QString replaceStringOldConv, replaceStringNewConv;
348 for(
int i = 0; i < chNamesA.size(); ++i) {
349 if(chNamesB.contains(chNamesA.at(i))) {
351 }
else if(bCheckForNewNamingConvention) {
353 replaceStringNewConv = chNamesA.at(i);
354 replaceStringNewConv.replace(
" ",
"");
356 if(chNamesB.contains(replaceStringNewConv)) {
360 QRegularExpression xRegExp(
"[0-9]{1,100}");
361 QRegularExpressionMatch match = xRegExp.match(chNamesA.at(i));
362 QStringList xList = match.capturedTexts();
364 for(
int k = 0;
k < xList.size(); ++
k) {
365 replaceStringOldConv = chNamesA.at(i);
366 replaceStringOldConv.replace(xList.at(
k),QString(
"%1%2").arg(
" ").arg(xList.at(
k)));
368 if(chNamesB.contains(replaceStringNewConv) || chNamesB.contains(replaceStringOldConv) ) {
383 bool IOUtils::check_matching_chnames_conventions(
const std::vector<std::string>& chNamesA,
const std::vector<std::string>& chNamesB,
bool bCheckForNewNamingConvention)
385 if(chNamesA.empty()){
386 qWarning(
"Warning in IOUtils::check_matching_chnames_conventions - chNamesA list is empty. Nothing to compare");
388 if(chNamesB.empty()){
389 qWarning(
"Warning in IOUtils::check_matching_chnames_conventions - chNamesB list is empty. Nothing to compare");
392 bool bMatching =
false;
394 for(
size_t i = 0 ; i < chNamesA.size(); ++i){
395 if (std::find(chNamesB.begin(), chNamesB.end(), chNamesA.at(i)) != chNamesB.end()){
397 }
else if(bCheckForNewNamingConvention){
398 std::string replaceStringNewConv{chNamesA.at(i)};
399 std::remove(replaceStringNewConv.begin(), replaceStringNewConv.end(),
' ');
401 if(std::find(chNamesB.begin(), chNamesB.end(), replaceStringNewConv) != chNamesB.end()){
404 std::string replaceStringOldConv{chNamesA.at(i)};
405 std::regex_replace(replaceStringOldConv, std::regex(
"[0-9]{1,100}"),
" $&");
406 if(std::find(chNamesB.begin(), chNamesB.end(), replaceStringNewConv) != chNamesB.end() || std::find(chNamesB.begin(), chNamesB.end(), replaceStringOldConv) != chNamesB.end()){