summaryrefslogtreecommitdiff
path: root/src/libaudcore/hook.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libaudcore/hook.h')
-rw-r--r--src/libaudcore/hook.h106
1 files changed, 52 insertions, 54 deletions
diff --git a/src/libaudcore/hook.h b/src/libaudcore/hook.h
index 5772844..176076d 100644
--- a/src/libaudcore/hook.h
+++ b/src/libaudcore/hook.h
@@ -28,20 +28,25 @@
// reducing CPU wakeups.
// ========================================================================
-enum class TimerRate {
- Hz1, Hz4, Hz10, Hz30, count
+enum class TimerRate
+{
+ Hz1,
+ Hz4,
+ Hz10,
+ Hz30,
+ count
};
-typedef void (* TimerFunc) (void * data);
+typedef void (*TimerFunc)(void * data);
/* Adds <func> to the list of functions to be called at the given <rate>,
* unless it has already been added with the same <data>. */
-void timer_add (TimerRate rate, TimerFunc func, void * data = nullptr);
+void timer_add(TimerRate rate, TimerFunc func, void * data = nullptr);
/* Removes all instances matching <func> and <data> from the list of functions
* to be called at the given <rate>. If <data> is nullptr, all instances
* matching <func> are removed. */
-void timer_remove (TimerRate rate, TimerFunc func, void * data = nullptr);
+void timer_remove(TimerRate rate, TimerFunc func, void * data = nullptr);
/* Convenience wrapper for C++ classes. Allows non-static member functions to
* be used as timer callbacks. The Timer should be made a member of the class
@@ -51,31 +56,28 @@ template<class T>
class Timer
{
public:
- Timer (TimerRate rate, T * target, void (T::* func) ()) :
- rate (rate),
- target (target),
- func (func) {}
+ Timer(TimerRate rate, T * target, void (T::*func)())
+ : rate(rate), target(target), func(func)
+ {
+ }
- void start () const
- { timer_add (rate, run, (void *) this); }
- void stop () const
- { timer_remove (rate, run, (void *) this); }
+ void start() const { timer_add(rate, run, (void *)this); }
+ void stop() const { timer_remove(rate, run, (void *)this); }
- ~Timer ()
- { stop (); }
+ ~Timer() { stop(); }
- Timer (const Timer &) = delete;
- void operator= (const Timer &) = delete;
+ Timer(const Timer &) = delete;
+ void operator=(const Timer &) = delete;
private:
const TimerRate rate;
T * const target;
- void (T::* const func) ();
+ void (T::*const func)();
- static void run (void * timer_)
+ static void run(void * timer_)
{
- auto timer = (const Timer *) timer_;
- (timer->target->* timer->func) ();
+ auto timer = (const Timer *)timer_;
+ (timer->target->*timer->func)();
}
};
@@ -83,30 +85,32 @@ private:
// named event, or "hook", is called.
// =========================================================================
-typedef void (* HookFunction) (void * data, void * user);
+typedef void (*HookFunction)(void * data, void * user);
/* Adds <func> to the list of functions to be called when the hook <name> is
* triggered. */
-void hook_associate (const char * name, HookFunction func, void * user);
+void hook_associate(const char * name, HookFunction func, void * user);
/* Removes all instances matching <func> and <user> from the list of functions
* to be called when the hook <name> is triggered. If <user> is nullptr, all
* instances matching <func> are removed. */
-void hook_dissociate (const char * name, HookFunction func, void * user = nullptr);
+void hook_dissociate(const char * name, HookFunction func,
+ void * user = nullptr);
/* Triggers the hook <name>. */
-void hook_call (const char * name, void * data);
+void hook_call(const char * name, void * data);
-typedef void (* EventDestroyFunc) (void * data);
+typedef void (*EventDestroyFunc)(void * data);
/* Schedules a call of the hook <name> from the program's main loop.
* If <destroy> is not nullptr, it will be called on <data> after the
* hook is called. */
-void event_queue (const char * name, void * data, EventDestroyFunc destroy = nullptr);
+void event_queue(const char * name, void * data,
+ EventDestroyFunc destroy = nullptr);
/* Cancels pending hook calls matching <name> and <data>. If <data> is nullptr,
* all hook calls matching <name> are canceled. */
-void event_queue_cancel (const char * name, void * data = nullptr);
+void event_queue_cancel(const char * name, void * data = nullptr);
/* Convenience wrapper for C++ classes. Allows non-static member functions to
* be used as hook callbacks. The HookReceiver should be made a member of the
@@ -116,29 +120,26 @@ template<class T, class D = void>
class HookReceiver
{
public:
- HookReceiver (const char * hook, T * target, void (T::* func) (D)) :
- hook (hook),
- target (target),
- func (func)
+ HookReceiver(const char * hook, T * target, void (T::*func)(D))
+ : hook(hook), target(target), func(func)
{
- hook_associate (hook, run, this);
+ hook_associate(hook, run, this);
}
- ~HookReceiver ()
- { hook_dissociate (hook, run, this); }
+ ~HookReceiver() { hook_dissociate(hook, run, this); }
- HookReceiver (const HookReceiver &) = delete;
- void operator= (const HookReceiver &) = delete;
+ HookReceiver(const HookReceiver &) = delete;
+ void operator=(const HookReceiver &) = delete;
private:
const char * const hook;
T * const target;
- void (T::* const func) (D);
+ void (T::*const func)(D);
- static void run (void * d, void * recv_)
+ static void run(void * d, void * recv_)
{
- auto recv = (const HookReceiver *) recv_;
- (recv->target->* recv->func) (aud::from_ptr<D> (d));
+ auto recv = (const HookReceiver *)recv_;
+ (recv->target->*recv->func)(aud::from_ptr<D>(d));
}
};
@@ -147,29 +148,26 @@ template<class T>
class HookReceiver<T, void>
{
public:
- HookReceiver (const char * hook, T * target, void (T::* func) ()) :
- hook (hook),
- target (target),
- func (func)
+ HookReceiver(const char * hook, T * target, void (T::*func)())
+ : hook(hook), target(target), func(func)
{
- hook_associate (hook, run, this);
+ hook_associate(hook, run, this);
}
- ~HookReceiver ()
- { hook_dissociate (hook, run, this); }
+ ~HookReceiver() { hook_dissociate(hook, run, this); }
- HookReceiver (const HookReceiver &) = delete;
- void operator= (const HookReceiver &) = delete;
+ HookReceiver(const HookReceiver &) = delete;
+ void operator=(const HookReceiver &) = delete;
private:
const char * const hook;
T * const target;
- void (T::* const func) ();
+ void (T::*const func)();
- static void run (void *, void * recv_)
+ static void run(void *, void * recv_)
{
- auto recv = (const HookReceiver *) recv_;
- (recv->target->* recv->func) ();
+ auto recv = (const HookReceiver *)recv_;
+ (recv->target->*recv->func)();
}
};