-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevicemanager.cpp
More file actions
74 lines (62 loc) · 2.11 KB
/
Copy pathdevicemanager.cpp
File metadata and controls
74 lines (62 loc) · 2.11 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "devicemanager.h"
#include "deviceconfigs/devicedefines.h"
#include "deviceconfigs/diffractiongrating.h"
#include "deviceconfigs/display.h"
#include "deviceconfigs/laser.h"
using std::make_shared;
using std::make_unique;
using std::shared_ptr;
DeviceManager::DeviceManager() : Singleton<DeviceManager>(*this) {}
void DeviceManager::addDevice(int type, int id) {
switch (type) {
case deviceType::TYPE_LASER:
_devices.push_back(make_unique<Laser>(id));
break;
case deviceType::TYPE_SHIELD:
_devices.push_back(make_unique<Display>(id));
break;
case deviceType::TYPE_DIFFRACTION_GRATING:
_devices.push_back(make_unique<DiffractionGrating>(id));
break;
default:
_devices.push_back(make_unique<Device>(type, id));
break;
}
}
void DeviceManager::addConnection(int sourceDevId,
int sourceOut,
int destDevId,
int destInput) {
getDeviceById(destDevId)->setConnection(
destInput, getDeviceById(sourceDevId), sourceOut);
}
void DeviceManager::removeDevice(int idDevice) {
auto iter = getDeviceIterById(idDevice);
if (iter != _devices.end()) {
_devices.erase(iter);
}
}
void DeviceManager::removeConnection(int sourceDevId,
int sourceOut,
int destDevId,
int destInput) {
Q_UNUSED(sourceDevId);
getDeviceById(destDevId)->setConnection(
destInput, make_shared<Device>(), sourceOut);
}
void DeviceManager::changeVariables(int id, VarList vars) {
if (id == -1) {
return;
}
getDeviceById(id)->setVariables(vars);
}
std::shared_ptr<Device> DeviceManager::getDeviceById(int id) {
auto iter = getDeviceIterById(id);
return iter != _devices.end() ? *iter : nullptr;
}
std::vector<std::shared_ptr<Device>>::iterator
DeviceManager::getDeviceIterById(int id) {
return std::find_if(_devices.begin(), _devices.end(), [id](auto device) {
return device->getId() == id;
});
}