Hana
Loading...
Searching...
No Matches
Core.h
1#pragma once
2
3#include <memory>
4
5// Platform detection using predefined macros
6#ifdef _WIN32
7 /* Windows x64/x86 */
8 #ifdef _WIN64
9 /* Windows x64 */
10 #define HN_PLATFORM_WINDOWS
11 #else
12 /* Windows x86 */
13 #error "x86 Builds are not supported!"
14 #endif
15#elif defined(__APPLE__) || defined(__MACH__)
16 #include <TargetConditionals.h>
17 /* TARGET_OS_MAC exists on all the platforms
18 * so we must check all of them (in this order)
19 * to ensure that we're running on MAC
20 * and not some other Apple platform */
21 #if TARGET_IPHONE_SIMULATOR == 1
22 #error "IOS simulator is not supported!"
23 #elif TARGET_OS_IPHONE == 1
24 #define HN_PLATFORM_IOS
25 #error "IOS is not supported!"
26 #elif TARGET_OS_MAC == 1
27 #define HN_PLATFORM_MACOS
28 #error "MacOS is not supported!"
29 #else
30 #error "Unknown Apple platform!"
31 #endif
32/* We also have to check __ANDROID__ before __linux__
33 * since android is based on the linux kernel
34 * it has __linux__ defined */
35#elif defined(__ANDROID__)
36 #define HN_PLATFORM_ANDROID
37 #error "Android is not supported!"
38#elif defined(__linux__)
39 #define HN_PLATFORM_LINUX
40 #error "Linux is not supported!"
41#else
42 /* Unknown compiler/platform */
43 #error "Unknown platform!"
44#endif // End of platform detection
45
46#ifdef HN_DEBUG
47 #define HN_ENABLE_ASSERTS
48#endif
49
50#ifdef HN_ENABLE_ASSERTS
51 #define HN_ASSERT(x, ...) { if(!(x)) { HN_ERROR("Assertion Failed: {0}", __VA_ARGS__); __debugbreak(); } }
52 #define HN_CORE_ASSERT(x, ...) { if(!(x)) { HN_CORE_ERROR("Assertion Failed: {0}", __VA_ARGS__); __debugbreak(); } }
53#else
54 #define HN_ASSERT(x, ...)
55 #define HN_CORE_ASSERT(x, ...)
56#endif
57
58#define BIT(x) (1 << x)
59
60#define HN_BIND_EVENT_FN(fn) std::bind(&fn, this, std::placeholders::_1)
61
62namespace Hana
63{
64 template<typename T>
65 using Scope = std::unique_ptr<T>;
66 template<typename T, typename ... Args>
67 constexpr Scope <T> CreateScope(Args&& ... args)
68 {
69 return std::make_unique<T>(std::forward<Args>(args)...);
70 }
71
72 template<typename T>
73 using Ref = std::shared_ptr<T>;
74 template<typename T, typename ... Args>
75 constexpr Ref<T> CreateRef(Args&& ... args)
76 {
77 return std::make_shared<T>(std::forward<Args>(args)...);
78 }
79}