QuasarAppLib 1.0.530.c9fba11
qaglobalutils.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2026 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8#ifndef QU_GLOBAL_UTILS_H
9#define QU_GLOBAL_UTILS_H
10
11#include <type_traits>
12#include <typeinfo>
13#include <QByteArray>
14#include "QtGlobal"
15#include "quasarapp_global.h"
16
24template <typename T>
25constexpr inline T operator | (T lhs, T rhs)
26{
27
28 static_assert(std::is_enum<T>::value,
29 "template parameter is not an enum type");
30
31 return static_cast<T>(static_cast<int>(lhs) | static_cast<int>(rhs));
32}
33
41template <typename T>
42constexpr inline T operator & (T lhs, T rhs)
43{
44
45 static_assert(std::is_enum<T>::value,
46 "template parameter is not an enum type");
47
48 return static_cast<T>(static_cast<int>(lhs) & static_cast<int>(rhs));
49}
50
58template <typename T>
59constexpr inline T operator >> (T lhs, T rhs)
60{
61
62 static_assert(std::is_enum<T>::value,
63 "template parameter is not an enum type");
64
65 return static_cast<T>(static_cast<int>(lhs) >> static_cast<int>(rhs));
66}
67
75template <typename T>
76constexpr inline T operator << (T lhs, T rhs)
77{
78
79 static_assert(std::is_enum<T>::value,
80 "template parameter is not an enum type");
81
82 return static_cast<T>(static_cast<int>(lhs) << static_cast<int>(rhs));
83}
84
91template <typename T>
92constexpr inline T operator ~ (T lhs)
93{
94
95 static_assert(std::is_enum<T>::value,
96 "template parameter is not an enum type");
97
98 return static_cast<T>(~static_cast<int>(lhs));
99}
100
108template <typename T>
109constexpr inline T operator ^ (T lhs, T rhs)
110{
111
112 static_assert(std::is_enum<T>::value,
113 "template parameter is not an enum type");
114
115 return static_cast<T>(static_cast<int>(lhs) ^ static_cast<int>(rhs));
116}
117
118template<class T>
125uint32_t static_type_hash_32() noexcept {
126 return typeid (T).hash_code();
127};
128
129template<class T>
136uint16_t static_type_hash_16() noexcept {
137 return typeid (T).hash_code() % 0xFFFF;
138};
139
140template<class T>
147uint8_t static_type_hash_8() noexcept {
148 return typeid (T).hash_code() % 0xFF;
149};
150
151template<class T>
157uint32_t static_type_hash_32(T& object) noexcept {
158 return typeid (object).hash_code();
159};
160
161template<class T>
167uint16_t static_type_hash_16(T& object) noexcept {
168 return typeid (object).hash_code() % 0xFFFF;
169};
170
171template<class T>
177uint8_t static_type_hash_8(T& object) noexcept {
178 return typeid (object).hash_code() % 0xFF;
179};
180
182#define H_8 static_type_hash_8
183
185#define H_16 static_type_hash_16
186
188#define H_32 static_type_hash_32
189
190
197#define debug_assert(C, M) Q_ASSERT(C && M)
198
204void QUASARAPPSHARED_EXPORT randomArray(int size, QByteArray &result);
205
206
228template <class QHashType>
229QHashType &subtract(QHashType &left, const QHashType& right) {
230 if (left.isSharedWith(right)) {
231 left.clear();
232 } else {
233 for (auto&& it = right.begin(); it != right.end(); ++it)
234 left.remove(it.key());
235 }
236 return left;
237}
238
260template <class QHashType>
261QHashType &unite(QHashType &left, const QHashType& right) {
262 if (!left.isSharedWith(right)) {
263 for (auto&& it = right.begin(); it != right.end(); ++it)
264 left.insert(it.key(), it.value());
265 }
266 return left;
267}
268
290template <class QHashType>
291QHashType &match(QHashType &left, const QHashType& right) {
292 if (!left.isSharedWith(right)) {
293 for (auto&& it = left.begin(); it != left.end(); ) {
294 if (!right.contains(it.key())) {
295 it = left.erase(it);
296 } else {
297 ++it;
298 }
299 }
300
301 return left;
302 }
303
304 left.clear();
305 return left;
306}
307
308
309#endif // GLOBAL_H
void randomArray(int size, QByteArray &result)
randomArray This function return random arrat with size size
constexpr T operator>>(T lhs, T rhs)
operator >> This operator returns the right shift of an enum value of type T by rhs positions.
QHashType & unite(QHashType &left, const QHashType &right)
Simplified union operation for QHash.
QHashType & match(QHashType &left, const QHashType &right)
Simplified match (intersection) operation for QHash.
constexpr T operator^(T lhs, T rhs)
operator ^ This operator returns the bitwise XOR of two enum values of type T.
constexpr T operator&(T lhs, T rhs)
operator & This operator returns the bitwise AND of two enum values of type T.
uint16_t static_type_hash_16() noexcept
static_type_hash_16 This function return hash code of the class T. For get more information see the s...
uint8_t static_type_hash_8() noexcept
static_type_hash_8 This function return hash code of the class T. For get more information see the st...
constexpr T operator~(T lhs)
operator ~ This operator returns the bitwise complement of an enum value of type T.
constexpr T operator<<(T lhs, T rhs)
operator << This operator returns the left shift of an enum value of type T by rhs positions.
constexpr T operator|(T lhs, T rhs)
operator | This operator returns the bitwise OR of two enum values of type T.
QHashType & subtract(QHashType &left, const QHashType &right)
Simplified subtraction operation for QHash.
uint32_t static_type_hash_32() noexcept
static_type_hash_32 This function return hash code of the class T. For get more information see the s...
#define QUASARAPPSHARED_EXPORT