kakoune/src/hook_manager.hh

42 lines
885 B
C++
Raw Normal View History

2012-04-03 14:01:01 +02:00
#ifndef hook_manager_hh_INCLUDED
#define hook_manager_hh_INCLUDED
2011-11-25 15:26:29 +01:00
#include "utils.hh"
#include <unordered_map>
namespace Kakoune
{
class Context;
typedef std::function<void (const String&, const Context&)> HookFunc;
2011-11-25 15:26:29 +01:00
2012-04-03 14:01:01 +02:00
class HookManager
2011-11-25 15:26:29 +01:00
{
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;
2011-11-25 15:26:29 +01:00
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;
2011-11-25 15:26:29 +01:00
};
2012-04-03 14:01:01 +02:00
class GlobalHookManager : public HookManager,
public Singleton<GlobalHookManager>
{
};
2011-11-25 15:26:29 +01:00
}
2012-04-03 14:01:01 +02:00
#endif // hook_manager_hh_INCLUDED
2011-11-25 15:26:29 +01:00