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
35 std::tuple<std::tuple<std::shared_ptr<Sequences>,
sequence::Id>...> result{};
37 [&]<std::size_t... indices>([[maybe_unused]]
const std::index_sequence<indices...>)
noexcept
39 ((std::get<indices>(result) =
41 std::get<indices>(sequences),
42 std::get<indices>(sequences)->add(),
45 std::index_sequence_for<Sequences...>{});
53 TimesConfig() =
default;
56 constexpr TimesConfig(
const int min,
const int max)
62 throw std::invalid_argument{
63 "min must be less or equal to max and both must not be less than zero."
72 constexpr int min() const noexcept
78 constexpr int max() const noexcept
98 const auto& sequenceEntries
103 return state_saturated{
107 .sequences = std::apply(
108 [](
const auto&... entries)
110 return std::vector<sequence::Tag>{
111 std::get<0>(entries)->tag()...
119 std::vector<sequence::rating> ratings{};
121 [&](
const auto&... entries)
127 if (
const std::optional priority = seq->priority_of(
id))
129 ratings.emplace_back(
138 std::get<0>(entries),
139 std::get<1>(entries)));
145 return state_inapplicable{
149 .sequenceRatings = std::move(ratings),
154 return state_applicable{
158 .sequenceRatings = std::move(ratings),
163 template <
typename... Sequences>
171 const detail::TimesConfig& timesConfig,
172 const sequence::detail::Config<Sequences...>& sequenceConfig
174 : m_Min{timesConfig.min()},
175 m_Max{timesConfig.max()},
177 detail::make_sequence_entries(sequenceConfig.sequences())
180 update_sequence_states();
186 return m_Min <= m_Count
193 return m_Count == m_Max;
199 return m_Count < m_Max
201 [](
const auto&... entries)
noexcept
203 return (... && std::get<0>(entries)->is_consumable(std::get<1>(entries)));
213 [](
auto&... entries)
noexcept
215 (..., std::get<0>(entries)->consume(std::get<1>(entries)));
221 update_sequence_states();
227 return detail::make_control_state(
239 std::tuple<std::shared_ptr<Sequences>,
sequence::Id>...> m_Sequences{};
241 constexpr void update_sequence_states() noexcept
243 if (m_Count == m_Min)
246 [](
auto&... entries)
noexcept
248 (..., std::get<0>(entries)->set_satisfied(std::get<1>(entries)));
252 else if (m_Count == m_Max)
255 [](
auto&... entries)
noexcept
257 (..., std::get<0>(entries)->set_saturated(std::get<1>(entries)));
292 constexpr auto times(
const int min,
const int max)
294 return detail::TimesConfig{min, max};
307 constexpr auto times(
const int exactly)
309 return detail::TimesConfig(exactly, exactly);
324 return detail::TimesConfig{
326 std::numeric_limits<int>::max()
342 return detail::TimesConfig{
358 constexpr detail::TimesConfig config{
376 constexpr detail::TimesConfig config{
Definition ControlPolicy.hpp:165
control_state_t state() const
Definition ControlPolicy.hpp:225
constexpr void consume() noexcept
Definition ControlPolicy.hpp:208
constexpr bool is_satisfied() const noexcept
Definition ControlPolicy.hpp:184
constexpr ControlPolicy(const detail::TimesConfig ×Config, const sequence::detail::Config< Sequences... > &sequenceConfig) noexcept
Definition ControlPolicy.hpp:170
static constexpr std::size_t sequenceCount
Definition ControlPolicy.hpp:167
constexpr bool is_saturated() const noexcept
Definition ControlPolicy.hpp:191
constexpr bool is_applicable() const noexcept
Definition ControlPolicy.hpp:197
constexpr auto at_most(const int max)
Specifies a times policy with just an upper limit.
Definition ControlPolicy.hpp:340
constexpr auto times(const int min, const int max)
Specifies a times policy with a limit range.
Definition ControlPolicy.hpp:292
consteval auto twice() noexcept
Specifies a times policy with both limits set to 2.
Definition ControlPolicy.hpp:374
consteval auto once() noexcept
Specifies a times policy with both limits set to 1.
Definition ControlPolicy.hpp:356
constexpr auto at_least(const int min)
Specifies a times policy with just a lower limit.
Definition ControlPolicy.hpp:322
std::variant< state_inapplicable, state_applicable, state_saturated > control_state_t
Definition Reports.hpp:73
Definition ControlPolicy.hpp:266
Definition BoostTest.hpp:20