Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
slot.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "export.hpp"
4#include <cstddef>
5#include <cstdint>
6#include <utility>
7
8namespace aria::abi {
9
12struct SlotId {
13 std::uint64_t value = 0;
14 [[nodiscard]] constexpr bool valid() const noexcept { return value != 0; }
15 constexpr bool operator==(SlotId rhs) const noexcept { return value == rhs.value; }
16 constexpr bool operator!=(SlotId rhs) const noexcept { return value != rhs.value; }
17};
18
36public:
37 using Invoker = void (*)(void* state, void* args) noexcept;
38 using Destroyer = void (*)(void* state) noexcept;
39
40 SlotErased() noexcept = default;
41
42 SlotErased(Invoker inv, Destroyer dtor, void* state) noexcept
43 : invoker_(inv), destroyer_(dtor), state_(state) {}
44
45 ~SlotErased() noexcept;
46
47 SlotErased(SlotErased&& o) noexcept;
48 SlotErased& operator=(SlotErased&& o) noexcept;
49
50 SlotErased(const SlotErased&) = delete;
51 SlotErased& operator=(const SlotErased&) = delete;
52
53 void invoke(void* args) const noexcept {
54 if (ARIA_LIKELY(invoker_)) invoker_(state_, args);
55 }
56
57 [[nodiscard]] bool empty() const noexcept { return invoker_ == nullptr; }
58
59private:
60 Invoker invoker_ = nullptr;
61 Destroyer destroyer_ = nullptr;
62 void* state_ = nullptr;
63};
64
65} // namespace aria::abi
void(*)(void *state) noexcept Destroyer
Definition slot.hpp:38
void(*)(void *state, void *args) noexcept Invoker
Definition slot.hpp:37
bool empty() const noexcept
Definition slot.hpp:57
void invoke(void *args) const noexcept
Definition slot.hpp:53
SlotErased() noexcept=default
#define ARIA_ABI_API
Definition export.hpp:21
#define ARIA_LIKELY(x)
Definition export.hpp:96
Definition signal.hpp:12
Opaque slot identifier returned when a callback is registered with a Signal.
Definition slot.hpp:12
constexpr bool operator==(SlotId rhs) const noexcept
Definition slot.hpp:15
constexpr bool valid() const noexcept
Definition slot.hpp:14
constexpr bool operator!=(SlotId rhs) const noexcept
Definition slot.hpp:16
std::uint64_t value
Definition slot.hpp:13