35 #define CALLBACK_HOOK_INVALID_IDX 0x0
45 template<
class R,
class... ArgTypes>
62 while (m_callbacks.find(
id) != m_callbacks.end())
67 m_callbacks[
id] = callback;
78 void add_callback(
const std::string&
name,
const std::function<R(ArgTypes...)>& callback)
80 auto it = m_name_to_id_map.find(
name);
81 if (it != m_name_to_id_map.end())
83 remove_callback(it->second);
85 m_name_to_id_map[
name] = add_callback(callback);
95 auto it = m_callbacks.find(
id);
96 if (it != m_callbacks.end())
98 m_callbacks.erase(it);
99 for (
auto it2 = m_name_to_id_map.begin(); it2 != m_name_to_id_map.end(); it2++)
101 if ((*it2).second ==
id)
103 m_name_to_id_map.erase(it2);
117 auto it = m_name_to_id_map.find(
id);
118 if (it != m_name_to_id_map.end())
120 remove_callback((*it).second);
131 if (this->size() == 0)
135 for (
const auto& i : m_callbacks)
151 auto it = m_callbacks.find(idx);
152 if (it == m_callbacks.end())
156 return (it->second)(
args...);
167 R
inline call(
const std::string& idx, ArgTypes...
args)
169 auto it = m_name_to_id_map.find(idx);
170 if (it == m_name_to_id_map.end())
174 return call((*it).second,
args...);
185 return m_callbacks.find(
id) != m_callbacks.end();
196 return m_name_to_id_map.find(
name) != m_name_to_id_map.end();
206 return m_callbacks.size();
217 for (
const auto& it : m_callbacks)
219 res.insert(it.first);
232 for (
const auto& it : m_name_to_id_map)
243 std::map<
u64, std::function<R(ArgTypes...)>> m_callbacks;
245 std::map<std::string, u64> m_name_to_id_map;
#define CALLBACK_HOOK_INVALID_IDX
bool is_callback_registered(const u64 id)
void add_callback(const std::string &name, const std::function< R(ArgTypes...)> &callback)
void remove_callback(const u64 id)
std::set< u64 > get_ids()
void remove_callback(const std::string &id)
void operator()(ArgTypes... args)
std::string get_name(u64 id)
u64 add_callback(const std::function< R(ArgTypes...)> &callback, u64 id=0x0)
bool is_callback_registered(const std::string &name)
R call(const std::string &idx, ArgTypes... args)
R call(const u64 idx, ArgTypes... args)