2020-05-23 02:13:32 +03:00
|
|
|
/*
|
2024-12-30 22:39:49 +01:00
|
|
|
* Copyright (C) 2018-2025 QuasarApp.
|
2020-05-23 02:13:32 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2022-01-20 17:09:19 +03:00
|
|
|
#ifndef QU_GLOBAL_UTILS_H
|
|
|
|
#define QU_GLOBAL_UTILS_H
|
2019-04-02 18:12:01 +03:00
|
|
|
|
|
|
|
#include <type_traits>
|
2020-09-07 10:16:55 +03:00
|
|
|
#include <typeinfo>
|
2022-02-10 20:02:48 +03:00
|
|
|
#include <QByteArray>
|
2021-07-14 16:40:55 +03:00
|
|
|
#include "QtGlobal"
|
2024-06-24 13:23:40 +02:00
|
|
|
#include "quasarapp_global.h"
|
2019-04-02 18:12:01 +03:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2020-05-22 22:34:06 +03:00
|
|
|
template<class T>
|
2021-04-26 11:27:19 +03:00
|
|
|
/**
|
2021-04-26 21:19:49 +03:00
|
|
|
* @brief static_type_hash_32 This function return hash code of the class T.
|
2021-04-26 11:27:19 +03:00
|
|
|
* 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.
|
2021-04-26 21:19:49 +03:00
|
|
|
* @return uint32_t hash code of the class T
|
2021-04-26 11:27:19 +03:00
|
|
|
*/
|
2020-06-30 13:13:08 +03:00
|
|
|
uint32_t static_type_hash_32() noexcept {
|
2020-05-23 02:12:35 +03:00
|
|
|
return typeid (T).hash_code();
|
2020-05-22 22:34:06 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
2021-04-26 11:27:19 +03:00
|
|
|
/**
|
2021-04-26 21:19:49 +03:00
|
|
|
* @brief static_type_hash_16 This function return hash code of the class T.
|
2021-04-26 11:27:19 +03:00
|
|
|
* 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.
|
2021-04-26 21:19:49 +03:00
|
|
|
* @return uint16_t hash code of the class T
|
2021-04-26 11:27:19 +03:00
|
|
|
*/
|
2020-06-30 13:13:08 +03:00
|
|
|
uint16_t static_type_hash_16() noexcept {
|
2020-05-23 02:12:35 +03:00
|
|
|
return typeid (T).hash_code() % 0xFFFF;
|
2020-05-22 22:34:06 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
2021-04-26 11:27:19 +03:00
|
|
|
/**
|
2021-04-26 21:19:49 +03:00
|
|
|
* @brief static_type_hash_8 This function return hash code of the class T.
|
2021-04-26 11:27:19 +03:00
|
|
|
* 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.
|
2021-04-26 21:19:49 +03:00
|
|
|
* @return uint8_t hash code of the class T
|
2021-04-26 11:27:19 +03:00
|
|
|
*/
|
2020-06-30 13:13:08 +03:00
|
|
|
uint8_t static_type_hash_8() noexcept {
|
2020-05-23 02:12:35 +03:00
|
|
|
return typeid (T).hash_code() % 0xFF;
|
2020-05-22 22:34:06 +03:00
|
|
|
};
|
|
|
|
|
2020-09-06 00:41:32 +03:00
|
|
|
template<class T>
|
2021-04-26 11:27:19 +03:00
|
|
|
/**
|
|
|
|
* @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.
|
2021-04-26 21:19:49 +03:00
|
|
|
* @return uint32_t hash code of the class T
|
2021-04-26 11:27:19 +03:00
|
|
|
*/
|
2020-09-06 00:41:32 +03:00
|
|
|
uint32_t static_type_hash_32(T& object) noexcept {
|
|
|
|
return typeid (object).hash_code();
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
2021-04-26 11:27:19 +03:00
|
|
|
/**
|
|
|
|
* @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.
|
2021-04-26 21:19:49 +03:00
|
|
|
* @return uint16_t hash code of the class T
|
2021-04-26 11:27:19 +03:00
|
|
|
*/
|
2020-09-06 00:41:32 +03:00
|
|
|
uint16_t static_type_hash_16(T& object) noexcept {
|
|
|
|
return typeid (object).hash_code() % 0xFFFF;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
2021-04-26 11:27:19 +03:00
|
|
|
/**
|
|
|
|
* @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.
|
2021-04-26 21:19:49 +03:00
|
|
|
* @return uint8_t hash code of the class T
|
2021-04-26 11:27:19 +03:00
|
|
|
*/
|
2020-09-06 00:41:32 +03:00
|
|
|
uint8_t static_type_hash_8(T& object) noexcept {
|
|
|
|
return typeid (object).hash_code() % 0xFF;
|
|
|
|
};
|
|
|
|
|
2021-04-26 11:27:19 +03:00
|
|
|
/// @brief H_8 This is short wraper of the static_type_hash_8 fucntion.
|
2020-05-22 22:36:42 +03:00
|
|
|
#define H_8 static_type_hash_8
|
2021-04-26 11:27:19 +03:00
|
|
|
|
|
|
|
/// @brief H_16 This is short wraper of the static_type_hash_16 fucntion.
|
2020-05-22 22:36:42 +03:00
|
|
|
#define H_16 static_type_hash_16
|
2021-04-26 11:27:19 +03:00
|
|
|
|
|
|
|
/// @brief H_32 This is short wraper of the static_type_hash_32 fucntion.
|
2020-05-22 22:36:42 +03:00
|
|
|
#define H_32 static_type_hash_32
|
2020-05-22 22:34:06 +03:00
|
|
|
|
2020-08-21 16:03:32 +03:00
|
|
|
|
2024-06-24 13:23:40 +02:00
|
|
|
#define debug_assert(C, M) Q_ASSERT(C && M)
|
2020-08-21 16:03:32 +03:00
|
|
|
|
2022-02-10 20:02:48 +03:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
2022-07-06 11:52:52 +03:00
|
|
|
void QUASARAPPSHARED_EXPORT randomArray(int size, QByteArray &result);
|
2022-02-10 20:02:48 +03:00
|
|
|
|
2019-04-02 18:12:01 +03:00
|
|
|
#endif // GLOBAL_H
|