3 #include <runner/machineRunner.h>
16 typename ListenerType,
29 typename MachineType_,
30 typename ListenerType_,
52 typedef std::integral_constant<bool, !std::is_same_v<ListenerType, void>>
IsListened;
55 static constexpr
bool IsListened_v = IsListened::value;
63 static constexpr
bool IsAccepting_v = IsAccepting::value;
71 static constexpr
bool IsAlternating_v = IsAlternating::value;
79 "The only valid value of template parameter ListenerConstructorArgs is the default one.");
89 currentStateAndId(getInitialStateAndId()),
99 currentStateAndId(other.currentStateAndId),
100 memory(other.memory),
101 running(other.running)
109 currentStateAndId(std::move(other.currentStateAndId)),
110 memory(std::move(other.memory)),
111 running(std::move(other.running))
120 MachineRunner_::operator=(other);
121 currentStateAndId = other.currentStateAndId;
122 memory = other.memory;
123 running = other.running;
134 MachineRunner_::operator=(std::move(other));
135 currentStateAndId = std::move(other.currentStateAndId);
136 memory = std::move(other.memory);
137 running = std::move(other.running);
164 if constexpr (IsListened_v) {
165 return std::get<StateType>(currentStateAndId);
167 return currentStateAndId;
178 virtual void step(
size_t nbIter = 1)
override {
179 for(
size_t i = 0; i < nbIter && running; ++i) {
190 #pragma clang diagnostic push
191 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
200 if constexpr (!IsAccepting_v) {
203 else if constexpr (IsAccepting_v && !IsAlternating_v) {
204 return this->machine.isAcceptingConfiguration(getCurrentState(), this->getStorage());
206 switch (this->machine.isAcceptingConfiguration(getCurrentState(), memory)) {
207 case Machine::Acceptance::Accept:
208 case Machine::Acceptance::Universal:
210 case Machine::Acceptance::Reject:
211 case Machine::Acceptance::Existential:
216 #pragma clang diagnostic pop
223 if constexpr (IsListened_v) {
224 return {MachineRunner_::machine.getInitialState(), MachineRunner_::listener.getInitialId()};
226 return MachineRunner_::machine.getInitialState();
237 if (!this->running) {
241 if constexpr (IsListened_v) {
242 auto& [currentState, currentId] = currentStateAndId;
243 std::optional<std::pair<const TransitionType &, ApplyHelperType>> matchingTransition =
244 MachineRunner_::machine.getMatchingTransition(currentState, memory);
246 if (matchingTransition) {
247 ListenerIdType id = this->listener.registerPreTransition(currentState, memory, currentId);
248 auto&[transition, helper] = *matchingTransition;
249 currentState = transition.apply(
254 this->running = this->running && !this->machine.isHaltingConfiguration(currentState, memory);
255 this->listener.registerPostTransition(
id, currentState, memory, transition, helper, this->running);
258 this->running =
false;
259 this->listener.registerNoTransition(currentId, currentState, memory);
262 auto& currentState = currentStateAndId;
263 std::optional<std::pair<const TransitionType &, ApplyHelperType>> matchingTransition =
264 MachineRunner_::machine.getMatchingTransition(currentState, memory);
266 if (matchingTransition) {
267 auto&[transition, helper] = *matchingTransition;
268 currentState = transition.apply(
273 this->running = this->running && !this->machine.isHaltingConfiguration(currentState, memory);
275 this->running =
false;