SObjectizer 5.8
|
Class for the representing agent state. More...
#include <state.hpp>
Classes | |
struct | time_limit_t |
Public Types | |
enum class | history_t { none , shallow , 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. | |
using | on_enter_handler_t = std::function< void() > |
Type of function to be called on enter to the state. | |
using | on_exit_handler_t = std::function< void() > |
Type of function to be called on exit from the state. | |
using | duration_t = std::chrono::high_resolution_clock::duration |
Alias for duration type. | |
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. | |
state_t (initial_substate_of parent, history_t state_history) | |
Constructor for the case when state is the initial substate of some parent state. | |
state_t (initial_substate_of parent, std::string state_name) | |
Constructor for the case when state is the initial substate of some parent state. | |
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. | |
state_t (substate_of parent) | |
Constructor for the case when state is a substate of some parent state. | |
state_t (substate_of parent, history_t state_history) | |
Constructor for the case when state is a substate of some parent state. | |
state_t (substate_of parent, std::string state_name) | |
Constructor for the case when state is a substate of some parent state. | |
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. | |
state_t (state_t &&other) | |
Move constructor. | |
~state_t () | |
bool | operator== (const state_t &state) const noexcept |
bool | operator!= (const state_t &state) const noexcept |
std::string | query_name () const |
Get textual name of the state. | |
bool | is_target (const agent_t *agent) const noexcept |
Is agent owner of this state? | |
void | activate () const |
Switch agent to that state. | |
bool | is_active () const noexcept |
Is this state or any of its substates activated? | |
void | clear_history () noexcept |
Clear state history. | |
template<typename... Args> | |
const state_t & | event (Args &&... args) const |
Helper for subscription of event handler in this state. | |
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. | |
template<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. | |
template<typename Method_Pointer > | |
bool | has_subscription (const mbox_t &from, Method_Pointer &&pfn) const |
Check the presence of a subscription. | |
template<typename Msg > | |
void | drop_subscription (const mbox_t &from) const |
Drop subscription. | |
template<typename Method_Pointer > | |
void | drop_subscription (const mbox_t &from, Method_Pointer &&pfn) const |
Drop subscription. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
template<typename Msg > | |
state_t & | just_switch_to (const state_t &target_state) |
Define handler which only switches agent to the specified state. | |
template<typename Msg > | |
const state_t & | suppress () const |
Suppress processing of event in this state. | |
template<typename Msg > | |
const state_t & | suppress (mbox_t from) const |
Suppress processing of event in this state. | |
template<typename Msg > | |
state_t & | suppress () |
Suppress processing of event in this state. | |
template<typename Msg > | |
state_t & | suppress (mbox_t from) |
Suppress processing of event in this state. | |
Method for manupulation of enter/exit handlers. | |
state_t & | on_enter (on_enter_handler_t handler) |
Set on enter handler. | |
template<typename Method_Pointer > | |
std::enable_if< details::is_agent_method_pointer< details::method_arity::nullary, Method_Pointer >::value, state_t & >::type | on_enter (Method_Pointer pfn) |
Set on enter handler. | |
const on_enter_handler_t & | on_enter () const |
Query on enter handler. | |
state_t & | on_exit (on_exit_handler_t handler) |
Set on exit handler. | |
template<typename Method_Pointer > | |
std::enable_if< details::is_agent_method_pointer< details::method_arity::nullary, Method_Pointer >::value, state_t & >::type | on_exit (Method_Pointer pfn) |
Set on exit handler. | |
const on_exit_handler_t & | on_exit () const |
Query on enter handler. | |
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. | |
state_t & | drop_time_limit () |
Drop time limit for the state if defined. | |
Static Public Attributes | |
static constexpr const std::size_t | max_deep = 16 |
Max deep of nested states. | |
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. | |
template<typename... Args> | |
const state_t & | subscribe_message_handler (const mbox_t &from, Args &&... args) const |
A helper for handle-methods implementation. | |
Methods to be used by agents. | |
const state_t * | parent_state () const noexcept |
Get a parent state if exists. | |
const state_t * | actual_state_to_enter () const |
Find actual state to be activated for agent. | |
std::size_t | nested_level () const noexcept |
Query nested level for the state. | |
void | fill_path (path_t &path) const noexcept |
A helper method for building a path from top-level state to this state. | |
void | update_history_in_parent_states () const |
A helper method which is used during state change for update state with history. | |
void | handle_time_limit_on_enter () const |
A special handler of time limit to be used on entering into state. | |
void | handle_time_limit_on_exit () const |
A special handler of time limit to be used on exiting from state. | |
void | call_on_enter () const noexcept |
Call for on enter handler if defined. | |
void | call_on_exit () const noexcept |
Call for on exit handler if defined. | |
Private Attributes | |
agent_t *const | m_target_agent |
Owner of this state. | |
std::string | m_state_name |
State name. | |
state_t * | m_parent_state |
Parent state. | |
const state_t * | m_initial_substate |
The initial substate. | |
history_t | m_state_history |
Type of state history. | |
const state_t * | m_last_active_substate |
Last active substate. | |
std::size_t | m_nested_level |
Nesting level for state. | |
size_t | m_substate_count |
Number of substates. | |
on_enter_handler_t | m_on_enter |
Handler for the enter to the state. | |
on_exit_handler_t | m_on_exit |
Handler for the exit from the state. | |
std::unique_ptr< time_limit_t > | m_time_limit |
A definition of time limit for the state. | |
Friends | |
class | agent_t |
Class for the representing agent state.
using so_5::state_t::duration_t = std::chrono::high_resolution_clock::duration |
using so_5::state_t::on_enter_handler_t = std::function< void() > |
using so_5::state_t::on_exit_handler_t = std::function< void() > |
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 | ) |
so_5::state_t::state_t | ( | agent_t * | agent, |
std::string | state_name ) |
so_5::state_t::state_t | ( | initial_substate_of | parent | ) |
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 ) |
so_5::state_t::state_t | ( | initial_substate_of | parent, |
std::string | state_name, | ||
history_t | state_history ) |
so_5::state_t::state_t | ( | substate_of | parent | ) |
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 ) |
so_5::state_t::state_t | ( | substate_of | parent, |
std::string | state_name, | ||
history_t | state_history ) |
so_5::state_t::state_t | ( | state_t && | other | ) |
|
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 |
|
private |
Find actual state to be activated for agent.
exception_t | if (*this) is a composite state but m_initial_substate is not defined. |
|
inlineprivatenoexcept |
|
inlineprivatenoexcept |
|
inlinenoexcept |
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.
|
inline |
const state_t & so_5::state_t::event | ( | Args &&... | args | ) | const |
Helper for subscription of event handler in this state.
const state_t & so_5::state_t::event | ( | mbox_t | from, |
Args &&... | args ) const |
Helper for subscription of event handler in this state.
|
inlineprivatenoexcept |
|
private |
|
private |
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:
|
inlinenoexcept |
Is this state or any of its substates activated?
|
noexcept |
|
inline |
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.
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.
|
inlineprivatenoexcept |
|
inline |
Query on enter handler.
std::enable_if< details::is_agent_method_pointer< details::method_arity::nullary, Method_Pointer >::value, state_t & >::type so_5::state_t::on_enter | ( | Method_Pointer | pfn | ) |
Set on enter handler.
|
inline |
Set on enter handler.
|
inline |
Query on enter handler.
std::enable_if< details::is_agent_method_pointer< details::method_arity::nullary, Method_Pointer >::value, state_t & >::type so_5::state_t::on_exit | ( | Method_Pointer | pfn | ) |
Set on exit handler.
|
inline |
Set on exit handler.
|
inlinenoexcept |
|
noexcept |
|
inlineprivatenoexcept |
std::string so_5::state_t::query_name | ( | ) | const |
|
inline |
Suppress processing of event in this state.
const state_t & so_5::state_t::suppress | ( | ) | const |
Suppress processing of event in this state.
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. |
|
inline |
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.
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.
|
private |
|
private |
The initial substate.
|
private |
Last active substate.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticconstexpr |