diff --git a/include/sta/tacos.hpp b/include/sta/tacos.hpp index b92f699..c5d6edc 100644 --- a/include/sta/tacos.hpp +++ b/include/sta/tacos.hpp @@ -68,7 +68,7 @@ namespace sta * @ingroup tacos_api */ template - std::shared_ptr addThread(std::list states, Args ... args) + std::shared_ptr addThread(std::set states, Args ... args) { std::shared_ptr thread_ptr = std::make_shared(args...); 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) {