QuasarAppLib
qaglobalutils.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2025 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
17template <typename T>
18constexpr inline T operator | (T lhs, T rhs)
19{
20
21 static_assert(std::is_enum<T>::value,
22 "template parameter is not an enum type");
23
24 return static_cast<T>(static_cast<int>(lhs) | static_cast<int>(rhs));
25}
26
27template <typename T>
28constexpr inline T operator & (T lhs, T rhs)
29{
30
31 static_assert(std::is_enum<T>::value,
32 "template parameter is not an enum type");
33
34 return static_cast<T>(static_cast<int>(lhs) & static_cast<int>(rhs));
35}
36
37template <typename T>
38constexpr inline T operator >> (T lhs, T rhs)
39{
40
41 static_assert(std::is_enum<T>::value,
42 "template parameter is not an enum type");
43
44 return static_cast<T>(static_cast<int>(lhs) >> static_cast<int>(rhs));
45}
46
47template <typename T>
48constexpr inline T operator << (T lhs, T rhs)
49{
50
51 static_assert(std::is_enum<T>::value,
52 "template parameter is not an enum type");
53
54 return static_cast<T>(static_cast<int>(lhs) << static_cast<int>(rhs));
55}
56
57template <typename T>
58constexpr inline T operator ~ (T lhs)
59{
60
61 static_assert(std::is_enum<T>::value,
62 "template parameter is not an enum type");
63
64 return static_cast<T>(~static_cast<int>(lhs));
65}
66
67template <typename T>
68constexpr inline T operator ^ (T lhs, T rhs)
69{
70
71 static_assert(std::is_enum<T>::value,
72 "template parameter is not an enum type");
73
74 return static_cast<T>(static_cast<int>(lhs) ^ static_cast<int>(rhs));
75}
76
77template<class T>
85 return typeid (T).hash_code();
86};
87
88template<class T>
96 return typeid (T).hash_code() % 0xFFFF;
97};
98
99template<class T>
107 return typeid (T).hash_code() % 0xFF;
108};
109
110template<class T>
116uint32_t static_type_hash_32(T& object) noexcept {
117 return typeid (object).hash_code();
118};
119
120template<class T>
126uint16_t static_type_hash_16(T& object) noexcept {
127 return typeid (object).hash_code() % 0xFFFF;
128};
129
130template<class T>
136uint8_t static_type_hash_8(T& object) noexcept {
137 return typeid (object).hash_code() % 0xFF;
138};
139
141#define H_8 static_type_hash_8
142
144#define H_16 static_type_hash_16
145
147#define H_32 static_type_hash_32
148
149
150#define debug_assert(C, M) Q_ASSERT(C && M)
151
158
159#endif // GLOBAL_H
void gen(int size, QByteArray &result)
constexpr T operator>>(T lhs, T rhs)
void QUASARAPPSHARED_EXPORT randomArray(int size, QByteArray &result)
randomArray This function return random arrat with size size
constexpr T operator^(T lhs, T rhs)
constexpr T operator&(T lhs, T rhs)
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)
constexpr T operator<<(T lhs, T rhs)
constexpr T operator|(T lhs, T rhs)
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