-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy pathfsm_states.hpp
43 lines (32 loc) · 1.01 KB
/
fsm_states.hpp
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
#pragma once
#include "client_fsm_types.h"
#include <array>
#include <common/fsm_base_types.hpp>
#include <optional>
namespace fsm {
class States {
public:
// TODO In the future, we could ditch the optional here.
// Instead, each fsm would have 'inactive' phase (some of them already do).
using State = std::optional<BaseData>;
private:
std::array<State, static_cast<size_t>(ClientFSM::_count)> states;
public:
uint32_t generation = 0;
constexpr bool is_active(ClientFSM client_fsm) const {
return (*this)[client_fsm].has_value();
}
constexpr State &operator[](ClientFSM client_fsm) {
return states[static_cast<size_t>(client_fsm)];
}
constexpr const State &operator[](ClientFSM client_fsm) const {
return states[static_cast<size_t>(client_fsm)];
}
struct Top {
ClientFSM fsm_type;
BaseData data;
};
std::optional<Top> get_top() const;
constexpr auto operator<=>(const States &) const = default;
};
} // namespace fsm