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
6 #include <base/system.h>
13 // friend with the kernel implementation
17 IKernel
*Kernel() { return m_pKernel
; }
19 IInterface() : m_pKernel(0) {}
20 virtual ~IInterface() {}
22 //virtual unsigned InterfaceID() = 0;
23 //virtual const char *InterfaceName() = 0;
26 #define MACRO_INTERFACE(Name, ver) \
28 static const char *InterfaceName() { return Name; } \
31 //virtual unsigned InterfaceID() { return INTERFACE_ID; }
32 //virtual const char *InterfaceName() { return name; }
35 // This kernel thingie makes the structure very flat and basiclly singletons.
36 // I'm not sure if this is a good idea but it works for now.
39 // hide the implementation
40 virtual bool RegisterInterfaceImpl(const char *InterfaceName
, IInterface
*pInterface
) = 0;
41 virtual bool ReregisterInterfaceImpl(const char *InterfaceName
, IInterface
*pInterface
) = 0;
42 virtual IInterface
*RequestInterfaceImpl(const char *InterfaceName
) = 0;
44 static IKernel
*Create();
47 // templated access to handle pointer convertions and interface names
48 template<class TINTERFACE
>
49 bool RegisterInterface(TINTERFACE
*pInterface
)
51 return RegisterInterfaceImpl(TINTERFACE::InterfaceName(), pInterface
);
53 template<class TINTERFACE
>
54 bool ReregisterInterface(TINTERFACE
*pInterface
)
56 return ReregisterInterfaceImpl(TINTERFACE::InterfaceName(), pInterface
);
60 // IMyInterface *pMyHandle = Kernel()->RequestInterface<IMyInterface>()
61 template<class TINTERFACE
>
62 TINTERFACE
*RequestInterface()
64 return reinterpret_cast<TINTERFACE
*>(RequestInterfaceImpl(TINTERFACE::InterfaceName()));