Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.3.3 #63

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions development/ffsm2/detail/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
namespace ffsm2 {
namespace detail {

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

template <
FeatureTag NFeatureTag
, typename TContext
, typename TActivation
, Short NSubstitutionLimit
FFSM2_IF_PLANS(, Long NTaskCapacity)
, typename TPayload
>
struct G_ final {
static constexpr FeatureTag FEATURE_TAG = NFeatureTag;

using Context = TContext;
using Activation = TActivation;

#if FFSM2_LOG_INTERFACE_AVAILABLE()
using LoggerInterface = LoggerInterfaceT<FEATURE_TAG, Context>;
#endif

static constexpr Short SUBSTITUTION_LIMIT = NSubstitutionLimit;

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

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

#if FFSM2_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, SUBSTITUTION_LIMIT FFSM2_IF_PLANS(, TASK_CAPACITY), Payload>;

/// @brief Select manual activation strategy
using ManualActivation = G_<FEATURE_TAG, Context, Manual , SUBSTITUTION_LIMIT FFSM2_IF_PLANS(, TASK_CAPACITY), Payload>;

#if FFSM2_UTILITY_THEORY_AVAILABLE()
#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, N FFSM2_IF_PLANS(, TASK_CAPACITY), Payload>;

#if FFSM2_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, 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, SUBSTITUTION_LIMIT FFSM2_IF_PLANS(, TASK_CAPACITY), T >;
};

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

template <typename>
struct M_;

template <
FeatureTag NFeatureTag
, typename TContext
, typename TActivation
, Short NSubstitutionLimit
FFSM2_IF_PLANS(, Long NTaskCapacity)
, typename TPayload
>
struct M_<
G_<
NFeatureTag
, TContext
, TActivation
, NSubstitutionLimit
FFSM2_IF_PLANS(, NTaskCapacity)
, TPayload
>
> final
{
using Cfg = G_<
NFeatureTag
, TContext
, TActivation
, NSubstitutionLimit
FFSM2_IF_PLANS(, NTaskCapacity)
, TPayload
>;

static constexpr FeatureTag FEATURE_TAG = NFeatureTag;

using Context = TContext;

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

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

#if FFSM2_UTILITY_THEORY_AVAILABLE()
#endif

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

/// @brief Root
/// @tparam THead Head state
/// @tparam TSubStates Sub-states
template <typename THead, typename... TSubStates>
using Root = RF_<Cfg, CI_<THead, TSubStates...>>;

/// @brief Headless root
/// @tparam TSubStates Sub-states
template < typename... TSubStates>
using PeerRoot = RF_<Cfg, CI_<void, TSubStates...>>;

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

#if FFSM2_UTILITY_THEORY_AVAILABLE()
#endif
};

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

}

/// @brief Type configuration for MachineT<>
using Config = detail::G_<
FFSM2_FEATURE_TAG
, EmptyContext
, Automatic
, 4
FFSM2_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<>;

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

}
14 changes: 7 additions & 7 deletions development/ffsm2/detail/containers/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ struct StaticArrayT<T, 0> final {
////////////////////////////////////////////////////////////////////////////////

template <typename T, Long NCapacity>
class ArrayT final {
class DynamicArrayT final {
template <typename>
friend class IteratorT;

public:
using Iterator = IteratorT< ArrayT>;
using CIterator = IteratorT<const ArrayT>;
using Iterator = IteratorT< DynamicArrayT>;
using CIterator = IteratorT<const DynamicArrayT>;

using Item = T;
using Index = UCapacity<NCapacity>;
Expand All @@ -113,12 +113,12 @@ class ArrayT final {
FFSM2_CONSTEXPR(11) bool empty() const noexcept { return _count == 0; }

// SPECIFIC
FFSM2_CONSTEXPR(14) ArrayT& operator += (const Item & item) noexcept;
FFSM2_CONSTEXPR(14) ArrayT& operator += ( Item&& item) noexcept;
FFSM2_CONSTEXPR(14) DynamicArrayT& operator += (const Item & item) noexcept;
FFSM2_CONSTEXPR(14) DynamicArrayT& operator += ( Item&& item) noexcept;
// SPECIFIC

template <Long N>
FFSM2_CONSTEXPR(14) ArrayT& operator += (const ArrayT<Item, N>& other) noexcept;
FFSM2_CONSTEXPR(14) DynamicArrayT& operator += (const DynamicArrayT<Item, N>& other) noexcept;

FFSM2_CONSTEXPR(14) Iterator begin() noexcept { return Iterator(*this, first()); }
FFSM2_CONSTEXPR(11) CIterator begin() const noexcept { return CIterator(*this, first()); }
Expand All @@ -141,7 +141,7 @@ class ArrayT final {
//------------------------------------------------------------------------------

template <typename T>
class ArrayT<T, 0> final {
class DynamicArrayT<T, 0> final {
public:
using Item = T;
using Index = UCapacity<0>;
Expand Down
62 changes: 31 additions & 31 deletions development/ffsm2/detail/containers/array.inl
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@ namespace detail {

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

template <typename T, Long NC>
template <typename T, Long NC_>
template <typename N>
FFSM2_CONSTEXPR(14)
T&
StaticArrayT<T, NC>::operator[] (const N index) noexcept {
StaticArrayT<T, NC_>::operator[] (const N index) noexcept {
FFSM2_ASSERT(0 <= index && index < CAPACITY);

return _items[static_cast<Index>(index)];
}

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

template <typename T, Long NC>
template <typename T, Long NC_>
template <typename N>
FFSM2_CONSTEXPR(14)
const T&
StaticArrayT<T, NC>::operator[] (const N index) const noexcept {
StaticArrayT<T, NC_>::operator[] (const N index) const noexcept {
FFSM2_ASSERT(0 <= index && index < CAPACITY);

return _items[static_cast<Index>(index)];
}

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

template <typename T, Long NC>
template <typename T, Long NC_>
FFSM2_CONSTEXPR(14)
void
StaticArrayT<T, NC>::fill(const Item filler) noexcept {
StaticArrayT<T, NC_>::fill(const Item filler) noexcept {
for (Item& item : _items)
item = filler;
}

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

template <typename T, Long NC>
template <typename T, Long NC_>
FFSM2_CONSTEXPR(14)
bool
StaticArrayT<T, NC>::empty() const noexcept {
StaticArrayT<T, NC_>::empty() const noexcept {
for (const Item& item : _items)
if (item != filler<Item>())
return false;
Expand All @@ -50,11 +50,11 @@ StaticArrayT<T, NC>::empty() const noexcept {

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

template <typename T, Long NC>
template <typename T, Long NC_>
template <typename... TArgs>
FFSM2_CONSTEXPR(14)
typename ArrayT<T, NC>::Index
ArrayT<T, NC>::emplace(const TArgs&... args) noexcept {
typename DynamicArrayT<T, NC_>::Index
DynamicArrayT<T, NC_>::emplace(const TArgs&... args) noexcept {
FFSM2_ASSERT(_count < CAPACITY);

new (&_items[_count]) Item{args...};
Expand All @@ -64,11 +64,11 @@ ArrayT<T, NC>::emplace(const TArgs&... args) noexcept {

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

template <typename T, Long NC>
template <typename T, Long NC_>
template <typename... TArgs>
FFSM2_CONSTEXPR(14)
typename ArrayT<T, NC>::Index
ArrayT<T, NC>::emplace(TArgs&&... args) noexcept {
typename DynamicArrayT<T, NC_>::Index
DynamicArrayT<T, NC_>::emplace(TArgs&&... args) noexcept {
FFSM2_ASSERT(_count < CAPACITY);

new (&_items[_count]) Item{forward<TArgs>(args)...};
Expand All @@ -78,46 +78,46 @@ ArrayT<T, NC>::emplace(TArgs&&... args) noexcept {

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

template <typename T, Long NC>
template <typename T, Long NC_>
template <typename N>
FFSM2_CONSTEXPR(14)
typename ArrayT<T, NC>::Item&
ArrayT<T, NC>::operator[] (const N index) noexcept {
FFSM2_ASSERT(0 <= index && index < CAPACITY);
typename DynamicArrayT<T, NC_>::Item&
DynamicArrayT<T, NC_>::operator[] (const N index) noexcept {
FFSM2_ASSERT(0 <= index && index < _count);

return _items[static_cast<Index>(index)];
}

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

template <typename T, Long NC>
template <typename T, Long NC_>
template <typename N>
FFSM2_CONSTEXPR(14)
const typename ArrayT<T, NC>::Item&
ArrayT<T, NC>::operator[] (const N index) const noexcept {
FFSM2_ASSERT(0 <= index && index < CAPACITY);
const typename DynamicArrayT<T, NC_>::Item&
DynamicArrayT<T, NC_>::operator[] (const N index) const noexcept {
FFSM2_ASSERT(0 <= index && index < _count);

return _items[static_cast<Index>(index)];
}

//------------------------------------------------------------------------------
// SPECIFIC

template <typename T, Long NC>
template <typename T, Long NC_>
FFSM2_CONSTEXPR(14)
ArrayT<T, NC>&
ArrayT<T, NC>::operator += (const Item& item) noexcept {
DynamicArrayT<T, NC_>&
DynamicArrayT<T, NC_>::operator += (const Item& item) noexcept {
emplace(item);

return *this;
}

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

template <typename T, Long NC>
template <typename T, Long NC_>
FFSM2_CONSTEXPR(14)
ArrayT<T, NC>&
ArrayT<T, NC>::operator += (Item&& item) noexcept {
DynamicArrayT<T, NC_>&
DynamicArrayT<T, NC_>::operator += (Item&& item) noexcept {
emplace(move(item));

return *this;
Expand All @@ -126,11 +126,11 @@ ArrayT<T, NC>::operator += (Item&& item) noexcept {
// SPECIFIC
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

template <typename T, Long NC>
template <typename T, Long NC_>
template <Long N>
FFSM2_CONSTEXPR(14)
ArrayT<T, NC>&
ArrayT<T, NC>::operator += (const ArrayT<T, N>& other) noexcept {
DynamicArrayT<T, NC_>&
DynamicArrayT<T, NC_>::operator += (const DynamicArrayT<T, N>& other) noexcept {
for (const auto& item : other)
emplace(item);

Expand Down
2 changes: 1 addition & 1 deletion development/ffsm2/detail/containers/bit_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace detail {
template <unsigned NCapacity>
class BitArrayT final {
public:
using Index = UCapacity<NCapacity>;
using Index = UCapacity<NCapacity>;

static constexpr Index CAPACITY = NCapacity;
static constexpr Index UNIT_COUNT = contain(CAPACITY, 8);
Expand Down
Loading