You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.2 KiB
C++
81 lines
2.2 KiB
C++
//
|
|
// Created by koncord on 04.03.17.
|
|
//
|
|
|
|
#ifndef OPENMW_UTILS_HPP
|
|
#define OPENMW_UTILS_HPP
|
|
|
|
#include <cstddef>
|
|
#include <regex>
|
|
#include <vector>
|
|
|
|
#include <components/esm/loadcell.hpp>
|
|
|
|
#include <components/openmw-mp/Utils.hpp>
|
|
#include <components/openmw-mp/Log.hpp>
|
|
|
|
#define Singleton(className)\
|
|
public:\
|
|
className(className const&) = delete;\
|
|
className(className&&) = delete;\
|
|
className& operator=(className const&) = delete;\
|
|
className& operator=(className &&) = delete;\
|
|
protected:\
|
|
className();\
|
|
~className();\
|
|
public:\
|
|
static className &Get() {static className instance; return instance;}\
|
|
private:
|
|
|
|
#if (!defined(DEBUG_PRINTF) && defined(DEBUG))
|
|
#define DEBUG_PRINTF(...) LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, __VA_ARGS__)
|
|
#else
|
|
#define DEBUG_PRINTF(...)
|
|
#endif
|
|
|
|
|
|
namespace Utils
|
|
{
|
|
const std::vector<std::string> split(const std::string &str, int delimiter);
|
|
|
|
ESM::Cell getCellFromDescription(const std::string &cellDescription);
|
|
|
|
const std::string getLastError();
|
|
|
|
void throwError(const std::string &errorMessage);
|
|
|
|
template<size_t N>
|
|
constexpr unsigned int hash(const char(&str)[N], size_t I = N)
|
|
{
|
|
return (I == 1 ? ((2166136261u ^ str[0]) * 16777619u) : ((hash(str, I - 1) ^ str[I - 1]) * 16777619u));
|
|
}
|
|
|
|
inline unsigned int hash(const char *str, std::size_t I)
|
|
{
|
|
return (I == 1 ? ((2166136261u ^ str[0]) * 16777619u) : ((hash(str, I - 1) ^ str[I - 1]) * 16777619u));
|
|
}
|
|
|
|
template<typename F, typename T, typename E = void>
|
|
struct is_static_castable : std::false_type
|
|
{
|
|
};
|
|
template<typename F, typename T>
|
|
struct is_static_castable<F, T, typename std::conditional<true, void, decltype(static_cast<T>(std::declval<F>()))>::type>
|
|
: std::true_type
|
|
{
|
|
};
|
|
|
|
template<typename T, typename F>
|
|
inline static typename std::enable_if<is_static_castable<F *, T *>::value, T *>::type static_or_dynamic_cast(
|
|
F *from)
|
|
{ return static_cast<T *>(from); }
|
|
|
|
template<typename T, typename F>
|
|
inline static typename std::enable_if<!is_static_castable<F *, T *>::value, T *>::type static_or_dynamic_cast(
|
|
F *from)
|
|
{ return dynamic_cast<T *>(from); }
|
|
}
|
|
|
|
|
|
#endif //OPENMW_UTILS_HPP
|