1
1
#pragma once
2
+ #include < Core/Memory/Allocator.h>
2
3
#include < CoreWindow.h>
3
4
#include < KeyCode.h>
4
5
#include < algorithm>
5
6
#include < map>
6
- #include < memory>
7
- #include < string>
8
7
#include < type_traits>
9
8
10
9
namespace ZEngine ::Windows::Inputs
11
10
{
12
11
13
12
struct IDevice
14
13
{
14
+ IDevice (const char * name = " abstract_device" ) : m_name(name) {}
15
15
virtual ~IDevice () = default ;
16
+ const char * m_name;
17
+ static Core::Memory::ArenaAllocator* Arena;
18
+ static std::map<const char *, ZRawPtr(IDevice)> Devices;
19
+
20
+ static void Initialize (Core::Memory::ArenaAllocator* arena)
21
+ {
22
+ Arena = arena;
23
+ }
16
24
17
25
template <typename T, typename = std::enable_if_t <std::is_base_of_v<IDevice, T>>>
18
26
static const T* As () noexcept
19
27
{
20
28
const std::type_info& type = typeid (T);
21
- auto it = m_devices .find (std::string ( type.name () ));
29
+ auto it = Devices .find (type.name ());
22
30
23
- if (it != std::end (m_devices ))
31
+ if (it != std::end (Devices ))
24
32
{
25
- return reinterpret_cast <T*>(& it->second );
33
+ return reinterpret_cast <T*>(it->second );
26
34
}
27
35
28
- IDevice device = T ( );
29
- auto pair = m_devices .emplace (std::make_pair (std::string ( type.name () ), device));
30
- return reinterpret_cast <T*>(&( pair.first ->second ) );
36
+ IDevice* device = ZPushStructCtor (Arena, T );
37
+ auto pair = Devices .emplace (std::make_pair (type.name (), device));
38
+ return reinterpret_cast <T*>(pair.first ->second );
31
39
}
32
40
33
41
virtual bool IsKeyPressed (ZENGINE_KEYCODE key, Windows::CoreWindow* const window) const
@@ -40,14 +48,9 @@ namespace ZEngine::Windows::Inputs
40
48
return false ;
41
49
}
42
50
43
- virtual std::string_view GetName () const
51
+ virtual const char * GetName () const
44
52
{
45
53
return m_name;
46
54
}
47
-
48
- protected:
49
- IDevice (std::string_view name = " abstract_device" ) : m_name(name) {}
50
- static std::map<std::string, IDevice> m_devices;
51
- std::string m_name;
52
55
};
53
56
} // namespace ZEngine::Windows::Inputs
0 commit comments