-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.h
75 lines (64 loc) · 3.19 KB
/
report.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
#ifndef REPORT_H
#define REPORT_H
#include <QDebug>
#define INITIALIZE(type, futureInterface) \
auto future = static_cast<QFutureInterface<type>*>(futureInterface); \
future->setProgressRange(0, 100); \
future->setProgressValue(0);
#define FINALIZE(result) \
future->setProgressValue(100); \
future->reportResult(result); \
return result;
#define REPORT(progress, result) \
future->reportResult(result); \
future->setProgressValue(progress); \
#define REPORT_RESULT_UNSAFE(result) \
if (future->isProgressUpdateNeeded()) { \
if (future->isPaused()) \
future->waitForResume(); \
if (future->isCanceled()) \
return 0; \
future->reportResult(result); \
}
#define REPORT_PROGRESS_SAFE(progress, zip) \
if (future->isProgressUpdateNeeded()) { \
if (future->isPaused()) \
future->waitForResume(); \
if (future->isCanceled()) { \
if (zip.m_zip_mode == MZ_ZIP_MODE_READING) { \
mz_zip_reader_end(&zip); \
} else { \
mz_zip_writer_finalize_archive(&zip); \
mz_zip_writer_end(&zip); \
} \
return 0; \
} \
future->setProgressValue(progress); \
}
namespace ZipAsync {
namespace Internal {
inline QString& combineStringArguments(QString& str) { return str; }
template <typename First, typename... Rest>
QString& combineStringArguments(QString& msg, First&& first, Rest&&... rest)
{
msg = msg.arg(first);
return combineStringArguments(msg, std::forward<Rest>(rest)...);
}
} // Internal
int WARNING(const char* msg, ...)
{
va_list ap;
va_start(ap, msg);
qWarning(msg, ap);
va_end(ap);
return 0;
}
template <typename Future, typename... Args>
int CRASH(Future future, QString msg, Args&&... args)
{
future->setProgressValueAndText(100, Internal::combineStringArguments(msg, std::forward<Args>(args)...));
future->reportResult(size_t(0));
return 0;
}
} // ZipAsync
#endif // REPORT_H