-
-
Notifications
You must be signed in to change notification settings - Fork 371
Expand file tree
/
Copy pathioregistry.h
More file actions
45 lines (35 loc) · 1.25 KB
/
Copy pathioregistry.h
File metadata and controls
45 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once
#include "iobase.h"
#include <QWidget>
#include "iodpad.h"
#include "iokeyboard.h"
#include "ioledmatrix.h"
#include "ioswitches.h"
/** @brief IORegistry
*
* This is where all peripherals should be registerred to be made available in
* the UI. The peripheral must be registerred three times:
* - Add it to the IOType enum
* - Add it to the IOTypeTitles map (Associate a name with the peripheral)
* - Add it to the IOFactories map (Associate a constructor with the peripheral)
*/
namespace Ripes {
enum IOType { LED_MATRIX, SWITCHES, DPAD, KEYBOARD, NPERIPHERALS };
template <typename T>
IOBase *createIO(QWidget *parent) {
static_assert(std::is_base_of<IOBase, T>::value);
return new T(parent);
}
using IOFactory = std::function<IOBase *(QWidget *parent)>;
const static std::map<IOType, QString> IOTypeTitles = {
{IOType::LED_MATRIX, "LED Matrix"},
{IOType::SWITCHES, "Switches"},
{IOType::DPAD, "D-Pad"},
{IOType::KEYBOARD, "Keyboard"}};
const static std::map<IOType, IOFactory> IOFactories = {
{IOType::LED_MATRIX, createIO<IOLedMatrix>},
{IOType::SWITCHES, createIO<IOSwitches>},
{IOType::DPAD, createIO<IODPad>},
{IOType::KEYBOARD, createIO<IOKeyboard>}};
} // namespace Ripes
Q_DECLARE_METATYPE(Ripes::IOType);