-
Notifications
You must be signed in to change notification settings - Fork 5
/
myglobals.h
111 lines (95 loc) · 3.22 KB
/
myglobals.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
#pragma once
//#include <vld.h>
#include <memory>
#include <sstream>
#include <iostream>
#include <ctime>
#include <QTCore/QtConcurrentRun>
#include <QTCore/QString>
#include <QFuture>
#include "Libraries/Logger.h"
#define qtawait(theType, theCall) ([&]()->theType{ \
QEventLoop el; \
QFuture<theType> theResult;\
auto threadLambda = [&]()->theType{ \
bool succ = QObject::connect(QThread::currentThread(), SIGNAL(finished()), &el, SLOT(quit())); \
theType result = theCall; \
el.quit(); \
qDebug() << "finished async function with return value" ; \
return result; \
}; \
theResult = QtConcurrent::run((function<theType()>)threadLambda); \
el.exec(); \
return theResult.result(); \
}())
#define qtawait_void(theCall) ([&]{ \
QEventLoop el; \
auto threadLambda = [&]{ \
bool succ = QObject::connect(QThread::currentThread(), SIGNAL(finished()), &el, SLOT(quit())); \
theCall; \
el.quit(); \
qDebug() << "finished void async function";\
}; \
QtConcurrent::run((function<void()>)threadLambda); \
el.exec(); \
}())
#define qtawait_local_statments(theBody) { \
QEventLoop el; \
auto threadLambda = [&]{ \
try \
{ \
bool succ = QObject::connect(QThread::currentThread(), SIGNAL(finished()), &el, SLOT(quit())); \
theBody; \
el.quit(); \
/*qDebug() << "finished async local statments";*/ \
} \
catch(std::exception e) \
{\
std::cout<<"Exception in qtawait_local_statements : "<<e.what() <<endl; \
throw e; \
} \
}; \
QtConcurrent::run(threadLambda); \
/*QtConcurrent::run((function<void()>)threadLambda); */\
el.exec(); \
}
#ifdef LOG_ENABLED
#define stream_to_log(theStream) {stream_to_log_inner(theStream)}
#define stream_to_log_sameLine(theStream) {stream_to_log_inner_sameLine(theStream)}
#else
#define stream_to_log(theStream)
#define stream_to_log_sameLine(theStream)
#endif
#define stream_to_log_inner(theStream) { using namespace HyperSpectralToolbox; \
auto sp_ofstream = Logger::openStream(); \
(*sp_ofstream) << theStream << "\n"; \
sp_ofstream->close(); \
std::cout << theStream <<endl; \
}
#define stream_to_log_inner_sameLine(theStream) { using namespace HyperSpectralToolbox; \
auto sp_ofstream = Logger::openStream(); \
(*sp_ofstream) << theStream; \
sp_ofstream->close(); \
std::cout << theStream; \
}
//#define ts(theTokens) ([&]()->std::string { std::stringstream sst; sst << theTokens; return sst.str();}())
template <typename T>
inline std::string ts( const T & theToken ) {
std::ostringstream os;
os << theToken;
return os.str();
}
template <typename T>
inline QString tqs( const T & theToken ) {
std::ostringstream os;
os << theToken;
return QString(os.str().c_str());
}
#define shnew(theType, constructorArgs) \
make_shared<theType>(theType constructorArgs )
#define shptr(theType) std::shared_ptr<theType>
#include "Libraries/HSWO.h"
struct MyFutureResult{
std::shared_ptr<HyperSpectralToolbox::HSWO> spHswo;
QFuture<void> future;
};