-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqaglobalutils.h
159 lines (126 loc) · 4.89 KB
/
qaglobalutils.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Copyright (C) 2018-2025 QuasarApp.
* Distributed under the lgplv3 software license, see the accompanying
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
#ifndef QU_GLOBAL_UTILS_H
#define QU_GLOBAL_UTILS_H
#include <type_traits>
#include <typeinfo>
#include <QByteArray>
#include "QtGlobal"
#include "quasarapp_global.h"
template <typename T>
constexpr inline T operator | (T lhs, T rhs)
{
static_assert(std::is_enum<T>::value,
"template parameter is not an enum type");
return static_cast<T>(static_cast<int>(lhs) | static_cast<int>(rhs));
}
template <typename T>
constexpr inline T operator & (T lhs, T rhs)
{
static_assert(std::is_enum<T>::value,
"template parameter is not an enum type");
return static_cast<T>(static_cast<int>(lhs) & static_cast<int>(rhs));
}
template <typename T>
constexpr inline T operator >> (T lhs, T rhs)
{
static_assert(std::is_enum<T>::value,
"template parameter is not an enum type");
return static_cast<T>(static_cast<int>(lhs) >> static_cast<int>(rhs));
}
template <typename T>
constexpr inline T operator << (T lhs, T rhs)
{
static_assert(std::is_enum<T>::value,
"template parameter is not an enum type");
return static_cast<T>(static_cast<int>(lhs) << static_cast<int>(rhs));
}
template <typename T>
constexpr inline T operator ~ (T lhs)
{
static_assert(std::is_enum<T>::value,
"template parameter is not an enum type");
return static_cast<T>(~static_cast<int>(lhs));
}
template <typename T>
constexpr inline T operator ^ (T lhs, T rhs)
{
static_assert(std::is_enum<T>::value,
"template parameter is not an enum type");
return static_cast<T>(static_cast<int>(lhs) ^ static_cast<int>(rhs));
}
template<class T>
/**
* @brief static_type_hash_32 This function return hash code of the class T.
* For get more information see the std [documentation](https://en.cppreference.com/w/cpp/types/type_info/hash_code).
* @note This method will create a T object on stack, so if you have a alredy created object use the static_type_hash_32(const T&) function.
* @return uint32_t hash code of the class T
*/
uint32_t static_type_hash_32() noexcept {
return typeid (T).hash_code();
};
template<class T>
/**
* @brief static_type_hash_16 This function return hash code of the class T.
* For get more information see the std [documentation](https://en.cppreference.com/w/cpp/types/type_info/hash_code).
* @note This method will create a T object on stack, so if you have a alredy created object use the static_type_hash_16(const T&) function.
* @return uint16_t hash code of the class T
*/
uint16_t static_type_hash_16() noexcept {
return typeid (T).hash_code() % 0xFFFF;
};
template<class T>
/**
* @brief static_type_hash_8 This function return hash code of the class T.
* For get more information see the std [documentation](https://en.cppreference.com/w/cpp/types/type_info/hash_code).
* @note This method will create a T object on stack, so if you have a alredy created object use the static_type_hash_8(const T&) function.
* @return uint8_t hash code of the class T
*/
uint8_t static_type_hash_8() noexcept {
return typeid (T).hash_code() % 0xFF;
};
template<class T>
/**
* @brief static_type_hash_32 This function return hash code of a T type using @a object.
* @param object This is object of the T type using for generate hash.
* @return uint32_t hash code of the class T
*/
uint32_t static_type_hash_32(T& object) noexcept {
return typeid (object).hash_code();
};
template<class T>
/**
* @brief static_type_hash_16 This function return hash code of a T type using @a object.
* @param object This is object of the T type using for generate hash.
* @return uint16_t hash code of the class T
*/
uint16_t static_type_hash_16(T& object) noexcept {
return typeid (object).hash_code() % 0xFFFF;
};
template<class T>
/**
* @brief static_type_hash_8 This function return hash code of a T type using @a object.
* @param object This is object of the T type using for generate hash.
* @return uint8_t hash code of the class T
*/
uint8_t static_type_hash_8(T& object) noexcept {
return typeid (object).hash_code() % 0xFF;
};
/// @brief H_8 This is short wraper of the static_type_hash_8 fucntion.
#define H_8 static_type_hash_8
/// @brief H_16 This is short wraper of the static_type_hash_16 fucntion.
#define H_16 static_type_hash_16
/// @brief H_32 This is short wraper of the static_type_hash_32 fucntion.
#define H_32 static_type_hash_32
#define debug_assert(C, M) Q_ASSERT(C && M)
/**
* @brief randomArray This function return random arrat with size @a size
* @param size This is size of needed array.
* @param result This is result value of generated array.
*/
void QUASARAPPSHARED_EXPORT randomArray(int size, QByteArray &result);
#endif // GLOBAL_H