Added ALL_STATES define

This commit is contained in:
CarlWachter 2024-01-30 13:01:42 +01:00
parent 93a4112f59
commit 96147df269
3 changed files with 27 additions and 2 deletions

View File

@ -59,7 +59,7 @@ namespace sta
/** /**
* @brief Register a thread to be managed by the manager. * @brief Register a thread to be managed by the manager.
*/ */
void registerThread(std::shared_ptr<TacosThread> thread, std::list<uint16_t> states); void registerThread(std::shared_ptr<TacosThread> thread, std::set<uint16_t> states);
void init() override; void init() override;

View File

@ -69,6 +69,23 @@
#include <functional> #include <functional>
#include <tuple> #include <tuple>
#include <set>
#include <algorithm>
/**
* @brief Addresses all states from 0 to STA_TACOS_NUM_STATES-1.
*
* @ingroup tacos_statemachine
*/
#define ALL_STATES std::set<uint16_t>{[]{ std::set<uint16_t> 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<uint16_t>
namespace sta namespace sta
{ {
@ -204,4 +221,12 @@ namespace sta
#endif // STA_TACOS_NUM_STATES #endif // STA_TACOS_NUM_STATES
/// Overwrite "-" operator for set.
template <typename T>
std::set<T> operator-(const std::set<T>& set1, const std::set<T>& set2) {
std::set<T> result;
std::set_difference(set1.begin(), set1.end(), set2.begin(), set2.end(), std::inserter(result, result.begin()));
return result;
}
#endif /* INCLUDE_TACOS_STATEMACHINE_HPP_ */ #endif /* INCLUDE_TACOS_STATEMACHINE_HPP_ */

View File

@ -18,7 +18,7 @@ namespace sta
{ {
namespace tacos namespace tacos
{ {
void Manager::registerThread(std::shared_ptr<TacosThread> thread, std::list<uint16_t> states) void Manager::registerThread(std::shared_ptr<TacosThread> thread, std::set<uint16_t> states)
{ {
for (uint16_t state : states) for (uint16_t state : states)
{ {