morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::offline::Attempts Class Reference

A replay attempt count, as a type distinct from a queue item id. More...

#include <offline_queue.hpp>

Public Member Functions

constexpr Attempts () noexcept=default
 Constructs a zero attempt count.
template<typename Count>
requires (std::integral<Count> && !std::same_as<std::remove_cv_t<Count>, bool> && sizeof(Count) < sizeof(std::uint64_t))
constexpr Attempts (Count count) noexcept
 Implicitly wraps a narrow integral attempt count.
constexpr std::uint32_t value () const noexcept
 Returns the wrapped count.
constexpr bool operator== (const Attempts &other) const noexcept=default
 Compares two attempt counts.

Detailed Description

A replay attempt count, as a type distinct from a queue item id.

setAttempts(itemId, attempts) takes two integers that mean entirely different things, and before this type existed both were plain unsigned integers, mutually convertible in either direction. Transposing them compiled, and — because setAttempts() on an unknown id is a documented no-op — it also ran: the real item's count never advanced, nothing threw, and the defect surfaced much later as a retry budget that never exhausts.

Attempts removes the hazard rather than suppressing the warning about it. It is implicitly constructible from a narrow integer, so setAttempts(id, 3) reads exactly as it did before, and deliberately not constructible from a 64-bit integer, which is what a QueueItem::id is — so the transposed call does not compile. A genuinely 64-bit count is still expressible, with the narrowing spelled out at the call site: setAttempts(id, static_cast<std::uint32_t>(count)).

Definition at line 41 of file offline_queue.hpp.

Constructor & Destructor Documentation

◆ Attempts()

template<typename Count>
requires (std::integral<Count> && !std::same_as<std::remove_cv_t<Count>, bool> && sizeof(Count) < sizeof(std::uint64_t))
morph::offline::Attempts::Attempts ( Count count)
inlineconstexprnoexcept

Implicitly wraps a narrow integral attempt count.

Constrained to integral types strictly narrower than a queue item id, which is the whole point of the class: uint64_t (and any other 64-bit integer) is rejected, so passing an item id where an attempt count belongs is a compile error rather than a silent no-op. bool is excluded because a boolean is never an attempt count.

Template Parameters
CountIntegral type of the incoming count.
Parameters
countThe attempt count to wrap.

Definition at line 59 of file offline_queue.hpp.

Member Function Documentation

◆ value()

std::uint32_t morph::offline::Attempts::value ( ) const
inlinenodiscardconstexprnoexcept

Returns the wrapped count.

Returns
The attempt count as a plain uint32_t.

Definition at line 63 of file offline_queue.hpp.

◆ operator==()

bool morph::offline::Attempts::operator== ( const Attempts & other) const
nodiscardconstexprdefaultnoexcept

Compares two attempt counts.

Parameters
otherThe count to compare against.
Returns
true when both wrap the same value.

The documentation for this class was generated from the following file: