aboutsummaryrefslogtreecommitdiff
path: root/primedev/plugins/interfaces/interface.h
blob: 440db5b2254c939999a5455fac1056208bd24621 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef INTERFACE_H
#define INTERFACE_H

typedef void* (*InstantiateInterfaceFn)();

// Used internally to register classes.
class InterfaceReg
{
public:
	InterfaceReg(InstantiateInterfaceFn fn, const char* pName);

	InstantiateInterfaceFn m_CreateFn;
	const char* m_pName;
	InterfaceReg* m_pNext;
};

// Use this to expose an interface that can have multiple instances.
#define EXPOSE_INTERFACE(className, interfaceName, versionName)                                                                            \
	static void* __Create##className##_interface()                                                                                         \
	{                                                                                                                                      \
		return static_cast<interfaceName*>(new className);                                                                                 \
	}                                                                                                                                      \
	static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName);

#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName)                                            \
	static void* __Create##className##interfaceName##_interface()                                                                          \
	{                                                                                                                                      \
		return static_cast<interfaceName*>(&globalVarName);                                                                                \
	}                                                                                                                                      \
	static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName);

// Use this to expose a singleton interface. This creates the global variable for you automatically.
#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName)                                                                     \
	static className __g_##className##_singleton;                                                                                          \
	EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton)

EXPORT void* CreateInterface(const char* pName, InterfaceStatus* pReturnCode);

#endif