Skip to content

Commit

Permalink
2.3.3
Browse files Browse the repository at this point in the history
internal maintenance update
  • Loading branch information
andrew-gresyk authored Dec 20, 2023
1 parent fd0373f commit d993031
Show file tree
Hide file tree
Showing 178 changed files with 35,966 additions and 17,255 deletions.
377 changes: 377 additions & 0 deletions development/hfsm2/detail/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,377 @@
namespace hfsm2 {
namespace detail {

////////////////////////////////////////////////////////////////////////////////

template <
FeatureTag NFeatureTag
, typename TContext
, typename TActivation
, typename TReactOrder

#if HFSM2_UTILITY_THEORY_AVAILABLE()
, typename TRank
, typename TUtility
, typename TRNG
#endif

, Short NSubstitutionLimit
HFSM2_IF_PLANS(, Long NTaskCapacity)
, typename TPayload
>
struct G_ final {
static constexpr FeatureTag FEATURE_TAG = NFeatureTag;

using Context = TContext;
using Activation = TActivation;
using ReactOrder = TReactOrder;

#if HFSM2_UTILITY_THEORY_AVAILABLE()
using Rank = TRank;
using Utility = TUtility;
using RNG = TRNG;
#endif

#if HFSM2_LOG_INTERFACE_AVAILABLE()
using LoggerInterface = LoggerInterfaceT<FEATURE_TAG, Context HFSM2_IF_UTILITY_THEORY(, Utility)>;
#endif

static constexpr Short SUBSTITUTION_LIMIT = NSubstitutionLimit;

#if HFSM2_PLANS_AVAILABLE()
static constexpr Long TASK_CAPACITY = NTaskCapacity;
#endif

using Payload = TPayload;
using Transition = TransitionT<Payload>;

#if HFSM2_PLANS_AVAILABLE()
using Task = TaskT<Payload>;
#endif

/// @brief Set Context type
/// @tparam T Context type for data shared between states and/or data interface between FSM and external code
template <typename T>
using ContextT = G_<FEATURE_TAG, T , Activation, ReactOrder HFSM2_IF_UTILITY_THEORY(, Rank, Utility, RNG), SUBSTITUTION_LIMIT HFSM2_IF_PLANS(, TASK_CAPACITY), Payload>;

/// @brief Select manual activation strategy
using ManualActivation = G_<FEATURE_TAG, Context, Manual , ReactOrder HFSM2_IF_UTILITY_THEORY(, Rank, Utility, RNG), SUBSTITUTION_LIMIT HFSM2_IF_PLANS(, TASK_CAPACITY), Payload>;

/// @brief Select event processing order
using BottomUpReactions = G_<FEATURE_TAG, Context, Activation, BottomUp HFSM2_IF_UTILITY_THEORY(, Rank, Utility, RNG), SUBSTITUTION_LIMIT HFSM2_IF_PLANS(, TASK_CAPACITY), Payload>;

#if HFSM2_UTILITY_THEORY_AVAILABLE()

/// @brief Set Rank type
/// @tparam T Rank type for 'TRank State::rank() const' method
template <typename T>
using RankT = G_<FEATURE_TAG, Context, Activation, ReactOrder , T , Utility, RNG , SUBSTITUTION_LIMIT HFSM2_IF_PLANS(, TASK_CAPACITY), Payload>;

/// @brief Set Utility type
/// @tparam T Utility type for 'TUtility State::utility() const' method
template <typename T>
using UtilityT = G_<FEATURE_TAG, Context, Activation, ReactOrder , Rank, T , RNG , SUBSTITUTION_LIMIT HFSM2_IF_PLANS(, TASK_CAPACITY), Payload>;

/// @brief Set RNG type
/// @tparam T RNG type used in 'Random' regions
template <typename T>
using RandomT = G_<FEATURE_TAG, Context, Activation, ReactOrder , Rank, Utility, T , SUBSTITUTION_LIMIT HFSM2_IF_PLANS(, TASK_CAPACITY), Payload>;

#endif

/// @brief Set Substitution limit
/// @tparam N Maximum number times 'guard()' methods can substitute their states for others
template <Long N>
using SubstitutionLimitN = G_<FEATURE_TAG, Context, Activation, ReactOrder HFSM2_IF_UTILITY_THEORY(, Rank, Utility, RNG), N HFSM2_IF_PLANS(, TASK_CAPACITY), Payload>;

#if HFSM2_PLANS_AVAILABLE()

/// @brief Set Task capacity
/// @tparam N Maximum number of tasks across all plans
template <Long N>
using TaskCapacityN = G_<FEATURE_TAG, Context, Activation, ReactOrder HFSM2_IF_UTILITY_THEORY(, Rank, Utility, RNG), SUBSTITUTION_LIMIT , N , Payload>;

#endif

/// @brief Set Transition Payload type
/// @tparam T Utility type for 'TUtility State::utility() const' method
template <typename T>
using PayloadT = G_<FEATURE_TAG, Context, Activation, ReactOrder HFSM2_IF_UTILITY_THEORY(, Rank, Utility, RNG), SUBSTITUTION_LIMIT HFSM2_IF_PLANS(, TASK_CAPACITY), T >;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#if HFSM2_UTILITY_THEORY_AVAILABLE()

struct UP final {
HFSM2_CONSTEXPR(14) UP(const Utility utility_ = Utility{1},
const Prong prong_ = INVALID_PRONG) noexcept
: utility{utility_}
, prong{prong_}
{}

Utility utility;
Prong prong;
};

#endif

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
};

////////////////////////////////////////////////////////////////////////////////

template <typename>
struct M_;

template <
FeatureTag NFeatureTag
, typename TContext
, typename TActivation
, typename TReactOrder

#if HFSM2_UTILITY_THEORY_AVAILABLE()
, typename TRank
, typename TUtility
, typename TRNG
#endif

, Short NSubstitutionLimit
HFSM2_IF_PLANS(, Long NTaskCapacity)
, typename TPayload
>
struct M_<
G_<
NFeatureTag
, TContext
, TActivation
, TReactOrder
HFSM2_IF_UTILITY_THEORY(, TRank, TUtility, TRNG)
, NSubstitutionLimit
HFSM2_IF_PLANS(, NTaskCapacity)
, TPayload
>
> final
{
using Cfg = G_<
NFeatureTag
, TContext
, TActivation
, TReactOrder
HFSM2_IF_UTILITY_THEORY(, TRank, TUtility, TRNG)
, NSubstitutionLimit
HFSM2_IF_PLANS(, NTaskCapacity)
, TPayload
>;

static constexpr FeatureTag FEATURE_TAG = NFeatureTag;

using Context = TContext;

#if HFSM2_UTILITY_THEORY_AVAILABLE()
using Utility = TUtility;
#endif

using Payload = TPayload;
using Transition = TransitionT<Payload>;

#if HFSM2_LOG_INTERFACE_AVAILABLE()
using LoggerInterface = typename Cfg::LoggerInterface;
#endif

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/// @brief Composite region ('changeTo<>()' into the region acts as 'restart<>()')
/// @tparam THead Head state
/// @tparam TSubStates Sub-states
template <typename THead, typename... TSubStates>
using Composite = CI_<Strategy::Composite, THead, TSubStates...>;

/// @brief Headless composite region ('changeTo<>()' into the region acts as 'restart<>()')
/// @tparam TSubStates Sub-states
template < typename... TSubStates>
using CompositePeers = CI_<Strategy::Composite, void, TSubStates...>;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/// @brief Resumable region ('changeTo<>()' into the region acts as 'resume<>()')
/// @tparam THead Head state
/// @tparam TSubStates Sub-states
template <typename THead, typename... TSubStates>
using Resumable = CI_<Strategy::Resumable, THead, TSubStates...>;

/// @brief Headless resumable region ('changeTo<>()' into the region acts as 'resume<>()')
/// @tparam TSubStates Sub-states
template < typename... TSubStates>
using ResumablePeers = CI_<Strategy::Resumable, void, TSubStates...>;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/// @brief Selectable region ('changeTo<>()' into the region acts as 'select<>()')
/// @tparam THead Head state
/// @tparam TSubStates Sub-states
template <typename THead, typename... TSubStates>
using Selectable = CI_<Strategy::Selectable, THead, TSubStates...>;

/// @brief Headless selectable region ('changeTo<>()' into the region acts as 'select<>()')
/// @tparam TSubStates Sub-states
template < typename... TSubStates>
using SelectablePeers = CI_<Strategy::Selectable, void, TSubStates...>;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#if HFSM2_UTILITY_THEORY_AVAILABLE()

/// @brief Utilitarian region ('changeTo<>()' into the region acts as 'utilize<>()')
/// @tparam THead Head state
/// @tparam TSubStates Sub-states
template <typename THead, typename... TSubStates>
using Utilitarian = CI_<Strategy::Utilitarian, THead, TSubStates...>;

/// @brief Headless utilitarian region ('changeTo<>()' into the region acts as 'utilize<>()')
/// @tparam TSubStates Sub-states
template < typename... TSubStates>
using UtilitarianPeers = CI_<Strategy::Utilitarian, void, TSubStates...>;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/// @brief Random region ('changeTo<>()' into the region acts as 'randomize<>()')
/// @tparam THead Head state
/// @tparam TSubStates Sub-states
template <typename THead, typename... TSubStates>
using Random = CI_<Strategy::RandomUtil, THead, TSubStates...>;

/// @brief Headless random region ('changeTo<>()' into the region acts as 'randomize<>()')
/// @tparam TSubStates Sub-states
template < typename... TSubStates>
using RandomPeers = CI_<Strategy::RandomUtil, void, TSubStates...>;

#endif

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/// @brief Orthogonal region (when activated, activates all sub-states)
/// @tparam THead Head state
/// @tparam TSubStates Sub-states
template <typename THead, typename... TSubStates>
using Orthogonal = OI_<THead, TSubStates...>;

/// @brief Headless orthogonal region (when activated, activates all sub-states)
/// @tparam TSubStates Sub-states
template < typename... TSubStates>
using OrthogonalPeers = OI_<void, TSubStates...>;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// COMMON

/// @brief Root ('changeTo<>()' into the root region acts as 'restart<>()')
/// @tparam THead Head state
/// @tparam TSubStates Sub-states
template <typename THead, typename... TSubStates>
using Root = RF_<Cfg, Composite <THead, TSubStates...>>;

/// @brief Headless root ('changeTo<>()' into the root region acts as 'restart<>()')
/// @tparam TSubStates Sub-states
template < typename... TSubStates>
using PeerRoot = RF_<Cfg, CompositePeers < TSubStates...>>;

// COMMON
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/// @brief Resumable root ('changeTo<>()' into the root region acts as 'resume<>()')
/// @tparam THead Head state
/// @tparam TSubStates Sub-states
template <typename THead, typename... TSubStates>
using ResumableRoot = RF_<Cfg, Resumable <THead, TSubStates...>>;

/// @brief Headless resumable root ('changeTo<>()' into the root region acts as 'resume<>()')
/// @tparam TSubStates Sub-states
template < typename... TSubStates>
using ResumablePeerRoot = RF_<Cfg, ResumablePeers < TSubStates...>>;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/// @brief Selectable root ('changeTo<>()' into the region acts as 'select<>()')
/// @tparam THead Head state
/// @tparam TSubStates Sub-states
template <typename THead, typename... TSubStates>
using SelectableRoot = RF_<Cfg, Selectable <THead, TSubStates...>>;

/// @brief Headless selectable root ('changeTo<>()' into the region acts as 'select<>()')
/// @tparam TSubStates Sub-states
template < typename... TSubStates>
using SelectablePeerRoot = RF_<Cfg, SelectablePeers < TSubStates...>>;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#if HFSM2_UTILITY_THEORY_AVAILABLE()

/// @brief Utilitarian root ('changeTo<>()' into the root region acts as 'utilize<>()')
/// @tparam THead Head state
/// @tparam TSubStates Sub-states
template <typename THead, typename... TSubStates>
using UtilitarianRoot = RF_<Cfg, Utilitarian<THead, TSubStates...>>;

/// @brief Headless utilitarian root ('changeTo<>()' into the root region acts as 'utilize<>()')
/// @tparam TSubStates Sub-states
template < typename... TSubStates>
using UtilitarianPeerRoot = RF_<Cfg, UtilitarianPeers< TSubStates...>>;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/// @brief Random root ('changeTo<>()' into the root region acts as 'randomize<>()')
/// @tparam THead Head state
/// @tparam TSubStates Sub-states
template <typename THead, typename... TSubStates>
using RandomRoot = RF_<Cfg, Random <THead, TSubStates...>>;

/// @brief Headless random root ('changeTo<>()' into the root region acts as 'randomize<>()')
/// @tparam TSubStates Sub-states
template < typename... TSubStates>
using RandomPeerRoot = RF_<Cfg, RandomPeers < TSubStates...>>;

#endif

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/// @brief Orthogonal root (all sub-states are active at all times)
/// @tparam THead Head state
/// @tparam TSubStates Sub-states
template <typename THead, typename... TSubStates>
using OrthogonalRoot = RF_<Cfg, Orthogonal <THead, TSubStates...>>;

/// @brief Headless orthogonal root (all sub-states are active at all times)
/// @tparam TSubStates Sub-states
template < typename... TSubStates>
using OrthogonalPeerRoot = RF_<Cfg, OrthogonalPeers < TSubStates...>>;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
};

////////////////////////////////////////////////////////////////////////////////

}

/// @brief Type configuration for MachineT<>
using Config = detail::G_<
HFSM2_FEATURE_TAG
, EmptyContext
, Automatic
, TopDown
HFSM2_IF_UTILITY_THEORY(, int8_t, float, RNGT<float>)
, 4
HFSM2_IF_PLANS(, INVALID_LONG)
, void
>;

/// @brief 'Template namespace' for FSM classes
/// @tparam TConfig 'ConfigT<>' type configuration for MachineT<>
/// @see ConfigT<>
template <typename TConfig = Config>
using MachineT = detail::M_<TConfig>;

/// @brief 'Template namespace' for FSM classes parametrized with default types
using Machine = MachineT<>;

////////////////////////////////////////////////////////////////////////////////

}
Loading

0 comments on commit d993031

Please sign in to comment.