I am programming a plugin API for an application. Plugins are loaded as shared libraries at runtime. They have access to the application API through an interface, for example:
class IPluginAPI
{
public:
virtual bool IsPluginsLoaded(void) = 0;
virtual bool IsHookingEnabled(void) = 0;
};
Plugins can request a "listening" of certain events (eg MouseClick, MouseScrolletc.). These functions make up a total of> 300 different events. Normally I would do something like this:
extern "C" void SetEventHooks(APITable& table)
{
table.MouseClick = &PluginMouseClickEvent;
table.MouseMove = &PluginMouseMoveEvent;
}
While the function SetEventHooksis located inside the plugin library and is called from the application, the plugins can listen to the functions of interest, indicating their functions. This is not the method that I want to use, but instead I want to offer some abstraction. That's what I meant:
void SetEventHook(HookID id, void * callback);
HookID , :
enum class HookID
{
MouseClick,
MouseMove,
};
, :
pluginAPI->SetEventHook(ID::MouseClick, &myCallback);
, , ( ). 300 (, SetHookMouseMove(void (*)(int, int)) ..). , , , , ( ):
template <typename T>
SetEventHook(HookID id, T callback)
{
if(typeof(T) == decltype())
gPluginAPI->SetEventHook(id, callback);
else static_assert("INVALID FUNCTION TYPE");
}
, ; , / > 300 ?
. , std::function