35 lines
900 B
C++
35 lines
900 B
C++
#include "hierarchical_fsm.hpp"
|
|
#include <utility>
|
|
|
|
namespace hierarchical_fsm {
|
|
|
|
Machine::Machine(const Machine &) = default;
|
|
Machine &Machine::operator=(const Machine &) = default;
|
|
|
|
Status Machine::dispatch_many(const std::vector<RawEvent> &events,
|
|
std::vector<Step> &output)
|
|
{
|
|
output.clear();
|
|
if (!state_.configured) {
|
|
return Status::unconfigured;
|
|
}
|
|
if (events.size() > 128) {
|
|
return Status::invalid;
|
|
}
|
|
Machine &staged = *this;
|
|
std::vector<Step> result;
|
|
result.reserve(events.size());
|
|
for (const RawEvent &event : events) {
|
|
Step step;
|
|
const Status status = staged.dispatch(event, step);
|
|
if (status != Status::ok) {
|
|
return status;
|
|
}
|
|
result.push_back(std::move(step));
|
|
}
|
|
*this = std::move(staged);
|
|
output = std::move(result);
|
|
return Status::ok;
|
|
}
|
|
}
|