-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonitoringComponent.h
More file actions
49 lines (39 loc) · 890 Bytes
/
MonitoringComponent.h
File metadata and controls
49 lines (39 loc) · 890 Bytes
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
#pragma once
#include <ArduinoSTL.h>
#include "Ref.h"
using namespace std;
namespace MonitoringComponents {
class MonitoringComponent {
public:
MonitoringComponent(Ref<MonitoringComponent> parent = nullptr) : _parent(parent), _isLooping(false) {}
void loop() {
_isLooping = true;
loopChildren();
if (_isLooping) {
privateLoop();
}
}
protected:
void SkipLoop() {
_isLooping = false;
if (*_parent != nullptr) _parent->SkipLoop();
}
void RegisterChild(Ref<MonitoringComponent> child) {
_children.push_back(child);
}
private:
Ref<MonitoringComponent> _parent;
std::vector<Ref<MonitoringComponent>> _children;
bool _isLooping;
void loopChildren() {
for (int i = 0; i < _children.size(); i++) {
_children[i]->loop();
if (!_isLooping) {
SkipLoop();
return;
}
}
}
virtual void privateLoop() = 0;
};
};