ACF $AcfVersion:0$
istd.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// STL includes
6#include <limits>
7
8// Qt includes
9#include <QtCore/QtGlobal>
10#include <QtCore/QByteArray>
11#include <QtCore/QString>
12#include <QtCore/QStringList>
13
14
21namespace istd
22{
23} // namespace istd
24
25
26static const double I_BIG_EPSILON = 1.0e-8;
27
31#define I_EPSILON std::numeric_limits<double>::epsilon()
32
33
37#define I_HUGE_NUMBER 10e20
38
39
43#define I_INFINITY std::numeric_limits<double>::infinity()
44
45
49static const QChar QCHAR_POW2 = QChar(0x00B2);
50static const QChar QCHAR_POW3 = QChar(0x00B3);
51static const QChar QCHAR_DEGREE = QChar(0x00B0);
52static const QChar QCHAR_PERMILLE = QChar(0x2030);
53
54
55
56#ifndef QT_NO_DEBUG
57
58
59#define I_IF_DEBUG(instructions) instructions
60#define I_CRITICAL() Q_ASSERT(false)
61
62
63#else // !QT_NO_DEBUG
64
65
66#define I_CRITICAL()
67#define I_IF_DEBUG(instructions)
68
69
70#endif // !QT_NO_DEBUG
71
72
73#ifndef NULL
74#define NULL 0
75#endif // !NULL
76
77
81#define I_ENUM_GET_VALUES(Enum, ...)\
82 static QList<int> Enum##GetValues(){\
83 QList<int> values;\
84 int vars[] = {0, __VA_ARGS__};\
85 int count = (sizeof(vars) / sizeof(int));\
86 for(int i = 0; i < count; ++i){\
87 if (i > 0){\
88 values << vars[i];\
89 }\
90 }\
91 return values;\
92 }
93
97#define I_ENUM_GET_STRINGS(Enum, ...)\
98 static QStringList Enum##GetStrings(){\
99 QString enumValuesString = #__VA_ARGS__;\
100 QStringList values = enumValuesString.split(",");\
101 for (int i = 0; i < values.count(); ++i){\
102 QString rawValue = values[i].simplified();\
103 QStringList splitNames = rawValue.split("_");\
104 if (splitNames.isEmpty()){\
105 values[i] = rawValue;\
106 }\
107 else{\
108 QString formattedValue = rawValue;\
109 for (int partIndex = 1; partIndex < splitNames.count(); ++partIndex){\
110 QString partValue = splitNames[partIndex].toLower();\
111 if (partIndex == 1){\
112 formattedValue = partValue;\
113 }\
114 else{\
115 formattedValue += partValue.at(0).toUpper() + partValue.mid(1);\
116 }\
117 }\
118 values[i] = formattedValue;\
119 }\
120 }\
121 return values;\
122 }
123
127#define I_DECLARE_ENUM(Enum, ...)\
128 I_ENUM_GET_VALUES(Enum, __VA_ARGS__)\
129 I_ENUM_GET_STRINGS(Enum, __VA_ARGS__)\
130 static QByteArray ToString(Enum enumValue){\
131 static QByteArray emptyString;\
132 QStringList values = Enum##GetStrings();\
133 QList<int> enumValues = Enum##GetValues();\
134 Q_ASSERT(enumValues.count() == values.count());\
135 for (int i = 0; i < enumValues.count(); ++i){\
136 if (enumValues[i] == enumValue){\
137 return values[i].toUtf8();\
138 }\
139 }\
140 return emptyString;\
141 }\
142 static bool FromString(const QByteArray& enumString, Enum& enumValue){\
143 QStringList values = Enum##GetStrings();\
144 QList<int> enumValues = Enum##GetValues();\
145 Q_ASSERT(enumValues.count() == values.count());\
146 for (int i = 0; i < enumValues.count(); ++i){\
147 if (values[i].toUtf8() == enumString){\
148 enumValue = Enum(enumValues[i]);\
149 return true;\
150 }\
151 }\
152 return false;\
153 }
154
155#define I_DECLARE_FLAGS(Enum, ...)\
156 I_ENUM_GET_VALUES(Enum, __VA_ARGS__)\
157 I_ENUM_GET_STRINGS(Enum, __VA_ARGS__)\
158 static QByteArray Enum##ToString(int flags){\
159 QByteArray retVal;\
160 QStringList values = Enum##GetStrings();\
161 QList<int> enumValues = Enum##GetValues();\
162 Q_ASSERT(enumValues.count() == values.count());\
163 for (int i = 0; i < enumValues.count(); ++i){\
164 if (enumValues[i] & flags){\
165 if (!retVal.isEmpty()){\
166 retVal += "|";\
167 }\
168 retVal += values[i].toUtf8();\
169 }\
170 }\
171 return retVal;\
172 }\
173 static bool Enum##FromString(const QByteArray& enumString, int& flags){\
174 QStringList values = Enum##GetStrings();\
175 QList<int> enumValues = Enum##GetValues();\
176 flags = 0;\
177 Q_ASSERT(enumValues.count() == values.count());\
178 QList<QByteArray> separatedValues = enumString.split('|');\
179 for (int valueIndex = 0; valueIndex < separatedValues.count(); ++valueIndex){\
180 QByteArray value = separatedValues[valueIndex];\
181 for (int i = 0; i < enumValues.count(); ++i){\
182 if (values[i].toUtf8() == value){\
183 flags |= enumValues[i];\
184 }\
185 }\
186 }\
187 return true;\
188 }
189
190
191
static const QChar QCHAR_PERMILLE
Definition istd.h:52
static const QChar QCHAR_DEGREE
Definition istd.h:51
static const double I_BIG_EPSILON
Definition istd.h:26
static const QChar QCHAR_POW3
Definition istd.h:50
static const QChar QCHAR_POW2
Commonly used symbols.
Definition istd.h:49
Standard library.
Definition IComponent.h:17