dispatch_table.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2025 Christian Granzin
  2. // Copyright 2008 Christophe Henry
  3. // henry UNDERSCORE christophe AT hotmail DOT com
  4. // This is an extended version of the state machine available in the boost::mpl library
  5. // Distributed under the same license as the original.
  6. // Copyright for the original version:
  7. // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
  8. // under the Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #ifndef BOOST_MSM_BACKMP11_DISPATCH_TABLE_H
  12. #define BOOST_MSM_BACKMP11_DISPATCH_TABLE_H
  13. #include <cstdint>
  14. #include <cstddef>
  15. #include <boost/mp11.hpp>
  16. #include <boost/msm/backmp11/common_types.hpp>
  17. namespace boost { namespace msm { namespace backmp11
  18. {
  19. namespace detail
  20. {
  21. // Value used to initialize a cell of the dispatch table
  22. template<typename Cell>
  23. struct init_cell_value
  24. {
  25. size_t index;
  26. Cell address;
  27. };
  28. template<size_t v1, typename Cell, Cell v2>
  29. struct init_cell_constant
  30. {
  31. static constexpr init_cell_value<Cell> value = {v1, v2};
  32. };
  33. // Type-punned init cell value to suppress redundant template instantiations
  34. typedef std::uintptr_t generic_cell;
  35. struct generic_init_cell_value
  36. {
  37. size_t index;
  38. generic_cell address;
  39. };
  40. // Helper to create an array of init cell values for table initialization
  41. template<typename Cell, typename InitCellConstants, std::size_t... I>
  42. static const init_cell_value<Cell>* get_init_cells_impl(mp11::index_sequence<I...>)
  43. {
  44. static constexpr init_cell_value<Cell> values[] {mp11::mp_at_c<InitCellConstants, I>::value...};
  45. return values;
  46. }
  47. template<typename Cell, typename InitCellConstants>
  48. static const init_cell_value<Cell>* get_init_cells_impl(mp11::index_sequence<>)
  49. {
  50. return nullptr;
  51. }
  52. template<typename Cell, typename InitCellConstants>
  53. static const generic_init_cell_value* get_init_cells()
  54. {
  55. return reinterpret_cast<const generic_init_cell_value*>(
  56. get_init_cells_impl<Cell, InitCellConstants>(mp11::make_index_sequence<mp11::mp_size<InitCellConstants>::value>{}));
  57. }
  58. } // detail
  59. }}} // boost::msm::backmp11
  60. #endif //BOOST_MSM_BACKMP11_DISPATCH_TABLE_H