19#ifndef HEDGEHOG_STATE_MANAGER_H_
20#define HEDGEHOG_STATE_MANAGER_H_
25#include "../../behavior/copyable.h"
26#include "../../behavior/task_node.h"
59template<
size_t Separator,
class ...AllTypes>
65 public tool::BehaviorMultiReceiversTypeDeducer_t<tool::Inputs<Separator, AllTypes...>>,
66 public tool::BehaviorMultiSendersTypeDeducer_t<tool::Outputs<Separator, AllTypes...>> {
80 std::string
const &
name =
"State manager",
82 : behavior::
TaskNode(std::make_shared<
core::CoreStateManager<Separator, AllTypes...>>(this,
87 tool::BehaviorMultiSendersTypeDeducer_t<tool::Outputs<Separator, AllTypes...>>(),
89 if (
state ==
nullptr) {
90 throw std::runtime_error(
"The state given to the state manager should be valid (!= nullptr).");
97 throw std::runtime_error(
"The core used by the state manager should be a CoreStateManager.");
112 tool::BehaviorMultiSendersTypeDeducer_t<tool::Outputs<Separator, AllTypes...>>() {
113 if (
state ==
nullptr) {
114 throw std::runtime_error(
"The state given to the state manager should be valid (!= nullptr).");
116 if (this->
core() ==
nullptr) {
117 throw std::runtime_error(
"The core given to the state manager should be valid (!= nullptr).");
123 throw std::runtime_error(
"The core used by the state manager should be a CoreStateManager.");
155 if (
copy ==
nullptr) {
156 std::ostringstream oss;
158 <<
"A copy of the state manager " << this->
name() <<
" has been invoked but return nullptr. "
159 <<
"Please implement the copyStateManager method to create a copy of the current state manager with the same state.";
160 throw std::runtime_error(oss.str());
162 if (
copy->state_ != this->state_) {
163 std::ostringstream oss;
164 oss <<
"A copy and the state manager \"" << this->
name() <<
"\" do not share the same state.\n";
165 throw std::runtime_error(oss.str());
173 virtual std::shared_ptr<
StateManager<Separator, AllTypes...>>
bool automaticStart() const
Automatic start flag accessor.
~StateManager() override=default
Default destructor for the state manager.
std::shared_ptr< AbstractState< Separator, AllTypes... > > const & state() const
AbstractState accessor.
std::shared_ptr< AbstractState< Separator, AllTypes... > > state_
AbstractState managed.
std::shared_ptr< core::CoreStateManager< Separator, AllTypes... > > const & coreStateManager() const
Accessor to the core.
std::shared_ptr< StateManager< Separator, AllTypes... > > copy() final
Provide a copy of the state manager.
StateManager(std::shared_ptr< AbstractState< Separator, AllTypes... > > state, std::string const &name="State manager", bool const automaticStart=false)
Main state manager constructor.
StateManager(std::shared_ptr< core::CoreStateManager< Separator, AllTypes... > > core, std::shared_ptr< AbstractState< Separator, AllTypes... > > state)
AbstractState Manager constructor with a user-custom core.
virtual std::shared_ptr< StateManager< Separator, AllTypes... > > copyStateManager(std::shared_ptr< AbstractState< Separator, AllTypes... > > state)
Customizable copy method.
bool canTerminate() const override
Default termination rule, it terminates if there is no predecessor connection and there is no input d...
std::shared_ptr< core::CoreStateManager< Separator, AllTypes... > > coreStateManager_
AbstractState manager core.
Behavior abstraction for nodes that expose termination condition.
Copy interface used to copy a node when either a group of nodes is created or a node is duplicated wh...
Copyable(size_t const numberThreads)
Copyable constructor, set the number of threads for a node.
std::string name() const
Node's name accessor.
std::shared_ptr< hh::core::abstraction::NodeAbstraction > const & core() const
Core accessor.
Behavior abstraction for TaskNode.
TaskNode(std::shared_ptr< hh::core::abstraction::TaskNodeAbstraction > core)
Constructor using a core.
AbstractState manager core.