Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAINT] Utils library Qt-less refactor (Part 1 of many) #881

Merged
merged 27 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9d659bd
Reproduce ioutils functionality without qt classes.
gabrielbmotta Jan 10, 2022
e3a0902
Reproduce kmeans functionality without qt classes.
gabrielbmotta Jan 10, 2022
7aa9e20
correct logic of looking for comments
gabrielbmotta Jan 10, 2022
f860e3b
fix logic of adding elements
gabrielbmotta Jan 10, 2022
cda4878
FIX: remove whitepace after reading
gabrielbmotta Jan 10, 2022
bc142de
Reproduce layoutloader functionality without qt classes.
gabrielbmotta Jan 10, 2022
5b92328
MAINT: use string::find where applicable instead of std::find
gabrielbmotta Jan 11, 2022
e0f9463
MAINT: fix warnings.
gabrielbmotta Jan 11, 2022
ea86740
MAINT: Reproduce layoutmaker functionality without qt classes.
gabrielbmotta Jan 11, 2022
cde4728
MAINT: Reproduce mnemath functionality without qt classes.
gabrielbmotta Jan 11, 2022
0559837
MAINT: change min c++ version to 17
gabrielbmotta Jan 11, 2022
5b50d49
MAINT: Reproduce selectionio functionality without qt classes.
gabrielbmotta Jan 11, 2022
e10348e
FIX: fix printing of vector
gabrielbmotta Jan 11, 2022
f8f15e1
MAINT: some of spectral functionality without qt classes.
gabrielbmotta Jan 11, 2022
d1c8575
MAINT: Reproduce warp functionality without qt classes.
gabrielbmotta Jan 11, 2022
7db07e2
MAINT: Add observerpattern overloads without qt classes.
gabrielbmotta Jan 11, 2022
325f15a
DEBUG: remove use of filesystem in fil.h/cpp
gabrielbmotta Jan 11, 2022
e6d6de7
FIX: remove use of filesystem lib, revert to c++ 14
gabrielbmotta Jan 11, 2022
8d005ca
FIX: rmeove include statement
gabrielbmotta Jan 11, 2022
917106a
MAINT: comment out overloads that result in ambiguous calls
gabrielbmotta Jan 12, 2022
4748902
FIX: also comment out declarations of oveloaded functions
gabrielbmotta Jan 12, 2022
4ce92df
MAINT: add QString explicitly to function calls
gabrielbmotta Jan 12, 2022
fe75f00
MAINT: restore commented string overloads
gabrielbmotta Jan 12, 2022
79b26e7
ENH: add skeleton of new test
gabrielbmotta Jan 13, 2022
0375822
DOC: updating author lists.
gabrielbmotta Jan 13, 2022
e3b9ff9
ENH: add test for commonly used circular buffer functionality.
gabrielbmotta Jan 13, 2022
937633a
Merge branch 'main' into byeqt
gabrielbmotta Jan 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/ex_hpiFit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,6 @@ int main(int argc, char *argv[])
<< "Average Duration:" << matPosition.col(9).mean() << "ms";

if(bSave) {
IOUtils::write_eigen_matrix(matPosition, QCoreApplication::applicationDirPath() + "/MNE-sample-data/" + sNameOut);
IOUtils::write_eigen_matrix(matPosition, QString(QCoreApplication::applicationDirPath() + "/MNE-sample-data/" + sNameOut));
}
}
2 changes: 1 addition & 1 deletion examples/ex_read_fwd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ int main(int argc, char *argv[])
qDebug() << "col_names:";
qDebug() << t_clusteredFwd.sol->col_names;
qDebug() << "write fwd data to ./test_fwd.txt ...";
IOUtils::write_eigen_matrix(t_clusteredFwd.sol->data,"./test_fwd.txt");
IOUtils::write_eigen_matrix(t_clusteredFwd.sol->data, QString("./test_fwd.txt"));
qDebug() << "[done]";

return app.exec();
Expand Down
2 changes: 1 addition & 1 deletion examples/ex_spectral/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int main(int argc, char *argv[])
}

//Generate hanning window
QPair<MatrixXd, VectorXd> tapers = Spectral::generateTapers(iNSamples, "hanning");
QPair<MatrixXd, VectorXd> tapers = Spectral::generateTapers(iNSamples, QString("hanning"));
MatrixXd matTaps = tapers.first;
VectorXd vecTapWeights = tapers.second;

Expand Down
25 changes: 0 additions & 25 deletions libraries/utils/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@
#include "file.h"
#include <fstream>

#if __cplusplus >= 201703L
#include <filesystem>
#else
#include <cstdio>
#endif

//=============================================================================================================
// USED NAMESPACES
Expand All @@ -57,12 +53,8 @@ using namespace UTILSLIB;

bool File::exists(const char* filePath)
{
#if __cplusplus >= 201703L
return std::filesystem::exists(filePath);
#else
std::ifstream infile(filePath);
return infile.good();
#endif
}

//=============================================================================================================
Expand All @@ -79,11 +71,6 @@ bool File::copy(const char* sourcePath, const char* destPath)
if (!exists(sourcePath) || exists(destPath)){
return false;
}

#if __cplusplus >= 201703L
std::filesystem::copy(sourcePath, destPath);
return exists(destPath);
#else
std::ifstream source(sourcePath, std::ios::binary);
std::ofstream destination(destPath, std::ios::binary);

Expand All @@ -92,7 +79,6 @@ bool File::copy(const char* sourcePath, const char* destPath)
} else {
return false;
}
#endif
}

//=============================================================================================================
Expand All @@ -109,13 +95,7 @@ bool File::rename(const char* sourcePath, const char* destPath)
if (!exists(sourcePath) || exists(destPath)){
return false;
}

#if __cplusplus >= 201703L
std::filesystem::rename(sourcePath, destPath);
return (!exists(sourcePath) && exists(destPath));
#else
return !std::rename(sourcePath, destPath); //std::rename returns 0 upon success
#endif
}

//=============================================================================================================
Expand All @@ -133,12 +113,7 @@ bool File::remove(const char* filePath)
return false;
}

#if __cplusplus >= 201703L
std::filesystem::remove(filePath);
return !exists(filePath);
#else
return !std::remove(filePath); //std::remove returns 0 upon success
#endif
}

//=============================================================================================================
Expand Down
3 changes: 3 additions & 0 deletions libraries/utils/generics/observerpattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ void Subject::notify()
t_Observers::const_iterator it = m_Observers.begin();
for( ; it != m_Observers.end(); ++it)
(*it)->update(this);
// for(auto observer : m_Observers){
// observer->update(this);
// }
}
}

Expand Down
15 changes: 15 additions & 0 deletions libraries/utils/generics/observerpattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
//=============================================================================================================

#include "../utils_global.h"
#include <set>

//=============================================================================================================
// QT INCLUDES
Expand Down Expand Up @@ -147,6 +148,14 @@ class UTILSSHARED_EXPORT Subject
*/
inline t_Observers& observers();

// //=========================================================================================================
// /**
// * Returns attached observers.

// * @return attached observers.
// */
// inline std::set<IObserver*>& observers();

//=========================================================================================================
/**
* Returns number of attached observers.
Expand All @@ -165,6 +174,7 @@ class UTILSSHARED_EXPORT Subject

private:
t_Observers m_Observers; /**< Holds the attached observers.*/
// std::set<IObserver*> m_Observers; /**< Holds the attached observers.*/
};

//=============================================================================================================
Expand All @@ -176,6 +186,11 @@ inline Subject::t_Observers& Subject::observers()
return m_Observers;
}

//inline std::set<IObserver*>& Subject::observers()
//{
// return m_Observers;
//}

} // Namespace

#endif // OBSERVERPATTERN_H
94 changes: 92 additions & 2 deletions libraries/utils/ioutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
/**
* @file ioutils.cpp
* @author Lorenz Esch <[email protected]>;
* Christoph Dinh <[email protected]>
* Christoph Dinh <[email protected]>;
* Gabriel Motta <[email protected]>
* @since 0.1.0
* @date March, 2013
*
* @section LICENSE
*
* Copyright (C) 2013, Lorenz Esch, Christoph Dinh. All rights reserved.
* Copyright (C) 2013, Lorenz Esch, Christoph Dinh, Gabriel Motta. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that
* the following conditions are met:
Expand Down Expand Up @@ -38,6 +39,8 @@
//=============================================================================================================

#include "ioutils.h"
#include <algorithm>
#include <regex>

//=============================================================================================================
// QT INCLUDES
Expand Down Expand Up @@ -73,6 +76,17 @@ qint32 IOUtils::fread3(QDataStream &p_qStream)

//=============================================================================================================

qint32 IOUtils::fread3(std::iostream& stream)
{
char* bytes = new char[3];
stream.read(bytes, 3);
qint32 int3 = (((unsigned char) bytes[0]) << 16) + (((unsigned char) bytes[1]) << 8) + ((unsigned char) bytes[2]);
delete[] bytes;
return int3;
}

//=============================================================================================================

VectorXi IOUtils::fread3_many(QDataStream &p_qStream, qint32 count)
{
VectorXi res(count);
Expand All @@ -83,6 +97,18 @@ VectorXi IOUtils::fread3_many(QDataStream &p_qStream, qint32 count)
return res;
}

//=============================================================================================================

VectorXi IOUtils::fread3_many(std::iostream& stream, qint32 count)
{
VectorXi res(count);

for(qint32 i = 0; i < count; ++i)
res[i] = IOUtils::fread3(stream);

return res;
}

//=============================================================================================================
//fiff_combat
qint16 IOUtils::swap_short(qint16 source)
Expand Down Expand Up @@ -253,6 +279,20 @@ QStringList IOUtils::get_new_chnames_conventions(const QStringList& chNames)

//=============================================================================================================

std::vector<std::string> IOUtils::get_new_chnames_conventions(const std::vector<std::string>& chNames)
{
std::vector<std::string> result;

for(auto channelName : chNames){
std::remove(channelName.begin(), channelName.end(), ' ');
result.push_back(std::move(channelName));
}

return result;
}

//=============================================================================================================

QStringList IOUtils::get_old_chnames_conventions(const QStringList& chNames)
{
QStringList result, xList;
Expand All @@ -276,6 +316,20 @@ QStringList IOUtils::get_old_chnames_conventions(const QStringList& chNames)

//=============================================================================================================

std::vector<std::string> IOUtils::get_old_chnames_conventions(const std::vector<std::string>& chNames)
{
std::vector<std::string> result;

for(auto channelName : chNames){
std::regex_replace(channelName, std::regex("[0-9]{1,100}"), " $&");
result.push_back(std::move(channelName));
}

return result;
}

//=============================================================================================================

bool IOUtils::check_matching_chnames_conventions(const QStringList& chNamesA, const QStringList& chNamesB, bool bCheckForNewNamingConvention)
{
bool bMatching = false;
Expand Down Expand Up @@ -322,3 +376,39 @@ bool IOUtils::check_matching_chnames_conventions(const QStringList& chNamesA, co

return bMatching;
}

//=============================================================================================================

bool IOUtils::check_matching_chnames_conventions(const std::vector<std::string>& chNamesA, const std::vector<std::string>& chNamesB, bool bCheckForNewNamingConvention)
{
if(chNamesA.empty()){
qWarning("Warning in IOUtils::check_matching_chnames_conventions - chNamesA list is empty. Nothing to compare");
}
if(chNamesB.empty()){
qWarning("Warning in IOUtils::check_matching_chnames_conventions - chNamesB list is empty. Nothing to compare");
}

bool bMatching = false;

for(size_t i = 0 ; i < chNamesA.size(); ++i){
if (std::find(chNamesB.begin(), chNamesB.end(), chNamesA.at(i)) != chNamesB.end()){
bMatching = true;
} else if(bCheckForNewNamingConvention){
std::string replaceStringNewConv{chNamesA.at(i)};
std::remove(replaceStringNewConv.begin(), replaceStringNewConv.end(), ' ');

if(std::find(chNamesB.begin(), chNamesB.end(), replaceStringNewConv) != chNamesB.end()){
bMatching = true;
} else {
std::string replaceStringOldConv{chNamesA.at(i)};
std::regex_replace(replaceStringOldConv, std::regex("[0-9]{1,100}"), " $&");
if(std::find(chNamesB.begin(), chNamesB.end(), replaceStringNewConv) != chNamesB.end() || std::find(chNamesB.begin(), chNamesB.end(), replaceStringOldConv) != chNamesB.end()){
bMatching = true;
} else {
bMatching = false;
}
}
}
}
return bMatching;
}
Loading