6#ifndef MIMICPP_SCOPED_SEQUENCE_HPP
7#define MIMICPP_SCOPED_SEQUENCE_HPP
17#ifndef MIMICPP_DETAIL_IS_MODULE
23namespace mimicpp::sequence::detail
25 template <
typename Sequence>
26 class ExpectationBuilderFinalizer
29 ExpectationBuilderFinalizer(ExpectationBuilderFinalizer
const&) =
delete;
30 ExpectationBuilderFinalizer& operator=(ExpectationBuilderFinalizer
const&) =
delete;
31 ExpectationBuilderFinalizer(ExpectationBuilderFinalizer&&) =
delete;
32 ExpectationBuilderFinalizer& operator=(ExpectationBuilderFinalizer&&) =
delete;
34 ~ExpectationBuilderFinalizer() =
default;
36 template <
bool timesConfigured,
typename... Args>
38 explicit(
false)
constexpr ExpectationBuilderFinalizer(
39 BasicExpectationBuilder<timesConfigured, Args...>&& builder,
40 util::SourceLocation loc = {})
41 : m_Builder{&builder},
42 m_SourceLocation{std::move(loc)},
44 +[](void* storage, util::SourceLocation finalLoc,
Sequence& sequence) {
45 auto* builderPtr =
static_cast<BasicExpectationBuilder<timesConfigured, Args...
>*>(storage);
46 return ScopedExpectation{
54 ScopedExpectation finalize(
Sequence& sequence)
60 std::exchange(m_FinalizeFn,
nullptr),
61 std::exchange(m_Builder,
nullptr),
62 std::move(m_SourceLocation),
68 util::SourceLocation m_SourceLocation;
70 using FinalizeFn = ScopedExpectation (*)(
void*, util::SourceLocation,
Sequence&);
71 FinalizeFn m_FinalizeFn;
95 template <auto Strategy>
97 :
public sequence::detail::BasicSequenceInterface<sequence::Id, Strategy>
120 auto const expectation = std::move(
expectations.front());
130 :
sequence::detail::BasicSequenceInterface<
sequence::Id, Strategy>{std::move(loc)}
132 static_assert(0u ==
sizeof...(canary),
"ScopedSequence does not accept constructor arguments.");
157 m_Expectations.emplace_back(builder.finalize(*
this));
171 return m_Expectations;
175 std::deque<ScopedExpectation> m_Expectations{};
#define MIMICPP_ASSERT(condition, msg)
Definition Config.hpp:51
#define MIMICPP_DETAIL_MODULE_EXPORT
Definition Config.hpp:19
A sequence type that verifies its owned expectations during destruction.
Definition ScopedSequence.hpp:98
BasicScopedSequence(auto &&... canary, util::SourceLocation loc={})
Default-constructor.
Definition ScopedSequence.hpp:129
BasicScopedSequence & operator=(BasicScopedSequence const &)=delete
Deleted copy-assignment operator.
~BasicScopedSequence() noexcept(false)
Possibly throwing destructor, checking the owned expectations in order of construction.
Definition ScopedSequence.hpp:114
BasicScopedSequence(BasicScopedSequence const &)=delete
Deleted copy-constructor.
std::deque< ScopedExpectation > const & expectations() const noexcept
Retrieves the collection of explicitly owned expectations.
Definition ScopedSequence.hpp:169
BasicScopedSequence & operator=(BasicScopedSequence &&)=default
Defaulted move-assignment operator.
BasicScopedSequence(BasicScopedSequence &&)=default
Defaulted move-constructor.
BasicScopedSequence & operator+=(sequence::detail::ExpectationBuilderFinalizer< BasicScopedSequence > &&builder)
Attaches a newly constructed expectation.
Definition ScopedSequence.hpp:155
A thin wrapper around general source-location info.
Definition SourceLocation.hpp:38
LazySequence Sequence
The default sequence type (LazySequence).
Definition Sequence.hpp:472
BasicScopedSequence< sequence::detail::LazyStrategy{}> LazyScopedSequence
The scoped-sequence type with lazy strategy.
Definition ScopedSequence.hpp:188
LazyScopedSequence ScopedSequence
The default scoped-sequence type (lazy strategy).
Definition ScopedSequence.hpp:194
BasicScopedSequence< sequence::detail::GreedyStrategy{}> GreedyScopedSequence
The scoped-sequence type with greedy strategy.
Definition ScopedSequence.hpp:182
constexpr auto in_sequence(sequence::detail::BasicSequenceInterface< Id, priorityStrategy > &sequence)
Attaches the expectation onto a sequence.
Definition Sequence.hpp:513