22 template<States Start,
class Event, EndStates Next>
26 using end_states=EndStates;
28 static constexpr const states
start=Start;
29 static constexpr const end_states
next=Next;
31 constexpr row()
noexcept(
true)=
default;
38 : ev(
std::forward<Arg>(arg),
std::forward<Args>(args)...) {}
42 template<
class... Params>
47 ev.
template operator()<
start,
next>(
std::forward<Params>(p)...);
51 template<
class... Params>
56 ev.
template operator()<
start,
next>(
std::forward<Params>(p)...);
65 template<States Start,
class Event, EndStates Next,
class Guard>
69 using end_states=EndStates;
72 static constexpr const states
start=Start;
73 static constexpr const end_states
next=Next;
75 constexpr g_row()
noexcept(
true)=
default;
82 : ev(
std::forward<Arg>(arg),
std::forward<Args>(args)...) {}
86 template<
class... Params>
92 if (guard_t(
std::forward<Params>(p)...)) {
93 ev.
template operator()<
start,
next>(
std::forward<Params>(p)...);
100 template<
class... Params>
106 if (guard_t(
std::forward<Params>(p)...)) {
107 ev.
template operator()<
start,
next>(
std::forward<Params>(p)...);
118 template<
class Deriv>
119 template<
class Row,
class... Rows>
123 size=
sizeof...(Rows)+1
125 using a_transition=Row;
126 using states=
typename a_transition::states;
127 using end_states=
typename a_transition::end_states;
129 constexpr rows()
noexcept(
true)=
default;
135 rows(Arg &&arg, Args &&...args)
noexcept(
139 : rows<Rows...>(
std::forward<Args>(args)...), transition(
std::forward<Arg>(arg)) {
141 BOOST_MPL_ASSERT_RELATION(
sizeof...(Args)+1, ==, size);
144 : rows<Rows...>(r), transition(r.transition) {
147 template<
class... Params>
149 return s==a_transition::start ? transition.process(
std::forward<Params>(p)...) : rows<Rows...>::process(s,
std::forward<Params>(p)...);
152 template<
class... Params>
154 return s==a_transition::start ? transition.process(
std::forward<Params>(p)...) : rows<Rows...>::process(s,
std::forward<Params>(p)...);
158 a_transition transition;
161 template<
class Deriv>
163 class unroll::state_transition_table<Deriv>::rows<Row> {
168 using a_transition=Row;
169 using states=
typename a_transition::states;
170 using end_states=
typename a_transition::end_states;
172 constexpr rows()
noexcept(
true)=
default;
178 : transition(
std::forward<Arg>(arg)) {}
180 : transition(r.transition) {}
182 template<
class... Params>
184 return transition.process(
std::forward<Params>(p)...);
187 template<
class... Params>
189 return transition.process(
std::forward<Params>(p)...);
193 a_transition transition;
197 template<
class Arg,
class... Args,
class>
inline constexpr
199 : rows_(
std::forward<Arg>(arg),
std::forward<Args>(args)...) {
201 BOOST_MPL_ASSERT_RELATION(
sizeof...(Args)+1, ==, rows_t::size);
211 template<
class... Params>
inline constexpr typename unroll::
machine<STT>::end_states
213 return rows_.process(s,
std::forward<Params>(p)...);
217 template<
class... Params>
inline constexpr typename unroll::
machine<STT>::end_states
219 return rows_.process(s,
std::forward<Params>(p)...);
223 template<States Start,
class Event, EndStates Next>
227 using end_states=EndStates;
229 static constexpr const states
start=Start;
230 static constexpr const end_states
next=Next;
232 constexpr row()
noexcept(
true)=
default;
239 : ev(
std::forward<Arg>(arg),
std::forward<Args>(args)...) {}
243 template<
class... Params>
248 ev.
template operator()<
start,
next>(
std::forward<Params>(p)...);
252 template<
class... Params>
257 ev.
template operator()<
start,
next>(
std::forward<Params>(p)...);
266 template<States Start,
class Event, EndStates Next,
class Guard>
270 using end_states=EndStates;
273 static constexpr const states
start=Start;
274 static constexpr const end_states
next=Next;
276 constexpr g_row()
noexcept(
true)=
default;
283 : ev(
std::forward<Arg>(arg),
std::forward<Args>(args)...) {}
287 template<
class... Params>
293 if (guard_t(
std::forward<Params>(p)...)) {
294 ev.
template operator()<
start,
next>(
std::forward<Params>(p)...);
301 template<
class... Params>
307 if (guard_t(
std::forward<Params>(p)...)) {
308 ev.
template operator()<
start,
next>(
std::forward<Params>(p)...);
319 template<
class Deriv>
321 class jump_table::state_transition_table<Deriv>::rows_details<Row> {
328 template<
class Deriv>
329 template<
class Row1,
class Row2>
330 class jump_table::state_transition_table<Deriv>::rows_details<Row1, Row2> {
332 BOOST_MPL_ASSERT_RELATION((
static_cast<std::size_t>(Row2::start)-
static_cast<std::size_t>(Row1::start)), >, 0);
334 stride=
static_cast<
std::size_t>(Row2::start)-
static_cast<
std::size_t>(Row1::start)
338 template<
class Deriv>
339 template<
class Row1,
class Row2,
class... Rows>
340 class jump_table::state_transition_table<Deriv>::rows_details<Row1, Row2, Rows...> {
342 stride_before=rows_details<Row1, Row2>::stride,
343 stride_after=rows_details<Row2, Rows...>::stride
345 BOOST_MPL_ASSERT_RELATION(stride_before, ==, stride_after);
353 template<
class Deriv>
357 template<
class Deriv>
359 class jump_table::state_transition_table<Deriv>::rows<Row> :
public rows_base {
365 using a_transition=Row;
366 using states=
typename a_transition::states;
367 using end_states=
typename a_transition::end_states;
369 constexpr rows()
noexcept(
true)=
default;
375 : transition(
std::forward<Arg>(arg)) {
378 : transition(r.transition) {
381 template<
class... Params>
383 assert(s==rows::a_transition::start);
384 return static_cast<rows &>(row).transition.process(
std::forward<Params>(p)...);
387 template<
class... Params>
389 using process_fn_ptr_t=end_states (*)(rows_base &, states, Params &&...);
390 using element_type=
std::array<process_fn_ptr_t,
size>;
393 &rows::process<Params...>
398 a_transition transition;
401 template<
class Deriv>
402 template<
class Row,
class... Rows>
407 stride=rows_details<Row, Rows...>::stride
409 using a_transition=Row;
410 using states=
typename a_transition::states;
411 using end_states=
typename a_transition::end_states;
413 constexpr rows()
noexcept(
true)=
default;
419 rows(Arg &&arg, Args &&...args)
noexcept(
423 : rows<Rows...>(
std::forward<Args>(args)...), transition(
std::forward<Arg>(arg)) {
425 BOOST_MPL_ASSERT_RELATION(
sizeof...(Args)+1, ==, size);
428 : rows<Rows...>(r), transition(r.transition) {
431 template<
class... Params>
433 assert(s==
static_cast<rows &>(row).a_transition::start);
434 return static_cast<rows &>(row).transition.process(
std::forward<Params>(p)...);
437 template<
class... Params>
439 using process_fn_ptr_t=end_states (*)(rows_base &, states, Params &&...);
440 using element_type=
std::array<process_fn_ptr_t,
size>;
447 &rows<Row>::
template process<Params...>,
448 &rows<Rows>::
template process<Params...>...
453 a_transition transition;
457 template<
class Arg,
class... Args,
class>
inline constexpr
459 : rows_(
std::forward<Arg>(arg),
std::forward<Args>(args)...) {
461 BOOST_MPL_ASSERT_RELATION(
sizeof...(Args)+1, ==, rows_t::size);
471 template<
class... Params>
inline constexpr typename jump_table::
machine<STT>::end_states
473 using fn_table_t=
typename rows_t::
template fn_table_t<Params...>;
474 constexpr auto offset=
static_cast<
typename std::underlying_type<states>::type>(element_type::transition_table::rows::a_transition::start);
475 const auto index=
static_cast<
typename std::underlying_type<states>::type>(s)/element_type::transition_table::rows::stride-offset;
477 return (*fn_table_t::fn_table[index])(rows_, s,
std::forward<Params>(p)...);
481 template<
class... Params>
inline constexpr typename jump_table::
machine<STT>::end_states
483 using fn_table_t=
typename rows_t::
template fn_table_t<Params...>;
484 constexpr auto offset=
static_cast<
typename std::underlying_type<states>::type>(element_type::transition_table::rows::a_transition::start);
485 const auto index=
static_cast<
typename std::underlying_type<states>::type>(s)/element_type::transition_table::rows::stride-offset;
487 return (*fn_table_t::fn_table[index])(rows_, s,
std::forward<Params>(p)...);
491 template<States Start,
class Event, EndStates Next>
495 using end_states=EndStates;
497 static constexpr const states
start=Start;
498 static constexpr const end_states
next=Next;
500 constexpr row()
noexcept(
true)=
default;
507 : ev(
std::forward<Arg>(arg),
std::forward<Args>(args)...) {}
511 template<
class... Params>
516 ev.
template operator()<
start,
next>(
std::forward<Params>(p)...);
520 template<
class... Params>
525 ev.
template operator()<
start,
next>(
std::forward<Params>(p)...);
534 template<States Start,
class Event, EndStates Next,
class Guard>
538 using end_states=EndStates;
541 static constexpr const states
start=Start;
542 static constexpr const end_states
next=Next;
544 constexpr g_row()
noexcept(
true)=
default;
551 : ev(
std::forward<Arg>(arg),
std::forward<Args>(args)...) {}
555 template<
class... Params>
561 if (guard_t(
std::forward<Params>(p)...)) {
562 ev.
template operator()<
start,
next>(
std::forward<Params>(p)...);
569 template<
class... Params>
575 if (guard_t(
std::forward<Params>(p)...)) {
576 ev.
template operator()<
start,
next>(
std::forward<Params>(p)...);
587 template<
class Deriv>
589 class computed_goto::state_transition_table<Deriv>::rows_details<Row> {
596 template<
class Deriv>
597 template<
class Row1,
class Row2>
598 class computed_goto::state_transition_table<Deriv>::rows_details<Row1, Row2> {
600 BOOST_MPL_ASSERT_RELATION((
static_cast<std::size_t>(Row2::start)-
static_cast<std::size_t>(Row1::start)), >, 0);
602 stride=
static_cast<
std::size_t>(Row2::start)-
static_cast<
std::size_t>(Row1::start)
606 template<
class Deriv>
607 template<
class Row1,
class Row2,
class... Rows>
608 class computed_goto::state_transition_table<Deriv>::rows_details<Row1, Row2, Rows...> {
610 stride_before=rows_details<Row1, Row2>::stride,
611 stride_after=rows_details<Row2, Rows...>::stride
613 BOOST_MPL_ASSERT_RELATION(stride_before, ==, stride_after);
621 template<
class Deriv>
623 class computed_goto::state_transition_table<Deriv>::rows<Row> {
629 using a_transition=Row;
630 using states=
typename a_transition::states;
631 using end_states=
typename a_transition::end_states;
633 constexpr rows()
noexcept(
true)=
default;
639 : transition(
std::forward<Arg>(arg)) {}
641 : transition(r.transition) {}
643 template<
class... Params>
645 assert(s==rows::a_transition::start);
646 return row.transition.process(
std::forward<Params>(p)...);
649 template<
class... Params>
651 using process_fn_ptr_t=end_states (*)(rows &, states, Params &&...);
653 static inline constexpr process_fn_ptr_t
base_fn_ptr=&rows::process<Params...>;
658 a_transition transition;
661 template<
class Deriv>
662 template<
class Row,
class... Rows>
667 stride=rows_details<Row, Rows...>::stride
669 using a_transition=Row;
670 using states=
typename a_transition::states;
671 using end_states=
typename a_transition::end_states;
673 constexpr rows()
noexcept(
true)=
default;
679 rows(Arg &&arg, Args &&...args)
noexcept(
683 : rows<Rows...>(
std::forward<Args>(args)...), transition(
std::forward<Arg>(arg)) {
685 BOOST_MPL_ASSERT_RELATION(
sizeof...(Args)+1, ==, size);
688 : rows<Rows...>(r), transition(r.transition) {
691 template<
class... Params>
693 assert(s==rows::a_transition::start);
694 return row.transition.process(
std::forward<Params>(p)...);
697 template<
class... Params>
699 using process_fn_ptr_t=end_states (*)(rows &, states, Params &&...);
701 static inline constexpr process_fn_ptr_t
base_fn_ptr=&rows::process<Params...>;
702 static inline constexpr auto next_fn_ptr=&rows<Rows...>::
template process<Params...>;
707 a_transition transition;
711 template<
class Arg,
class... Args,
class>
inline constexpr
713 : rows_(
std::forward<Arg>(arg),
std::forward<Args>(args)...) {
715 BOOST_MPL_ASSERT_RELATION(
sizeof...(Args)+1, ==, rows_t::size);
727 using fn_details_t=
typename rows_t::
template fn_details_t<Params...>;
728 constexpr auto offset=
static_cast<
typename std::underlying_type<states>::type>(element_type::transition_table::rows::a_transition::start);
729 const auto index=
static_cast<
typename std::underlying_type<states>::type>(s)/element_type::transition_table::rows::stride-offset;
731 const std::size_t ptr_offset=index*fn_details_t::stride;
732 assert(ptr_offset>=0);
733 const typename fn_details_t::process_fn_ptr_t process_fn_ptr=fn_details_t::base_fn_ptr+ptr_offset;
734 return (*process_fn_ptr)(rows_, s,
std::forward<Params>(p)...);
740 using fn_details_t=
typename rows_t::
template fn_details_t<Params...>;
741 constexpr auto offset=
static_cast<
typename std::underlying_type<states>::type>(element_type::transition_table::rows::a_transition::start);
742 const auto index=
static_cast<
typename std::underlying_type<states>::type>(s)/element_type::transition_table::rows::stride-offset;
744 const std::size_t ptr_offset=index*fn_details_t::stride;
745 assert(ptr_offset>=0);
746 const typename fn_details_t::process_fn_ptr_t process_fn_ptr=fn_details_t::base_fn_ptr+ptr_offset;
747 return (*process_fn_ptr)(rows_, s,
std::forward<Params>(p)...);
750 template<
class States,
class EndStates>
755 virtual EndStates
process(
void *p)
const noexcept(
false)=0;
759 virtual EndStates
process(
void *p)
noexcept(
false)=0;
763 template<States Start,
class Event, EndStates Next>
764 class hash::
row_types<States, EndStates>::row
final :
public compat_row_base {
767 using end_states=EndStates;
769 static constexpr const states
start=Start;
770 static constexpr const end_states
next=Next;
772 constexpr row()
noexcept(
true)=
default;
778 row(Arg &&arg, Args &&...args)
noexcept(
false)
779 : ev(
std::forward<Arg>(arg),
std::forward<Args>(args)...) {}
787 assert(
dynamic_cast<
typename event_t::argument_type *>(
reinterpret_cast<
typename event_t::argument_type *>(p)));
788 ev.
template operator()<
start,
next>(*
reinterpret_cast<
typename event_t::argument_type *>(p));
796 assert(
dynamic_cast<
typename event_t::argument_type *>(
reinterpret_cast<
typename event_t::argument_type *>(p)));
797 ev.
template operator()<
start,
next>(*
reinterpret_cast<
typename event_t::argument_type *>(p));
806 template<States Start,
class Event, EndStates Next,
class Guard>
807 class hash::
row_types<States, EndStates>::g_row
final :
public compat_row_base {
810 using end_states=EndStates;
813 static constexpr const states
start=Start;
814 static constexpr const end_states
next=Next;
816 constexpr g_row()
noexcept(
true)=
default;
823 : ev(
std::forward<Arg>(arg),
std::forward<Args>(args)...) {}
834 auto arg=
reinterpret_cast<
typename event_t::argument_type *>(p);
835 assert(
dynamic_cast<
typename event_t::argument_type *>(arg));
837 ev.
template operator()<
start,
next>(*arg);
851 auto arg=
reinterpret_cast<
typename event_t::argument_type *>(p);
852 assert(
dynamic_cast<
typename event_t::argument_type *>(arg));
854 ev.
template operator()<
start,
next>(*arg);
866 template<
class Deriv>
869 static constexpr const typename Row::states value=Row::start;
872 template<
class Deriv>
873 template<
class Row,
class... Rows>
876 size=
sizeof...(Rows)+1
878 using a_transition=Row;
879 using states=
typename a_transition::states;
880 using end_states=
typename a_transition::end_states;
881 struct hasher
final {
886 template<
class T,
bool=
std::is_enum<T>::value>
892 struct is_enum<T,
true>
894 using type=
typename std::underlying_type<T>::type;
898 using element_type=
typename is_enum<states>::type;
901 return static_cast<element_type>(v);
904 return static_cast<element_type>(v);
907 using states_to_actions_table_t=unordered_tuple<
909 typename hash::row_types<states, end_states>::compat_row_base,
917 template<
class Arg,
class... Args,
class>
constexpr inline
919 : tbl(
std::forward<Arg>(arg),
std::forward<Args>(args)...) {
929 template<
class Params>
inline typename hash::
machine<STT>::end_states
935 return static_cast<
typename machine<STT>::end_states>(tbl[s].process(
reinterpret_cast<
void *>(&p)));
939 template<
class Params>
inline typename hash::
machine<STT>::end_states
945 return static_cast<
typename machine<STT>::end_states>(tbl[s].process(
reinterpret_cast<
void *>(&p)));