Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

167 righe
6.3 KiB

  1. #pragma once
  2. #include <ecs/config.h>
  3. #include <ecs/core/mp/core.h>
  4. #include <ecs/core/mp/list.h>
  5. #include <ecs/core/mp/option_map.h>
  6. #include <ecs/tag/system.h>
  7. #include "./output.h"
  8. #include "./parallelism.h"
  9. namespace ecs {
  10. namespace signature {
  11. namespace system {
  12. namespace keys
  13. {
  14. constexpr decltype(auto) parallelism = hana::size_c<0>;
  15. constexpr decltype(auto) dependencies = hana::size_c<1>;
  16. constexpr decltype(auto) read_components = hana::size_c<2>;
  17. constexpr decltype(auto) write_components = hana::size_c<3>;
  18. constexpr decltype(auto) output = hana::size_c<4>;
  19. }
  20. namespace detail
  21. {
  22. /**
  23. * defines a system signature
  24. *
  25. * @tparam T_system_tag system tag the signature is defined for
  26. * @tparam T_options option map for the system signature
  27. */
  28. template<typename T_system_tag, typename T_options>
  29. struct signature_t
  30. {
  31. static_assert(tag::system::is_valid(T_system_tag { }) == hana::true_c, "system signature needs a system tags");
  32. using tag_type = T_system_tag;
  33. private:
  34. /**
  35. * change the value of an option key
  36. *
  37. * @tparam T_key key type to change value for
  38. * @tparam T_value value type of the new value
  39. *
  40. * @param key key to change the value for
  41. * @param value new value
  42. *
  43. * @return updated system signature
  44. */
  45. template<typename T_key, typename T_value>
  46. constexpr decltype(auto) change(const T_key& key, T_value&& value) const noexcept;
  47. /**
  48. * get the value of an option key
  49. *
  50. * @tparam T_key key type to get value for
  51. *
  52. * @param key key to get the value for
  53. *
  54. * @return value stored for key
  55. */
  56. template<typename T_key>
  57. constexpr decltype(auto) get(const T_key& key) const noexcept;
  58. public: /* misc */
  59. /**
  60. * get the system tag of this system signature
  61. *
  62. * @return system tag of this system signature
  63. */
  64. constexpr decltype(auto) tag() const noexcept;
  65. /**
  66. * check if the given component tag can be written by this system
  67. *
  68. * @tparam T_component_tag component tag type to check write access for
  69. *
  70. * @param ct component tag to check write access for
  71. *
  72. * @retval integral constant TRUE if the given component tag can be written
  73. * @retval integral constant FALSE if the given component tag can not be written
  74. */
  75. template<typename T_component_tag>
  76. constexpr decltype(auto) can_write(T_component_tag ct) const noexcept;
  77. /**
  78. * check if the given component tag can be read by this system
  79. *
  80. * @tparam T_component_tag component tag type to check read access for
  81. *
  82. * @param ct component tag to check read access for
  83. *
  84. * @retval integral constant TRUE if the given component tag can be read
  85. * @retval integral constant FALSE if the given component tag can not be read
  86. */
  87. template<typename T_component_tag>
  88. constexpr decltype(auto) can_read(T_component_tag ct) const noexcept;
  89. public: /* getter */
  90. /**
  91. * get the value of the parallelism option
  92. */
  93. constexpr decltype(auto) parallelism() const noexcept;
  94. /** get a list of system tags that system depends on */
  95. constexpr decltype(auto) dependencies() const noexcept;
  96. /** get a list of component tags this system wants to read */
  97. constexpr decltype(auto) read() const noexcept;
  98. /** get a list of component tags this system wants to write */
  99. constexpr decltype(auto) write() const noexcept;
  100. /** get the output type of the system */
  101. constexpr decltype(auto) output() const noexcept;
  102. public: /* setter */
  103. /** set the parallelism options
  104. * @param parallelism is a predicate that takes no parameters and returns a
  105. * system executor interface */
  106. template<typename T_parallelism>
  107. constexpr decltype(auto) parallelism(T_parallelism parallelism) const noexcept;
  108. /** set a list of system tags, that system depends on */
  109. template<typename... T_system_tags>
  110. constexpr decltype(auto) dependencies(T_system_tags... tags) const noexcept;
  111. /** set a list of component tags, this system wants to read */
  112. template<typename... T_component_tags>
  113. constexpr decltype(auto) read(T_component_tags... tags) const noexcept;
  114. /** set a list of component tags, this system wants to write */
  115. template<typename... T_component_tags>
  116. constexpr decltype(auto) write(T_component_tags... tags) const noexcept;
  117. /** set the output type of this system */
  118. template<typename T_output>
  119. constexpr decltype(auto) output(T_output output) const noexcept;
  120. };
  121. /** predicate class to create a system signature */
  122. struct make_t
  123. {
  124. template<typename T_system_tag>
  125. constexpr decltype(auto) operator()(T_system_tag) const noexcept;
  126. };
  127. }
  128. /** predicate to create a system signature */
  129. constexpr decltype(auto) make = detail::make_t { };
  130. /** predicate to check if a system signature is valid */
  131. constexpr decltype(auto) is_valid = core::mp::is_valid<detail::signature_t>;
  132. /** predicate to check if a list of system signatures is valid */
  133. constexpr decltype(auto) is_list = core::mp::is_list<detail::signature_t>;
  134. /** get the system tag type of a system signature type */
  135. template<typename T_system_sig>
  136. using tag_type_t = typename core::mp::unwrap_t<T_system_sig>::tag_type;
  137. } } }