|
SObjectizer
5.5
|
Class for the representing agent state. More...
#include <state.hpp>
Classes | |
| struct | time_limit_t |
Public Types | |
| enum | history_t { history_t::none, history_t::shallow, history_t::deep } |
| Type of history for state. More... | |
| using | path_t = std::array< const state_t *, max_deep > |
| A type for representation of state's path. More... | |
| using | on_enter_handler_t = std::function< void() > |
| Type of function to be called on enter to the state. More... | |
| using | on_exit_handler_t = std::function< void() > |
| Type of function to be called on exit from the state. More... | |
| using | duration_t = std::chrono::high_resolution_clock::duration |
| Alias for duration type. More... | |
Public Member Functions | |
| state_t (agent_t *agent) | |
| state_t (agent_t *agent, history_t state_history) | |
| state_t (agent_t *agent, std::string state_name) | |
| state_t (agent_t *agent, std::string state_name, history_t state_history) | |
| state_t (initial_substate_of parent) | |
| Constructor for the case when state is the initial substate of some parent state. More... | |
| state_t (initial_substate_of parent, history_t state_history) | |
| Constructor for the case when state is the initial substate of some parent state. More... | |
| state_t (initial_substate_of parent, std::string state_name) | |
| Constructor for the case when state is the initial substate of some parent state. More... | |
| state_t (initial_substate_of parent, std::string state_name, history_t state_history) | |
| Constructor for the case when state is the initial substate of some parent state. More... | |
| state_t (substate_of parent) | |
| Constructor for the case when state is a substate of some parent state. More... | |
| state_t (substate_of parent, history_t state_history) | |
| Constructor for the case when state is a substate of some parent state. More... | |
| state_t (substate_of parent, std::string state_name) | |
| Constructor for the case when state is a substate of some parent state. More... | |
| state_t (substate_of parent, std::string state_name, history_t state_history) | |
| Constructor for the case when state is a substate of some parent state. More... | |
| state_t (state_t &&other) | |
| Move constructor. More... | |
| ~state_t () | |
| bool | operator== (const state_t &state) const |
| bool | operator!= (const state_t &state) const |
| std::string | query_name () const |
| Get textual name of the state. More... | |
| bool | is_target (const agent_t *agent) const |
| Does agent owner of this state? More... | |
| void | activate () const |
| Switch agent to that state. More... | |
| bool | is_active () const |
| Is this state or any of its substates activated? More... | |
| void | clear_history () |
| Clear state history. More... | |
| template<typename... Args> | |
| const state_t & | event (Args &&... args) const |
| Helper for subscription of event handler in this state. More... | |
| template<typename... Args> | |
| state_t & | event (Args &&... args) |
| template<typename... Args> | |
| const state_t & | event (mbox_t from, Args &&... args) const |
| Helper for subscription of event handler in this state. More... | |
| template<typename... Args> | |
| state_t & | event (mbox_t from, Args &&... args) |
| template<typename Signal , typename... Args> | |
| const state_t & | event (Args &&... args) const |
| Helper for subscription of event handler in this state. More... | |
| template<typename Signal , typename... Args> | |
| state_t & | event (Args &&... args) |
| template<typename Signal , typename... Args> | |
| const state_t & | event (mbox_t from, Args &&... args) const |
| Helper for subscription of event handler in this state. More... | |
| template<typename Signal , typename... Args> | |
| state_t & | event (mbox_t from, Args &&... args) |
| template<typename Msg > | |
| bool | has_subscription (const mbox_t &from) const |
| Check the presence of a subscription. More... | |
| template<typename Method_Pointer > | |
| bool | has_subscription (const mbox_t &from, Method_Pointer &&pfn) const |
| Check the presence of a subscription. More... | |
| template<typename Msg > | |
| void | drop_subscription (const mbox_t &from) const |
| Drop subscription. More... | |
| template<typename Method_Pointer > | |
| void | drop_subscription (const mbox_t &from, Method_Pointer &&pfn) const |
| Drop subscription. More... | |
| template<typename Msg > | |
| const state_t & | transfer_to_state (mbox_t from, const state_t &target_state) const |
| An instruction for switching agent to the specified state and transfering event proceessing to new state. More... | |
| template<typename Msg > | |
| const state_t & | transfer_to_state (const state_t &target_state) const |
| An instruction for switching agent to the specified state and transfering event proceessing to new state. More... | |
| template<typename Msg > | |
| state_t & | transfer_to_state (mbox_t from, const state_t &target_state) |
| An instruction for switching agent to the specified state and transfering event proceessing to new state. More... | |
| template<typename Msg > | |
| state_t & | transfer_to_state (const state_t &target_state) |
| An instruction for switching agent to the specified state and transfering event proceessing to new state. More... | |
| template<typename Msg > | |
| const state_t & | just_switch_to (mbox_t from, const state_t &target_state) const |
| Define handler which only switches agent to the specified state. More... | |
| template<typename Msg > | |
| const state_t & | just_switch_to (const state_t &target_state) const |
| Define handler which only switches agent to the specified state. More... | |
| template<typename Msg > | |
| state_t & | just_switch_to (mbox_t from, const state_t &target_state) |
| Define handler which only switches agent to the specified state. More... | |
| template<typename Msg > | |
| state_t & | just_switch_to (const state_t &target_state) |
| Define handler which only switches agent to the specified state. More... | |
| template<typename Msg > | |
| const state_t & | suppress () const |
| Suppress processing of event in this state. More... | |
| template<typename Msg > | |
| const state_t & | suppress (mbox_t from) const |
| Suppress processing of event in this state. More... | |
| template<typename Msg > | |
| state_t & | suppress () |
| Suppress processing of event in this state. More... | |
| template<typename Msg > | |
| state_t & | suppress (mbox_t from) |
| Suppress processing of event in this state. More... | |
Method for manupulation of enter/exit handlers. | |
| state_t & | on_enter (on_enter_handler_t handler) |
| Set on enter handler. More... | |
| template<typename Method_Pointer > | |
| std::enable_if< details::is_agent_method_pointer< Method_Pointer >::value, state_t &>::type | on_enter (Method_Pointer pfn) |
| Set on enter handler. More... | |
| const on_enter_handler_t & | on_enter () const |
| Query on enter handler. More... | |
| state_t & | on_exit (on_exit_handler_t handler) |
| Set on exit handler. More... | |
| template<typename Method_Pointer > | |
| std::enable_if< details::is_agent_method_pointer< Method_Pointer >::value, state_t &>::type | on_exit (Method_Pointer pfn) |
| Set on exit handler. More... | |
| const on_exit_handler_t & | on_exit () const |
| Query on enter handler. More... | |
Methods for dealing with state's time limit. | |
| state_t & | time_limit (duration_t timeout, const state_t &state_to_switch) |
| Set up a time limit for the state. More... | |
| state_t & | drop_time_limit () |
| Drop time limit for the state if defined. More... | |
Static Public Attributes | |
| static const std::size_t | max_deep = 16 |
| Max deep of nested states. More... | |
Private Member Functions | |
| state_t (const state_t &)=delete | |
| state_t & | operator= (const state_t &)=delete |
| state_t (agent_t *target_agent, std::string state_name, state_t *parent_state, std::size_t nested_level, history_t state_history) | |
| Fully initialized constructor. More... | |
| template<typename... Args> | |
| const state_t & | subscribe_message_handler (const mbox_t &from, Args &&... args) const |
| A helper for handle-methods implementation. More... | |
| template<typename Signal , typename... Args> | |
| const state_t & | subscribe_signal_handler (const mbox_t &from, Args &&... args) const |
| A helper for handle-methods implementation. More... | |
Methods to be used by agents. | |
| const state_t * | parent_state () const |
| Get a parent state if exists. More... | |
| const state_t * | actual_state_to_enter () const |
| Find actual state to be activated for agent. More... | |
| std::size_t | nested_level () const |
| Query nested level for the state. More... | |
| void | fill_path (path_t &path) const |
| A helper method for building a path from top-level state to this state. More... | |
| void | update_history_in_parent_states () const |
| A helper method which is used during state change for update state with history. More... | |
| void | handle_time_limit_on_enter () const |
| A special handler of time limit to be used on entering into state. More... | |
| void | handle_time_limit_on_exit () const |
| A special handler of time limit to be used on exiting from state. More... | |
| void | call_on_enter () const |
| Call for on enter handler if defined. More... | |
| void | call_on_exit () const |
| Call for on exit handler if defined. More... | |
Private Attributes | |
| agent_t *const | m_target_agent |
| Owner of this state. More... | |
| std::string | m_state_name |
| State name. More... | |
| state_t * | m_parent_state |
| Parent state. More... | |
| const state_t * | m_initial_substate |
| The initial substate. More... | |
| history_t | m_state_history |
| Type of state history. More... | |
| const state_t * | m_last_active_substate |
| Last active substate. More... | |
| std::size_t | m_nested_level |
| Nesting level for state. More... | |
| size_t | m_substate_count |
| Number of substates. More... | |
| on_enter_handler_t | m_on_enter |
| Handler for the enter to the state. More... | |
| on_exit_handler_t | m_on_exit |
| Handler for the exit from the state. More... | |
| std::unique_ptr< time_limit_t > | m_time_limit |
| A definition of time limit for the state. More... | |
Friends | |
| class | agent_t |
Class for the representing agent state.
| using so_5::state_t::duration_t = std::chrono::high_resolution_clock::duration |
Alias for duration type.
| using so_5::state_t::on_enter_handler_t = std::function< void() > |
Type of function to be called on enter to the state.
| using so_5::state_t::on_exit_handler_t = std::function< void() > |
Type of function to be called on exit from the state.
| using so_5::state_t::path_t = std::array< const state_t *, max_deep > |
A type for representation of state's path.
|
strong |
|
privatedelete |
| so_5::state_t::state_t | ( | agent_t * | agent | ) |
| agent | State owner. |
| agent | State owner. |
| state_history | Type of state history. |
| so_5::state_t::state_t | ( | agent_t * | agent, |
| std::string | state_name | ||
| ) |
| agent | State owner. |
| state_name | State name. |
| agent | State owner. |
| state_name | State name. |
| state_history | Type of state history. |
| so_5::state_t::state_t | ( | initial_substate_of | parent | ) |
Constructor for the case when state is the initial substate of some parent state.
| parent | Parent state. |
| so_5::state_t::state_t | ( | initial_substate_of | parent, |
| history_t | state_history | ||
| ) |
Constructor for the case when state is the initial substate of some parent state.
| parent | Parent state. |
| state_history | Type of state history. |
| so_5::state_t::state_t | ( | initial_substate_of | parent, |
| std::string | state_name | ||
| ) |
Constructor for the case when state is the initial substate of some parent state.
| parent | Parent state. |
| state_name | State name. |
| so_5::state_t::state_t | ( | initial_substate_of | parent, |
| std::string | state_name, | ||
| history_t | state_history | ||
| ) |
Constructor for the case when state is the initial substate of some parent state.
| parent | Parent state. |
| state_name | State name. |
| state_history | Type of state history. |
| so_5::state_t::state_t | ( | substate_of | parent | ) |
Constructor for the case when state is a substate of some parent state.
| parent | Parent state. |
| so_5::state_t::state_t | ( | substate_of | parent, |
| history_t | state_history | ||
| ) |
Constructor for the case when state is a substate of some parent state.
| parent | Parent state. |
| state_history | Type of state history. |
| so_5::state_t::state_t | ( | substate_of | parent, |
| std::string | state_name | ||
| ) |
Constructor for the case when state is a substate of some parent state.
| parent | Parent state. |
| state_name | State name. |
| so_5::state_t::state_t | ( | substate_of | parent, |
| std::string | state_name, | ||
| history_t | state_history | ||
| ) |
Constructor for the case when state is a substate of some parent state.
| parent | Parent state. |
| state_name | State name. |
| state_history | Type of state history. |
| so_5::state_t::state_t | ( | state_t && | other | ) |
Move constructor.
| so_5::state_t::~state_t | ( | ) |
|
private |
Fully initialized constructor.
| target_agent | Owner of this state. |
| state_name | Name for this state. |
| parent_state | Parent state. nullptr means that there is no parent state. |
| nested_level | Nesting deep for this state. Value 0 means this state is a top-level state. |
| state_history | Type of state history. |
| void so_5::state_t::activate | ( | ) | const |
Switch agent to that state.
|
private |
Find actual state to be activated for agent.
| exception_t | if (*this) is a composite state but m_initial_substate is not defined. |
|
inlineprivate |
Call for on enter handler if defined.
|
inlineprivate |
Call for on exit handler if defined.
|
inline |
Clear state history.
| void so_5::state_t::drop_subscription | ( | const mbox_t & | from | ) | const |
Drop subscription.
Drops the subscription for the message/signal of type Msg for the state (if this subscription is present). Do nothing if subscription is not exists.
Usage example:
| void so_5::state_t::drop_subscription | ( | const mbox_t & | from, |
| Method_Pointer && | pfn | ||
| ) | const |
Drop subscription.
Drops the subscription for the message/signal for the state (if this subscription is present). Do nothing if subscription is not exists.
Type of a message is deduced from event handler signature.
Usage example:
| state_t & so_5::state_t::drop_time_limit | ( | ) |
Drop time limit for the state if defined.
| const state_t & so_5::state_t::event | ( | Args &&... | args | ) | const |
Helper for subscription of event handler in this state.
|
inline |
| const state_t & so_5::state_t::event | ( | mbox_t | from, |
| Args &&... | args | ||
| ) | const |
Helper for subscription of event handler in this state.
| const state_t & so_5::state_t::event | ( | Args &&... | args | ) | const |
Helper for subscription of event handler in this state.
|
inline |
| const state_t & so_5::state_t::event | ( | mbox_t | from, |
| Args &&... | args | ||
| ) | const |
Helper for subscription of event handler in this state.
|
inline |
|
inlineprivate |
A helper method for building a path from top-level state to this state.
|
private |
A special handler of time limit to be used on entering into state.
|
private |
A special handler of time limit to be used on exiting from state.
| bool so_5::state_t::has_subscription | ( | const mbox_t & | from | ) | const |
Check the presence of a subscription.
Usage example:
| bool so_5::state_t::has_subscription | ( | const mbox_t & | from, |
| Method_Pointer && | pfn | ||
| ) | const |
Check the presence of a subscription.
Type is deduced from the signature of event_handler.
Usage example:
|
inline |
Is this state or any of its substates activated?
| bool so_5::state_t::is_target | ( | const agent_t * | agent | ) | const |
Does agent owner of this state?
| const state_t & so_5::state_t::just_switch_to | ( | mbox_t | from, |
| const state_t & | target_state | ||
| ) | const |
Define handler which only switches agent to the specified state.
| const state_t & so_5::state_t::just_switch_to | ( | const state_t & | target_state | ) | const |
Define handler which only switches agent to the specified state.
|
inline |
Define handler which only switches agent to the specified state.
|
inline |
Define handler which only switches agent to the specified state.
|
inlineprivate |
Query nested level for the state.
|
inline |
Set on enter handler.
| std::enable_if< details::is_agent_method_pointer< Method_Pointer >::value, state_t &>::type so_5::state_t::on_enter | ( | Method_Pointer | pfn | ) |
Set on enter handler.
|
inline |
Query on enter handler.
|
inline |
Set on exit handler.
| std::enable_if< details::is_agent_method_pointer< Method_Pointer >::value, state_t &>::type so_5::state_t::on_exit | ( | Method_Pointer | pfn | ) |
Set on exit handler.
|
inline |
Query on enter handler.
|
inline |
| bool so_5::state_t::operator== | ( | const state_t & | state | ) | const |
|
inlineprivate |
Get a parent state if exists.
| std::string so_5::state_t::query_name | ( | ) | const |
Get textual name of the state.
|
private |
A helper for handle-methods implementation.
|
private |
A helper for handle-methods implementation.
| const state_t & so_5::state_t::suppress | ( | ) | const |
Suppress processing of event in this state.
Suppress processing of event in this state.
|
inline |
Suppress processing of event in this state.
Suppress processing of event in this state.
| state_t & so_5::state_t::time_limit | ( | duration_t | timeout, |
| const state_t & | state_to_switch | ||
| ) |
Set up a time limit for the state.
| timeout | Max duration of time for staying in this state. |
| state_to_switch | A new state to be switched to. |
| const state_t & so_5::state_t::transfer_to_state | ( | mbox_t | from, |
| const state_t & | target_state | ||
| ) | const |
An instruction for switching agent to the specified state and transfering event proceessing to new state.
| const state_t & so_5::state_t::transfer_to_state | ( | const state_t & | target_state | ) | const |
An instruction for switching agent to the specified state and transfering event proceessing to new state.
|
inline |
An instruction for switching agent to the specified state and transfering event proceessing to new state.
|
inline |
An instruction for switching agent to the specified state and transfering event proceessing to new state.
|
private |
A helper method which is used during state change for update state with history.
|
friend |
|
private |
The initial substate.
|
private |
Last active substate.
|
private |
Nesting level for state.
|
private |
Handler for the enter to the state.
|
private |
Handler for the exit from the state.
|
private |
Parent state.
|
private |
Type of state history.
|
private |
State name.
|
private |
Number of substates.
|
private |
Owner of this state.
|
private |
A definition of time limit for the state.
|
static |
Max deep of nested states.
1.8.14