Libmacro  0.2
Libmacro is an extensible macro and hotkey library.
trigger_functions.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_TRIGGER_FUNCTIONS_H_
24 #define MCR_EXTRAS_TRIGGER_FUNCTIONS_H_
25 
26 #include <QtCore>
27 
28 #include "mcr/extras/iserializer.h"
30 
31 namespace mcr
32 {
33 class SerTrigger;
35 class TriggerFunctionsPrivate;
37 class MCR_API TriggerFunctions : public QObject
38 {
39  Q_OBJECT
40  friend class TriggerFunctionsPrivate;
41 public:
42  explicit TriggerFunctions(QObject *parent = nullptr,
43  Libmacro *libmacroPt = nullptr);
44  TriggerFunctions(const TriggerFunctions &) = delete;
45  virtual ~TriggerFunctions() override;
46  TriggerFunctions &operator =(const TriggerFunctions &) = delete;
47 
48  Q_INVOKABLE QVariant id(const QString &name) const;
49  Q_INVOKABLE QString name(const QVariant &id) const;
50 
51  Libmacro &context() const
52  {
53  return *_context;
54  }
55 
56  SerTrigger *serializer(size_t id) const;
57  SerTrigger *serializer(const QVariant &id) const
58  {
59  return serializer(id.value<size_t>());
60  }
61  void setSerializer(size_t id, SerTrigger *(*serFnc)());
62 private:
63  Libmacro *_context;
64  TriggerFunctionsPrivate *_private;
65 };
66 
68 class SerTriggerPrivate;
69 class MCR_API SerTrigger : public ISerializer, public TriggerBuilder
70 {
71  friend class SerTriggerPrivate;
72 public:
77  typedef SerTrigger *(*get_serializer)();
79  typedef QVariant (*get)(const SerTrigger &container);
80  typedef void (*set)(SerTrigger &container, const QVariant &value);
81 
82  SerTrigger(size_t reserveKeys = 0, mcr_ITrigger *valueInterface = nullptr);
83  SerTrigger(const SerTrigger &) = default;
84  virtual ~SerTrigger() override;
85  SerTrigger &operator =(const SerTrigger &) = delete;
86 
87  virtual size_t keyCount(bool canonical) const override;
88  virtual QString *keysArray(bool canonical) const override;
89  virtual QVariant value(const QString &name) const override;
90  virtual void setValue(const QString &name, const QVariant &val) override;
91 
92  virtual inline void setValueInterface(mcr_ITrigger *itrigPt)
93  {
94  mcr_throwif(!itrigPt, EFAULT);
95  _valueInterface = itrigPt;
96  }
97  /* Will modify keys, getMap, and setMap */
98  virtual void setMaps(const QString &key, get fnGet, set fnSet);
99  /* Will modify keysCanonical, getMap, and setMap */
100  virtual void setMapsCanonical(const QString &key, get fnGet, set fnSet);
101  /* Will add to both keys and keysCanonical, and add to both getMap and setMap. */
102  virtual void setMapsGeneric(const QString &key, get fnGet, set fnSet)
103  {
104  setMaps(key, fnGet, fnSet);
105  setMapsCanonical(key, fnGet, fnSet);
106  }
107 private:
108  mcr_ITrigger *_valueInterface;
109  /* Non-exportable */
110  SerTriggerPrivate *_private;
111 };
112 
113 class MCR_API SerAction : public SerTrigger
114 {
115 public:
116  SerAction();
117 
118  static QVariant modifiers(const SerTrigger &container)
119  {
120  return container.empty() ? 0 : container.data<mcr_Action>()->modifiers;
121  }
122  static void setModifiers(SerTrigger &container, const QVariant &val)
123  {
124  container.mkdata().data<mcr_Action>()->modifiers = val.toUInt();
125  }
126  static QVariant triggerFlags(const SerTrigger &container)
127  {
128  return container.empty() ? 0 : container.data<mcr_Action>()->trigger_flags;
129  }
130  static void setTriggerFlags(SerTrigger &container, const QVariant &val)
131  {
132  container.mkdata().data<mcr_Action>()->trigger_flags = val.toUInt();
133  }
134 };
135 
136 class MCR_API SerAlarm : public SerTrigger
137 {
138 public:
139  SerAlarm();
140 
141  static QVariant second(const SerTrigger &container);
142  static void setSecond(SerTrigger &container, const QVariant &val);
143  static QVariant minute(const SerTrigger &container);
144  static void setMinute(SerTrigger &container, const QVariant &val);
145  static QVariant hour(const SerTrigger &container);
146  static void setHour(SerTrigger &container, const QVariant &val);
147  static QVariant days(const SerTrigger &container);
148  static void setDays(SerTrigger &container, const QVariant &val);
149 };
150 
151 class MCR_API SerStaged : public SerTrigger
152 {
153 public:
154  SerStaged();
155 
156  static QVariant stages(const SerTrigger &container);
157  static void setStages(SerTrigger &container, const QVariant &val);
158 };
159 }
160 
161 #endif
#define mcr_throwif(condition, errorNumber)
Definition: defines.h:415
Libmacro, by Jonathan Pelletier, New Paradigm Software. Alpha version.
Definition: classes.h:31
Get/Set all values of an object.
Definition: iserializer.h:35