kakoune/src/hook_manager.hh
Maxime Coste 9bcfda3226 HookManager are now hierarchical from window to buffer to global
window hooks also executes buffer hook which also execute global hooks
2012-06-07 13:29:44 +00:00

42 lines
885 B
C++

#ifndef hook_manager_hh_INCLUDED
#define hook_manager_hh_INCLUDED
#include "utils.hh"
#include <unordered_map>
namespace Kakoune
{
class Context;
typedef std::function<void (const String&, const Context&)> HookFunc;
class HookManager
{
public:
HookManager(HookManager& parent) : m_parent(&parent) {}
void add_hook(const String& hook_name, HookFunc hook);
void run_hook(const String& hook_name, const String& param,
const Context& context) const;
private:
HookManager()
: m_parent(nullptr) {}
// the only one allowed to construct a root hook manager
friend class GlobalHookManager;
HookManager* m_parent;
std::unordered_map<String, std::vector<HookFunc>> m_hook;
};
class GlobalHookManager : public HookManager,
public Singleton<GlobalHookManager>
{
};
}
#endif // hook_manager_hh_INCLUDED