Libmacro  0.2
Libmacro is an extensible macro and hotkey library.
dispatcher.h
Go to the documentation of this file.
1 /* Libmacro - A multi-platform, extendable macro and hotkey C library
2  Copyright (C) 2013 Jonathan Pelletier, New Paradigm Software
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
23 #ifndef __cplusplus
24  #pragma message "C++ support is required for extras module"
25  #include "mcr/err.h"
26 #endif
27 
28 #ifndef MCR_EXTRAS_DISPATCHER_H_
29 #define MCR_EXTRAS_DISPATCHER_H_
30 
32 
33 namespace mcr
34 {
36 class DispatcherPrivate;
37 struct MCR_API Dispatcher
38 {
39  friend class DispatcherPrivate;
40  mcr_AbsDispatcher self;
41 
42  Dispatcher(Libmacro *ctx = nullptr);
43  Dispatcher(const Dispatcher &copytron);
44  virtual ~Dispatcher();
45  Dispatcher &operator =(const Dispatcher &copytron);
46 
47  inline mcr_AbsDispatcher &operator *()
48  {
49  return self;
50  }
51  inline const mcr_AbsDispatcher &operator *() const
52  {
53  return self;
54  }
55  static inline Dispatcher *offset(mcr_IDispatcher *originPt)
56  {
57  return mcr::offset<Dispatcher>(originPt);
58  }
59  static inline const Dispatcher *offset(const mcr_IDispatcher *originPt)
60  {
61  return mcr::offset<Dispatcher>(originPt);
62  }
63 
64  virtual void add(struct mcr_Signal *sigPt, void *receiver, mcr_dispatch_receive_fnc receiverFnc);
65  virtual void clear();
66  // dispatch = mcr_AbsKeyDispatcher_dispatch
67  virtual void modifier(struct mcr_Signal *, unsigned int *) {}
68  virtual void remove(void *remReceiver);
69  virtual void trim();
70 
71 private:
72  Libmacro *_context;
73  DispatchReceiverSet _receivers;
74  /* non-export */
75  DispatcherPrivate *_private;
76 
77  static void deinit(struct mcr_IDispatcher *idispPt)
78  {
79  mcr_throwif(!idispPt, EFAULT);
80  offset(idispPt)->clear();
81  }
82  static int add(struct mcr_IDispatcher *idispPt, struct mcr_Signal *sigPt, void *receiver, mcr_dispatch_receive_fnc receiverFnc);
83  static void clear(struct mcr_IDispatcher *idispPt);
84  // dispatch = mcr_AbsDispatcher_dispatch
85  static void modifier(struct mcr_IDispatcher *idispPt, struct mcr_Signal *sigPt, unsigned int *modifiersPt);
86  static void remove(struct mcr_IDispatcher *idispPt, void *remReceiver);
87  static void trim(struct mcr_IDispatcher *idispPt);
88 };
89 }
90 
91 #endif
#define mcr_throwif(condition, errorNumber)
Definition: defines.h:415
bool(* mcr_dispatch_receive_fnc)(struct mcr_DispatchReceiver *dispatchReceiver, struct mcr_Signal *dispatchSignal, unsigned int mods)
Definition: types.h:50
Raise a compiler error. Usage: #include "mcr/err.h"
Libmacro, by Jonathan Pelletier, New Paradigm Software. Alpha version.
Definition: classes.h:31
void(* trim)(struct mcr_IDispatcher *)
Definition: idispatcher.h:108
rT * offset(vT *valuePt)
Definition: functions.h:44