20 #ifndef HEDGEHOG_ABSTRACT_STATE_H 21 #define HEDGEHOG_ABSTRACT_STATE_H 25 #include <shared_mutex> 27 #include "../../behavior/execute.h" 28 #include "../../tools/traits.h" 57 template<
class StateOutput,
class ...StateInputs>
59 static_assert(traits::isUnique<StateInputs...>,
"A Task can't accept multiple inputs with the same type.");
60 static_assert(
sizeof... (StateInputs) >= 1,
"A state need to have one output type and at least one output type.");
62 mutable std::unique_ptr<std::shared_mutex>
stateMutex_ =
nullptr;
63 std::unique_ptr<std::queue<std::shared_ptr<StateOutput>>>
readyList_ =
nullptr;
69 stateMutex_ = std::make_unique<std::shared_mutex>();
70 readyList_ = std::make_unique<std::queue<std::shared_ptr<StateOutput>>>();
78 std::unique_ptr<std::queue<std::shared_ptr<StateOutput>>>
const &
readyList()
const {
return readyList_; }
82 void push(std::shared_ptr<StateOutput>
const &elem) { readyList_->push(elem); }
87 std::shared_ptr<StateOutput> elem = readyList_->front();
93 void lock() { stateMutex_->lock(); }
96 void unlock() { stateMutex_->unlock(); }
100 #endif //HEDGEHOG_ABSTRACT_STATE_H AbstractState()
Default constructor, initialize the mutex (AbstractState::stateMutex_) and the ready list (AbstractSt...
std::unique_ptr< std::queue< std::shared_ptr< StateOutput > > > readyList_
State Ready list.
void lock()
Lock the state.
State Interface for managing computation, need a corresponding AbstractStateManager to be embedded in...
std::unique_ptr< std::shared_mutex > stateMutex_
State Mutex.
void unlock()
Unlock the state.
Execute Behavior definition, node that has an execution for an Input data type.
virtual ~AbstractState()=default
Default destructor.
std::shared_ptr< StateOutput > frontAndPop()
Used by AbstractStateManager to get the ready list's front element.
std::unique_ptr< std::queue< std::shared_ptr< StateOutput > > > const & readyList() const
Ready list accessor.
void push(std::shared_ptr< StateOutput > const &elem)
Add an element to the ready list.