libsidplayfp 2.15.0
EventCallback.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright (C) 2011-2015 Leandro Nini
5 * Copyright (C) 2009 Antti S. Lankila
6 * Copyright (C) 2001 Simon White
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#ifndef EVENTCALLBACK_H
24#define EVENTCALLBACK_H
25
26#include "Event.h"
27
28#include "sidcxx11.h"
29
30
31namespace libsidplayfp
32{
33
34template< class This >
35class EventCallback final : public Event
36{
37private:
38 using Callback = void (This::*)();
39
40private:
41 This &m_this;
42 Callback const m_callback;
43
44private:
45 void event() override { (m_this.*m_callback)(); }
46
47public:
48 EventCallback(const char* const name, This &object, Callback callback) :
49 Event(name),
50 m_this(object),
51 m_callback(callback)
52 {}
53};
54
55template< class This, void(This::*Callback)() >
56class FastEventCallback final : public Event
57{
58private:
59 This &m_this;
60
61private:
62 void event() override { (m_this.*Callback)(); }
63
64public:
65 FastEventCallback(const char* const name, This &object) :
66 Event(name),
67 m_this(object)
68 {}
69};
70
71}
72
73#endif // EVENTCALLBACK_H
Definition EventCallback.h:36
Definition Event.h:39
const char * name() const
Definition Event.h:72
Definition EventCallback.h:57