6#ifndef MIMICPP_CONTROL_POLICY_HPP
7#define MIMICPP_CONTROL_POLICY_HPP
24namespace mimicpp::detail
26 template <
typename... Sequences>
28 constexpr std::tuple<std::tuple<std::shared_ptr<Sequences>,
sequence::Id>...> make_sequence_entries(
29 const std::tuple<std::shared_ptr<Sequences>...>& sequences)
noexcept
34 std::tuple<std::tuple<std::shared_ptr<Sequences>,
sequence::Id>...> result{};
36 [&]<std::size_t... indices>([[maybe_unused]]
const std::index_sequence<indices...>)
noexcept {
37 ((std::get<indices>(result) =
39 std::get<indices>(sequences),
40 std::get<indices>(sequences)->add(),
44 std::index_sequence_for<Sequences...>{});
52 TimesConfig() =
default;
55 constexpr TimesConfig(
const int min,
const int max)
61 throw std::invalid_argument{
62 "min must be less or equal to max and both must not be less than zero."};
70 constexpr int min() const noexcept
76 constexpr int max() const noexcept
96 const auto& sequenceEntries)
100 return state_saturated{
104 .sequences = std::apply(
105 [](
const auto&... entries) {
106 return std::vector<sequence::Tag>{
107 std::get<0>(entries)->tag()...};
113 std::vector<sequence::rating> ratings{};
115 [&](
const auto&... entries) {
119 if (
const std::optional priority = seq->priority_of(
id))
121 ratings.emplace_back(
130 std::get<0>(entries),
131 std::get<1>(entries)));
137 return state_inapplicable{
141 .sequenceRatings = std::move(ratings),
145 return state_applicable{
149 .sequenceRatings = std::move(ratings),
154 template <
typename... Sequences>
162 const detail::TimesConfig& timesConfig,
163 const sequence::detail::Config<Sequences...>& sequenceConfig) noexcept
164 : m_Min{timesConfig.min()},
165 m_Max{timesConfig.max()},
167 detail::make_sequence_entries(sequenceConfig.sequences())}
169 update_sequence_states();
175 return m_Min <= m_Count
182 return m_Count == m_Max;
188 return m_Count < m_Max
190 [](
const auto&... entries)
noexcept {
191 return (... && std::get<0>(entries)->is_consumable(std::get<1>(entries)));
201 [](
auto&... entries)
noexcept {
202 (..., std::get<0>(entries)->consume(std::get<1>(entries)));
208 update_sequence_states();
214 return detail::make_control_state(
226 std::tuple<std::shared_ptr<Sequences>,
sequence::Id>...>
229 constexpr void update_sequence_states() noexcept
231 if (m_Count == m_Min)
234 [](
auto&... entries)
noexcept {
235 (..., std::get<0>(entries)->set_satisfied(std::get<1>(entries)));
239 else if (m_Count == m_Max)
242 [](
auto&... entries)
noexcept {
243 (..., std::get<0>(entries)->set_saturated(std::get<1>(entries)));
278 constexpr auto times(
const int min,
const int max)
280 return detail::TimesConfig{min, max};
293 constexpr auto times(
const int exactly)
295 return detail::TimesConfig(exactly, exactly);
310 return detail::TimesConfig{
312 std::numeric_limits<int>::max()};
327 return detail::TimesConfig{
342 constexpr detail::TimesConfig config{
359 constexpr detail::TimesConfig config{
Definition ControlPolicy.hpp:156
control_state_t state() const
Definition ControlPolicy.hpp:212
constexpr void consume() noexcept
Definition ControlPolicy.hpp:196
constexpr bool is_satisfied() const noexcept
Definition ControlPolicy.hpp:173
constexpr ControlPolicy(const detail::TimesConfig ×Config, const sequence::detail::Config< Sequences... > &sequenceConfig) noexcept
Definition ControlPolicy.hpp:161
static constexpr std::size_t sequenceCount
Definition ControlPolicy.hpp:158
constexpr bool is_saturated() const noexcept
Definition ControlPolicy.hpp:180
constexpr bool is_applicable() const noexcept
Definition ControlPolicy.hpp:186
constexpr auto at_most(const int max)
Specifies a times policy with just an upper limit.
Definition ControlPolicy.hpp:325
constexpr auto times(const int min, const int max)
Specifies a times policy with a limit range.
Definition ControlPolicy.hpp:278
consteval auto twice() noexcept
Specifies a times policy with both limits set to 2.
Definition ControlPolicy.hpp:357
consteval auto once() noexcept
Specifies a times policy with both limits set to 1.
Definition ControlPolicy.hpp:340
constexpr auto at_least(const int min)
Specifies a times policy with just a lower limit.
Definition ControlPolicy.hpp:308
std::variant< state_inapplicable, state_applicable, state_saturated > control_state_t
Definition Reports.hpp:73
Definition ControlPolicy.hpp:252
Definition BoostTest.hpp:20