6#ifndef MIMICPP_OBJECT_WATCHER_HPP
7#define MIMICPP_OBJECT_WATCHER_HPP
16#ifndef MIMICPP_DETAIL_IS_MODULE
22 #include <type_traits>
26namespace mimicpp::detail
28 template <
typename Base>
30 static StringT generate_lifetime_watcher_mock_name()
34 return std::move(out).str();
37 template <
typename Base>
39 static StringT generate_relocation_watcher_mock_name()
43 return std::move(out).str();
58 template <
typename Base>
64 template <
typename Base>
103 static constexpr std::size_t stacktraceSkip = 4u;
113 if (
const std::unique_ptr destruction = std::exchange(
127 template <
typename Base>
131 .name = detail::generate_lifetime_watcher_mock_name<Base>(),
132 .stacktraceSkip = stacktraceSkip}
209 if (std::exchange(m_HasDestructExpectation,
true))
211 throw std::logic_error{
212 "LifetimeWatcher: A destruct expectation can not be created more than once for a single instance."};
215 return m_DestructionMock->expect_call()
220 bool m_HasDestructExpectation{};
221 MockSettings m_MockSettings{};
222 std::unique_ptr<Mock<void()>> m_DestructionMock{
223 std::make_unique<Mock<void()>>(m_MockSettings)};
227 : m_MockSettings{std::move(settings)}
270 static constexpr std::size_t stacktraceSkip = 5u;
284 template <
typename Base>
288 .name = detail::generate_relocation_watcher_mock_name<Base>(),
289 .stacktraceSkip = stacktraceSkip}
316 m_MockSettings = other.m_MockSettings;
320 m_RelocationMock =
Mock<void()>{m_MockSettings};
333 handle_move(std::move(other));
343 handle_move(std::move(other));
358 return m_RelocationMock.expect_call();
363 Mock<void()> m_RelocationMock{m_MockSettings};
367 : m_MockSettings{std::move(settings)}
373 other.m_RelocationMock();
375 std::ranges::swap(m_MockSettings, other.m_MockSettings);
377 m_RelocationMock = std::move(other).m_RelocationMock;
381 template <
typename T,
typename Base>
383 && std::is_copy_constructible_v<T>
384 && std::is_copy_assignable_v<T>
385 && std::is_move_constructible_v<T>
386 && std::is_move_assignable_v<T>
387 && std::is_destructible_v<T>;
390namespace mimicpp::detail
392 template <
typename Base,
typename... Watchers>
393 class CombinedWatchers
397 ~CombinedWatchers()
noexcept(std::is_nothrow_destructible_v<Base>) =
default;
404 CombinedWatchers(
const CombinedWatchers&) =
default;
405 CombinedWatchers& operator=(
const CombinedWatchers&) =
default;
407 CombinedWatchers(CombinedWatchers&& other)
noexcept(std::is_nothrow_move_constructible_v<Base>) =
default;
408 CombinedWatchers& operator=(CombinedWatchers&& other)
noexcept(std::is_nothrow_move_assignable_v<Base>) =
default;
411 template <
typename Base,
typename... Watchers>
413 :
public CombinedWatchers<Base, Watchers...>,
417 ~BasicWatched() =
default;
421 BasicWatched(
const BasicWatched&) =
default;
422 BasicWatched& operator=(
const BasicWatched&) =
default;
423 BasicWatched(BasicWatched&&) =
default;
424 BasicWatched& operator=(BasicWatched&&) =
default;
427 template <util::satisfies<std::has_virtual_destructor> Base,
typename... Watchers>
428 class BasicWatched<Base, Watchers...>
429 :
public CombinedWatchers<Base, Watchers...>,
433 ~BasicWatched()
override =
default;
437 BasicWatched(
const BasicWatched&) =
default;
438 BasicWatched& operator=(
const BasicWatched&) =
default;
439 BasicWatched(BasicWatched&&) =
default;
440 BasicWatched& operator=(BasicWatched&&) =
default;
499 template <
typename Base,
object_watcher_for<Base>... Watchers>
500 requires std::same_as<Base, std::remove_cvref_t<Base>>
502 :
public detail::BasicWatched<Base, Watchers...>
504 using SuperT = detail::BasicWatched<Base, Watchers...>;
509 using SuperT::SuperT;
#define MIMICPP_DETAIL_MODULE_EXPORT
Definition Config.hpp:19
A Mock type, which fully supports overload sets.
Definition Mock.hpp:463
Watched(const Watched &)=default
Watched & operator=(const Watched &)=default
Watched(Watched &&)=default
Watched & operator=(Watched &&)=default
Definition ObjectWatcher.hpp:382
consteval auto once() noexcept
Specifies a times policy with both limits set to 1.
Definition ControlPolicies.hpp:355
LifetimeWatcher()=default
Default constructor.
auto expect_relocate()
Begins a relocation-expectation construction.
Definition ObjectWatcher.hpp:356
RelocationWatcher(RelocationWatcher &&other) noexcept(false)
Move-constructor, which reports a relocation.
Definition ObjectWatcher.hpp:331
~LifetimeWatcher() noexcept(false)
Destructor, which reports the call.
Definition ObjectWatcher.hpp:111
~RelocationWatcher()=default
Defaulted destructor.
RelocationWatcher(const for_base_tag< Base >)
Definition ObjectWatcher.hpp:285
RelocationWatcher(const RelocationWatcher &other)
Copy-constructor.
Definition ObjectWatcher.hpp:302
RelocationWatcher()=default
Defaulted default constructor.
LifetimeWatcher & operator=(LifetimeWatcher &&)=default
Defaulted move-assignment-operator.
LifetimeWatcher(const LifetimeWatcher &other)
Copy-constructor.
Definition ObjectWatcher.hpp:148
RelocationWatcher & operator=(const RelocationWatcher &other)
Copy-assignment-operator.
Definition ObjectWatcher.hpp:314
LifetimeWatcher & operator=(const LifetimeWatcher &other)
Copy-assignment-operator.
Definition ObjectWatcher.hpp:168
RelocationWatcher & operator=(RelocationWatcher &&other) noexcept(false)
Move-assignment-operator, which reports a relocation.
Definition ObjectWatcher.hpp:341
LifetimeWatcher(LifetimeWatcher &&)=default
Defaulted move-constructor.
LifetimeWatcher(const for_base_tag< Base >)
Definition ObjectWatcher.hpp:128
auto expect_destruct()
Begins a destruction-expectation construction.
Definition ObjectWatcher.hpp:207
Base type
Definition ObjectWatcher.hpp:61
constexpr for_base_tag< Base > for_base_v
Definition ObjectWatcher.hpp:65
constexpr printing::PrintTypeFn< T > print_type
Functional object, converting the given type to its textual representation.
Definition PrintType.hpp:478
std::basic_ostringstream< CharT, CharTraitsT > StringStreamT
Definition Format.hpp:35
std::basic_string< CharT, CharTraitsT > StringT
Definition Fwd.hpp:391
Definition ObjectWatcher.hpp:60