ddnet/src/engine/kernel.h
Chairn a69dc599a9 Huge variable naming format
Fix pointer and pointer array variable naming

Huge renaming to match our rules

Used regex: (?!(return|delete)\b)\b\w+ (m_|ms_|g_|gs_|s_)[^a]\w+\[
            (?!(return|delete)\b)\b\w+ (?!(m_|ms_|g_|gs_|s_))[^a]\w+\[

Further format static variables

Format almost all pointer names accordingly

Used regex: (?!(return)\b)\b\w+
\*(?!(m_p|p|s_p|m_ap|s_ap|g_p|g_ap|ap|gs_ap|ms_ap|gs_p|ms_p))\w+\b[^:\(p]

clang-format

Fix CI fail

Fix misnamed non pointer as pointer and non array as array

Used regex: (?!(return|delete)\b)\b\w+ (m_|ms_|g_|gs_|s_)p\w+\b
            (?!return\b)\b\w+ (ms_|m_|g_|gs_|s_)a\w+\b[^\[]

clang-format

Revert to SCREAMING_SNAKE_CASE and reinstate dead code
2022-07-08 18:01:29 +02:00

67 lines
1.8 KiB
C++

/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#ifndef ENGINE_KERNEL_H
#define ENGINE_KERNEL_H
#include <base/system.h>
class IKernel;
class IInterface;
class IInterface
{
// friend with the kernel implementation
friend class CKernel;
IKernel *m_pKernel;
protected:
IKernel *Kernel() { return m_pKernel; }
public:
IInterface() :
m_pKernel(nullptr) {}
virtual ~IInterface() {}
};
#define MACRO_INTERFACE(Name, ver) \
public: \
static const char *InterfaceName() { return Name; } \
\
private:
// This kernel thingie makes the structure very flat and basiclly singletons.
// I'm not sure if this is a good idea but it works for now.
class IKernel
{
// hide the implementation
virtual bool RegisterInterfaceImpl(const char *pInterfaceName, IInterface *pInterface, bool Destroy) = 0;
virtual bool ReregisterInterfaceImpl(const char *pInterfaceName, IInterface *pInterface) = 0;
virtual IInterface *RequestInterfaceImpl(const char *pInterfaceName) = 0;
public:
static IKernel *Create();
virtual ~IKernel() {}
// templated access to handle pointer conversions and interface names
template<class TINTERFACE>
bool RegisterInterface(TINTERFACE *pInterface, bool Destroy = true)
{
return RegisterInterfaceImpl(TINTERFACE::InterfaceName(), pInterface, Destroy);
}
template<class TINTERFACE>
bool ReregisterInterface(TINTERFACE *pInterface)
{
return ReregisterInterfaceImpl(TINTERFACE::InterfaceName(), pInterface);
}
// Usage example:
// IMyInterface *pMyHandle = Kernel()->RequestInterface<IMyInterface>()
template<class TINTERFACE>
TINTERFACE *RequestInterface()
{
return reinterpret_cast<TINTERFACE *>(RequestInterfaceImpl(TINTERFACE::InterfaceName()));
}
};
#endif