mimic++ v10.0.1
Loading...
Searching...
No Matches
Collector.hpp
Go to the documentation of this file.
1// Copyright Dominic (DNKpp) Koepke 2026.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef MIMICPP_EXPECTATION_COLLECTOR_HPP
7#define MIMICPP_EXPECTATION_COLLECTOR_HPP
8
9#pragma once
10
11#include "mimic++/Fwd.hpp"
14
15#ifndef MIMICPP_DETAIL_IS_MODULE
16 #include <deque>
17 #include <utility>
18#endif
19
21{
32 {
33 public:
37 Collector(Collector const&) = delete;
38
42 Collector& operator=(Collector const&) = delete;
43
47 ~Collector() noexcept(false)
48 {
49 auto expectations = std::exchange(m_Expectations, {});
50 while (!expectations.empty())
51 {
52 // Prevent the `pop_front() noexcept` from raising an exception and thus terminating.
53 auto const expectation = std::move(expectations.front());
54 expectations.pop_front();
55 }
56 }
57
61 [[nodiscard]]
62 Collector() = default;
63
67 [[nodiscard]]
68 Collector(Collector&&) = default;
69
75
85 {
86 m_Expectations.emplace_back(std::move(builder));
87
88 return *this;
89 }
90
101 {
102 return attach(std::move(builder));
103 }
104
109 [[nodiscard]]
110 constexpr std::deque<ScopedExpectation> const& expectations() const noexcept
111 {
112 return m_Expectations;
113 }
114
115 private:
116 std::deque<ScopedExpectation> m_Expectations{};
117 };
118}
119
120#endif
#define MIMICPP_DETAIL_MODULE_EXPORT
Definition Config.hpp:19
Collector & operator+=(ScopedExpectation &&builder) &
Attaches a newly constructed expectation.
Definition Collector.hpp:100
~Collector() noexcept(false)
Possibly throwing destructor, checking the owned expectations in order of construction.
Definition Collector.hpp:47
Collector & attach(ScopedExpectation &&builder) &
Attaches a newly constructed expectation.
Definition Collector.hpp:84
Collector(Collector const &)=delete
Deleted copy-constructor.
constexpr std::deque< ScopedExpectation > const & expectations() const noexcept
Retrieves the collection of explicitly owned expectations.
Definition Collector.hpp:110
Collector & operator=(Collector &&)=default
Defaulted move-assignment operator.
Collector(Collector &&)=default
Defaulted move-constructor.
Collector()=default
Defaulted default-constructor.
Collector & operator=(Collector const &)=delete
Deleted copy-assignment operator.
expectation::Owner ScopedExpectation
Takes the ownership of an expectation and checks whether it's satisfied during destruction.
Definition Fwd.hpp:480
Definition Builder.hpp:33