2024-03-18 15:41:46 -03:00
|
|
|
#ifndef XNA_HELPERS_HPP
|
|
|
|
#define XNA_HELPERS_HPP
|
|
|
|
|
|
|
|
#include <string>
|
2024-05-02 10:52:08 -03:00
|
|
|
#include <utility>
|
2024-03-18 15:41:46 -03:00
|
|
|
|
|
|
|
namespace xna {
|
2024-04-14 21:23:09 -03:00
|
|
|
inline std::wstring XnaHToWString(const std::string& str)
|
2024-03-18 15:41:46 -03:00
|
|
|
{
|
|
|
|
std::wstring wstr;
|
|
|
|
size_t size;
|
|
|
|
wstr.resize(str.length());
|
|
|
|
mbstowcs_s(&size, &wstr[0], wstr.size() + 1, str.c_str(), str.size());
|
|
|
|
return wstr;
|
|
|
|
}
|
|
|
|
|
2024-04-14 21:23:09 -03:00
|
|
|
inline std::string XnaHToString(const std::wstring& wstr)
|
2024-03-18 15:41:46 -03:00
|
|
|
{
|
|
|
|
std::string str;
|
|
|
|
size_t size;
|
|
|
|
str.resize(wstr.length());
|
|
|
|
wcstombs_s(&size, &str[0], str.size() + 1, wstr.c_str(), wstr.size());
|
|
|
|
return str;
|
|
|
|
}
|
2024-05-02 10:52:08 -03:00
|
|
|
|
|
|
|
template <class T>
|
2024-06-01 20:33:35 -03:00
|
|
|
constexpr void XnaHHashCombine(std::size_t& seed, const T& v) {
|
2024-05-02 10:52:08 -03:00
|
|
|
std::hash<T> hasher;
|
|
|
|
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
|
|
|
}
|
2024-06-01 20:33:35 -03:00
|
|
|
|
|
|
|
template<typename T> struct is_shared_ptr : std::false_type {};
|
|
|
|
template<typename T> struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline auto ReturnDefaultOrNull() {
|
|
|
|
if constexpr (is_shared_ptr<T>::value)
|
|
|
|
return (T)nullptr;
|
|
|
|
else
|
|
|
|
return T();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*template<typename T>
|
|
|
|
inline auto ReturnAuto(T& value) {
|
|
|
|
return value;
|
|
|
|
}*/
|
2024-03-18 15:41:46 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|