-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathController.h
32 lines (26 loc) · 954 Bytes
/
Controller.h
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
#ifndef CONTROLLER_H
#define CONTROLLER_H
#include "Device.h"
template<typename T, typename E>
class Controller : public Device<T> {
protected:
ArrayList<String> _device_tags;
ArrayList<Device<E>> _devices;
void _attachDevice(const String &tag, Device<E> device) {
_device_tags.add(tag);
_devices.add(device);
device.tag(tag);
}
public:
Controller() : Device<T>() {}
int level() { return this->_parentTags.size(); }
const ArrayList<Device<E>> &devices() { return _devices; }
void device(const String &tag, const Device<E> &device) { _attachDevice(tag, device); }
Device<E> device(const String &tag) { return _devices.get(_device_tags.indexOf(tag)); }
void initialize(const ArrayList<String> &parentTags) override {
Device<E>::initialize(parentTags);
for (Device<E> d: _devices)
d.initialize(this->_parentTags + this->_tag);
}
};
#endif // CONTROLLER_H