EduArt Sensor Ring Library 4.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 sensorring {
18
19namespace subscription {
20
27 using TokenType = unsigned long long;
28
32 SubscriberToken() noexcept : _value(0) {}
33
38 bool isValid() const noexcept { return _value != 0; }
39
43 static SubscriberToken getNextToken() noexcept {
44 static std::atomic<TokenType> next_token{ 1 };
45 return SubscriberToken(next_token++);
46 }
47
51 TokenType value() const noexcept { return _value; }
52
54 bool operator==(const SubscriberToken& other) const noexcept { return _value == other._value; }
55
57 bool operator!=(const SubscriberToken& other) const noexcept { return _value != other._value; }
58
59private:
63 SubscriberToken(TokenType value) noexcept : _value(value) {};
64
65 TokenType _value;
66};
67
68} // namespace subscription
69
70} // namespace sensorring
71
72} // namespace eduart
73
74#ifndef SWIG
75namespace std {
76
80template <> struct hash<eduart::sensorring::subscription::SubscriberToken> {
86 std::size_t operator()(const eduart::sensorring::subscription::SubscriberToken& token) const noexcept { return std::hash<eduart::sensorring::subscription::SubscriberToken::TokenType>{}(token.value()); }
87};
88
89} // namespace std
90#endif // SWIG
Opaque token identifying a subscription (state or device group).
Definition SubscriberToken.hpp:25
unsigned long long TokenType
Underlying numeric type used to represent the token value.
Definition SubscriberToken.hpp:27
TokenType value() const noexcept
Underlying value for hashing and comparison.
Definition SubscriberToken.hpp:51
SubscriberToken() noexcept
Default construction (invalid token, value 0).
Definition SubscriberToken.hpp:32
bool operator!=(const SubscriberToken &other) const noexcept
Inequality comparison operators for SubscriberToken.
Definition SubscriberToken.hpp:57
bool isValid() const noexcept
Check if the token is valid (non-zero).
Definition SubscriberToken.hpp:38
bool operator==(const SubscriberToken &other) const noexcept
Equality comparison operators for SubscriberToken.
Definition SubscriberToken.hpp:54
static SubscriberToken getNextToken() noexcept
Get the next token.
Definition SubscriberToken.hpp:43
std::size_t operator()(const eduart::sensorring::subscription::SubscriberToken &token) const noexcept
Compute hash value for a SubscriberToken.
Definition SubscriberToken.hpp:86