aboutsummaryrefslogtreecommitdiff
path: root/ttwhy/core/concepts.cppm
blob: e1442d6e44d0b055207bbf6c7a5cc0b014b46fa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module;

#include <asio/awaitable.hpp>

#include <concepts>
#include <span>

export module ttwhy.core:concepts;

namespace ttwhy
{

  //! Validates that a candidate type implements the byte scanner interface.
  //!
  //! @tparam Candidate The type to validate.
  export template<typename Candidate>
  concept scanner = requires(Candidate a, std::span<char const> buffer) {
    { a.process(buffer) } -> std::same_as<void>;
    { a.timeout() } -> std::same_as<void>;
    { a.is_pending() } -> std::same_as<bool>;
  };

  //! Validates that a candidate type implements an asynchronous event router interface.
  //!
  //! @tparam Candidate The type to validate.
  //! @tparam Event The type of the event to process.
  export template<typename Candidate, typename Event>
  concept router = requires(Candidate candidate, Event event) {
    { candidate.process(event) } -> std::same_as<asio::awaitable<void>>;
  };

  //! Validates that a sink type can receive an event of the given type.
  //!
  //! @tparam Sink The sink callable type.
  //! @tparam Event The type of the event to deliver.
  export template<typename Sink, typename Event>
  concept event_sink = requires(Sink sink, Event event) {
    { sink(event) } -> std::same_as<void>;
  };

}  // namespace ttwhy