Libmacro  0.2
Libmacro is an extensible macro and hotkey library.
itrigger_builder.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 MCR_EXTRAS_REFERENCES_ITRIGGER_BUILDER_H_
24 #define MCR_EXTRAS_REFERENCES_ITRIGGER_BUILDER_H_
25 
26 #include "mcr/extras/wrappers.h"
27 
28 namespace mcr
29 {
34 class MCR_API ITriggerBuilder
35 {
36 public:
40  ITriggerBuilder(Libmacro *context = nullptr);
41  ITriggerBuilder(const ITriggerBuilder &) = default;
42  virtual ~ITriggerBuilder() {}
43  inline ITriggerBuilder &operator =(const ITriggerBuilder &copytron) = delete;
44 
45  inline ITriggerBuilder &build(mcr_ITrigger *itrigPt)
46  {
47  setITrigger(itrigPt);
48  return *this;
49  }
50  inline ITriggerBuilder &build(size_t id)
51  {
52  setId(id);
53  return *this;
54  }
55  inline ITriggerBuilder &build(const char *name)
56  {
57  setName(name);
58  return *this;
59  }
60 
61  inline Libmacro &context() const
62  {
63  return *_context;
64  }
65 
71  virtual void registerType(const char *name,
72  const char * const*addNames = nullptr, size_t addNamesCount = 0);
73  virtual void unregisterType();
74 
76  virtual inline mcr_ITrigger *itrigger() const
77  {
78  return _itrigPt;
79  }
80  inline mcr_Interface *interface() const
81  {
82  return _itrigPt ? &_itrigPt->interface : NULL;
83  }
84  virtual inline void setITrigger(mcr_ITrigger *itrigPt)
85  {
86  _itrigPt = itrigPt;
87  }
88 
89  /* Interface */
91  virtual inline size_t id()
92  {
93  return mcr_ITrigger_id(_itrigPt);
94  }
95  virtual void setId(size_t val);
97  virtual const char *name();
98  virtual void setName(const char *name);
100  virtual inline size_t dataSize() const
101  {
102  return _itrigPt ? _itrigPt->interface.data_size : 0;
103  }
104  virtual inline void setDataSize(size_t newSize)
105  {
106  if (_itrigPt)
107  _itrigPt->interface.data_size = newSize;
108  }
109 
110  virtual inline mcr_data_fnc init() const
111  {
112  return _itrigPt ? _itrigPt->interface.init : nullptr;
113  }
114  virtual inline void setInit(mcr_data_fnc val)
115  {
116  if (_itrigPt)
117  _itrigPt->interface.init = val;
118  }
119 
120  virtual inline mcr_data_fnc deinit() const
121  {
122  return _itrigPt ? _itrigPt->interface.deinit : nullptr;
123  }
124  virtual inline void setDeinit(mcr_data_fnc val)
125  {
126  if (_itrigPt)
127  _itrigPt->interface.deinit = val;
128  }
129 
130  virtual inline mcr_compare_fnc compare() const
131  {
132  return _itrigPt ? _itrigPt->interface.compare : nullptr;
133  }
134  virtual inline void setCompare(mcr_compare_fnc val)
135  {
136  if (_itrigPt)
137  _itrigPt->interface.compare = val;
138  }
139 
140  virtual inline mcr_copy_fnc copy() const
141  {
142  return _itrigPt ? _itrigPt->interface.copy : nullptr;
143  }
144  virtual inline void setCopy(mcr_copy_fnc val)
145  {
146  if (_itrigPt)
147  _itrigPt->interface.copy = val;
148  }
149 
150  /* ITrigger */
151  virtual inline mcr_Trigger_receive_fnc receive() const
152  {
153  return _itrigPt ? _itrigPt->receive : nullptr;
154  }
155  virtual inline void setReceive(mcr_Trigger_receive_fnc fnc)
156  {
157  if (_itrigPt)
158  _itrigPt->receive = fnc;
159  }
160 
161  virtual mcr_IRegistry *registry();
162 private:
163  Libmacro *_context;
164  mcr_ITrigger *_itrigPt;
165 };
166 }
167 
168 #endif
int(* mcr_compare_fnc)(const void *lhsPt, const void *rhsPt)
Definition: comparison.h:53
virtual mcr_ITrigger * itrigger() const
MCR_API size_t mcr_ITrigger_id(struct mcr_ITrigger *itrigPt)
int(* mcr_data_fnc)(void *dataPt)
Definition: comparison.h:39
int(* mcr_copy_fnc)(void *destinationPt, const void *sourcePt)
Definition: comparison.h:46
C++ wrappers and extensions of C types.
Libmacro, by Jonathan Pelletier, New Paradigm Software. Alpha version.
Definition: classes.h:31
virtual size_t id()
virtual size_t dataSize() const