Chrysalis - Hooks
Loading...
Searching...
No Matches
HookHandle.h
Go to the documentation of this file.
1#ifndef CHRYSALIS_HOOKHANDLE_H
2#define CHRYSALIS_HOOKHANDLE_H
3
4#include <list>
5#include <functional>
6
8
9// =============================================================================
10// HookHandle
11// Must be defined before hook_detail so the Before/After/Replace std::function
12// signatures that reference it can be fully formed.
13//
14// Returned to the caller when registering a before/after/replace callback.
15// Calling remove() schedules the callback for deletion on the next hook
16// invocation — deletion is deferred so it is safe to call remove() from
17// inside the callback itself without invalidating the iterator mid-loop.
18// =============================================================================
19class HOOKS HookHandle {
20 friend class HooksManager;
21 explicit HookHandle(std::list<std::function<void()>>& executeLater, std::function<void()> remover);
22public:
23 // Schedule this callback for removal. Safe to call from inside the callback.
24 void remove() const;
25private:
26 // Raw pointer is intentional: the list is an instance member of HookBase
27 // and outlives every HookHandle created during a single hook invocation.
28 std::list<std::function<void()>>* executeLater_;
29 std::function<void()> remover_;
30};
31
32#endif // CHRYSALIS_HOOKHANDLE_H
#define HOOKS
Definition HooksLibraryExport.h:11
friend class HooksManager
Definition HookHandle.h:20
void remove() const
Definition HookHandle.cpp:6