DDraceNetwork Documentation
Loading...
Searching...
No Matches
kernel.h
Go to the documentation of this file.
1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef ENGINE_KERNEL_H
4#define ENGINE_KERNEL_H
5
6class IKernel;
7class IInterface;
8
10{
11 // friend with the kernel implementation
12 friend class CKernel;
14
15protected:
16 IKernel *Kernel() { return m_pKernel; }
17
18public:
21 virtual void Shutdown() {}
22 virtual ~IInterface() = default;
23};
24
25#define MACRO_INTERFACE(Name) \
26public: \
27 static const char *InterfaceName() { return Name; } \
28\
29private:
30
31// This kernel thingie makes the structure very flat and basically singletons.
32// I'm not sure if this is a good idea but it works for now.
34{
35 // hide the implementation
36 virtual void RegisterInterfaceImpl(const char *pInterfaceName, IInterface *pInterface, bool Destroy) = 0;
39
40public:
41 static IKernel *Create();
42 virtual void Shutdown() = 0;
43 virtual ~IKernel() = default;
44
45 // templated access to handle pointer conversions and interface names
46 template<class TINTERFACE>
47 void RegisterInterface(TINTERFACE *pInterface, bool Destroy = true)
48 {
49 RegisterInterfaceImpl(TINTERFACE::InterfaceName(), pInterface, Destroy);
50 }
51 template<class TINTERFACE>
53 {
54 ReregisterInterfaceImpl(TINTERFACE::InterfaceName(), pInterface);
55 }
56
57 // Usage example:
58 // IMyInterface *pMyHandle = Kernel()->RequestInterface<IMyInterface>()
59 template<class TINTERFACE>
61 {
62 return reinterpret_cast<TINTERFACE *>(RequestInterfaceImpl(TINTERFACE::InterfaceName()));
63 }
64};
65
66#endif
Definition kernel.cpp:11
Definition kernel.h:10
IInterface()
Definition kernel.h:19
IKernel * Kernel()
Definition kernel.h:16
virtual void Shutdown()
Definition kernel.h:21
virtual ~IInterface()=default
IKernel * m_pKernel
Definition kernel.h:13
Definition kernel.h:34
void ReregisterInterface(TINTERFACE *pInterface)
Definition kernel.h:52
TINTERFACE * RequestInterface()
Definition kernel.h:60
virtual void Shutdown()=0
virtual void ReregisterInterfaceImpl(const char *pInterfaceName, IInterface *pInterface)=0
static IKernel * Create()
Definition kernel.cpp:96
virtual ~IKernel()=default
virtual void RegisterInterfaceImpl(const char *pInterfaceName, IInterface *pInterface, bool Destroy)=0
virtual IInterface * RequestInterfaceImpl(const char *pInterfaceName)=0
void RegisterInterface(TINTERFACE *pInterface, bool Destroy=true)
Definition kernel.h:47
Definition vmath.h:15