EduArt Sensor Ring Library 3.0.0
Loading...
Searching...
No Matches
SubscriberToken.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 EduArt Robotik GmbH
2
9
10#pragma once
11
12#include <atomic>
13#include <functional>
14
15namespace eduart {
16
17namespace subscription {
18
24 using TokenType = unsigned long long;
25
29 SubscriberToken() noexcept : _value(0) {}
30
35 bool isValid() const noexcept { return _value != 0; }
36
40 static SubscriberToken getNextToken() noexcept {
41 static std::atomic<TokenType> next_token{ 1 };
42 return SubscriberToken(next_token++);
43 }
44
48 TokenType value() const noexcept { return _value; }
49
51 bool operator==(const SubscriberToken& other) const noexcept { return _value == other._value; }
52
54 bool operator!=(const SubscriberToken& other) const noexcept { return _value != other._value; }
55
56private:
60 SubscriberToken(TokenType value) noexcept : _value(value) {};
61
62 TokenType _value;
63};
64
65} // namespace subscription
66
67} // namespace eduart
68
69#ifndef SWIG
70namespace std {
71
76template <> struct hash<eduart::subscription::SubscriberToken> {
82 std::size_t operator()(const eduart::subscription::SubscriberToken& token) const noexcept { return std::hash<eduart::subscription::SubscriberToken::TokenType>{}(token.value()); }
83};
84
85} // namespace std
86#endif // SWIG
Opaque token identifying a subscription (state or device group).
Definition SubscriberToken.hpp:22
unsigned long long TokenType
Token type.
Definition SubscriberToken.hpp:24
bool isValid() const noexcept
Check if the token is valid (non-zero).
Definition SubscriberToken.hpp:35
bool operator!=(const SubscriberToken &other) const noexcept
Inequality comparison operators for SubscriberToken.
Definition SubscriberToken.hpp:54
TokenType value() const noexcept
Underlying value for hashing and comparison.
Definition SubscriberToken.hpp:48
static SubscriberToken getNextToken() noexcept
Get the next token.
Definition SubscriberToken.hpp:40
SubscriberToken() noexcept
Default construction (invalid token, value 0).
Definition SubscriberToken.hpp:29
bool operator==(const SubscriberToken &other) const noexcept
Equality comparison operators for SubscriberToken.
Definition SubscriberToken.hpp:51
std::size_t operator()(const eduart::subscription::SubscriberToken &token) const noexcept
Compute hash value for a SubscriberToken.
Definition SubscriberToken.hpp:82