From 96147df269e06a92898dc78e7b155ad17db863fd Mon Sep 17 00:00:00 2001 From: CarlWachter Date: Tue, 30 Jan 2024 13:01:42 +0100 Subject: [PATCH] Added ALL_STATES define --- include/sta/tacos/manager.hpp | 2 +- include/sta/tacos/statemachine.hpp | 25 +++++++++++++++++++++++++ src/manager.cpp | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/sta/tacos/manager.hpp b/include/sta/tacos/manager.hpp index e9e7120..58e67a1 100644 --- a/include/sta/tacos/manager.hpp +++ b/include/sta/tacos/manager.hpp @@ -59,7 +59,7 @@ namespace sta /** * @brief Register a thread to be managed by the manager. */ - void registerThread(std::shared_ptr thread, std::list states); + void registerThread(std::shared_ptr thread, std::set states); void init() override; diff --git a/include/sta/tacos/statemachine.hpp b/include/sta/tacos/statemachine.hpp index 030e903..9305316 100644 --- a/include/sta/tacos/statemachine.hpp +++ b/include/sta/tacos/statemachine.hpp @@ -69,6 +69,23 @@ #include #include +#include +#include + + +/** + * @brief Addresses all states from 0 to STA_TACOS_NUM_STATES-1. + * + * @ingroup tacos_statemachine + */ +#define ALL_STATES std::set{[]{ std::set states; for (uint16_t i = 0; i < STA_TACOS_NUM_STATES; ++i) states.insert(i); return states; }() } + +/** + * @brief Shorthand to make own sets of states. Primarily for exlcusion via "-" operator. + * + * @ingroup tacos_statemachine + */ +#define state_set std::set namespace sta { @@ -204,4 +221,12 @@ namespace sta #endif // STA_TACOS_NUM_STATES +/// Overwrite "-" operator for set. +template +std::set operator-(const std::set& set1, const std::set& set2) { + std::set result; + std::set_difference(set1.begin(), set1.end(), set2.begin(), set2.end(), std::inserter(result, result.begin())); + return result; +} + #endif /* INCLUDE_TACOS_STATEMACHINE_HPP_ */ diff --git a/src/manager.cpp b/src/manager.cpp index 468c5fb..1c853a4 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -18,7 +18,7 @@ namespace sta { namespace tacos { - void Manager::registerThread(std::shared_ptr thread, std::list states) + void Manager::registerThread(std::shared_ptr thread, std::set states) { for (uint16_t state : states) {