Skip to content

Commit

Permalink
auto: add allowed transitions check
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Bernard <[email protected]>
  • Loading branch information
Alexandre Bernard committed Jul 9, 2018
1 parent df5f6e6 commit 295c20a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 6 additions & 2 deletions auto.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
#include "type_utils.hxx"

template<template<class> class PInterface,
class AllowedTransitions,
template<class> class ...States>
class Auto {
using self_t = Auto<PInterface, States...>;
using self_t = Auto<PInterface, AllowedTransitions, States...>;
using intf_t = PInterface<self_t>;
using ttlist = TTList<States...>;

Expand Down Expand Up @@ -90,11 +91,14 @@ public:
template<class> class OldState,
class ...Args>
void free_transit(Args&& ...args) {
// TODO: validate former state
static_assert(
AllowedTransitions::template contains<TPair<OldState, NewState>>());

#ifdef AUTO_LOGGING
std::cout << "transition from " << typeid(OldState<self_t>).name() << " to "
<< typeid(NewState<self_t>).name() << std::endl;
#endif

enter<NewState, Args...>(std::forward<Args>(args)...);
}

Expand Down
3 changes: 2 additions & 1 deletion test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ struct StateB : ExInterface<Auto> {
};


using MyAuto = Auto<ExInterface, StateA, StateB>;
using trans = TList<TPair<StateB, StateA>>;
using MyAuto = Auto<ExInterface, trans, StateA, StateB>;

int main() {
MyAuto a;
Expand Down
6 changes: 6 additions & 0 deletions type_utils.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,9 @@ struct AlignofReducer {
return AlignofReducer<T>{};
}
};

template<template<class> class OldState, template<class> class NewState>
struct TPair {
template<class T> using old_t = OldState<T>;
template<class T> using new_t = NewState<T>;
};

0 comments on commit 295c20a

Please sign in to comment.