-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathutils.h
50 lines (41 loc) · 1001 Bytes
/
utils.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
#ifndef UTILS_H
#define UTILS_H
#include <QString>
#include <QTextStream>
#include <QMetaEnum>
#define STRINGIFY0(x) #x
#define STRINGIFY(x) STRINGIFY0(x)
template <typename Last>
QString toStr(const Last& last) {
QString str;
QTextStream stream(&str);
stream << last;
return str;
}
template <typename First, typename ...Rest>
QString toStr(const First& first, Rest&&... args) {
QString str;
QTextStream stream(&str);
stream << first << " ";
return str + toStr(args...);
}
template<typename E>
QString enumToString (const E value) {
const auto metaEnum = QMetaEnum::fromType<E>();
return metaEnum.valueToKey(static_cast<int>(value));
}
class RAII_ {
public:
using Deldelegate = std::function<void()>;
RAII_(const Deldelegate& d) : m_d(d) {}
~RAII_() {m_d();}
private:
Deldelegate m_d;
};
#ifndef QT5
inline QByteArray& operator+=(QByteArray& ba, const QString& qstr) {
ba += qstr.toUtf8();
return ba;
}
#endif
#endif // UTILS_H