35#include <unordered_set>
91 std::bitset<MaxCores> _bits;
106 for (
const auto id : coreIds) {
117 for (
const auto id : ids) {
126 [[nodiscard]]
const std::bitset<MaxCores> &
138 return id <
MaxCores && _bits.test(
id);
195 return _bits.count();
202 [[nodiscard]] std::vector<CoreId>
204 std::vector<CoreId> result;
205 result.reserve(_bits.count());
207 for (
size_t i = 0; i <
MaxCores; ++i) {
209 result.push_back(
static_cast<CoreId>(i));
224 for (
size_t i = 0; i <
MaxCores; ++i) {
226 result.insert(
static_cast<CoreId>(i));
260 while (_pos <
MaxCores && !_set._bits.test(_pos)) {
266 using iterator_category = std::forward_iterator_tag;
267 using value_type =
CoreId;
268 using difference_type = std::ptrdiff_t;
269 using pointer =
const CoreId *;
270 using reference =
const CoreId &;
289 return static_cast<CoreId>(_pos);
321 return &_set == &other._set && _pos == other._pos;
331 return !(*
this == other);
339 [[nodiscard]] iterator
348 [[nodiscard]] iterator
375 template <
typename T>
376 friend struct std::hash;
378 friend class CoreInitializer;
379 friend class SharedCoreCommunication;
380 friend class VirtualCore;
382 friend class Service;
392 static constexpr uint32_t NotFound = 0;
393 static constexpr ServiceId BroadcastSid = (std::numeric_limits<ServiceId>::max)();
403 ActorId(uint32_t
id) noexcept;
409 [[nodiscard]] operator uint32_t() const noexcept;
445class BroadcastId : public ActorId {
447 BroadcastId() =
delete;
544struct hash<qb::ActorId> {
552 return static_cast<uint32_t
>(val);
Platform, compiler, and C++ feature detection macros for the QB Framework.
Unique identifier for actors.
Definition ActorId.h:374
CoreId index() const noexcept
Get the core identifier component of this ActorId.
ServiceId sid() const noexcept
Get the service identifier component of this ActorId.
bool is_valid() const noexcept
Check if this ActorId is valid (not NotFound)
bool is_broadcast() const noexcept
Check if this ActorId represents a broadcast identifier.
Specialized ActorId for broadcasting messages to all actors on a core.
Definition ActorId.h:445
Iterator for traversing set bits in a CoreIdBitSet.
Definition ActorId.h:252
iterator operator++(int)
Post-increment operator.
Definition ActorId.h:308
iterator(const CoreIdBitSet &set, size_t pos)
Constructs an iterator for a CoreIdBitSet.
Definition ActorId.h:277
CoreId operator*() const
Dereference operator.
Definition ActorId.h:288
bool operator!=(const iterator &other) const
Inequality comparison operator.
Definition ActorId.h:330
bool operator==(const iterator &other) const
Equality comparison operator.
Definition ActorId.h:320
iterator & operator++()
Pre-increment operator.
Definition ActorId.h:297
Efficient representation of a set of core IDs using a bitset.
Definition ActorId.h:89
qb::unordered_set< CoreId > to_unordered_set() const
Get an unordered_set of the core IDs.
Definition ActorId.h:221
const std::bitset< MaxCores > & bits() const noexcept
Get the raw bitset.
Definition ActorId.h:127
void remove(CoreId id) noexcept
Remove a core ID from the set.
Definition ActorId.h:166
iterator begin() const
Get an iterator to the beginning of the set.
Definition ActorId.h:340
qb::unordered_set< CoreId > raw() const
Get a reference to the raw set for internal use.
Definition ActorId.h:238
size_t size() const noexcept
Get the number of core IDs in the set.
Definition ActorId.h:194
void emplace(CoreId id) noexcept
Add a core ID to the set (emplace version)
Definition ActorId.h:157
iterator end() const
Get an iterator to the end of the set.
Definition ActorId.h:349
void clear() noexcept
Clear all core IDs from the set.
Definition ActorId.h:176
bool empty() const noexcept
Check if the set is empty.
Definition ActorId.h:185
void insert(CoreId id) noexcept
Add a core ID to the set.
Definition ActorId.h:146
bool contains(CoreId id) const noexcept
Check if a core ID is in the set.
Definition ActorId.h:137
std::vector< CoreId > to_vector() const
Convert the set to a vector of core IDs.
Definition ActorId.h:203
constexpr size_t MaxCores
Maximum number of cores supported in a system.
Definition ActorId.h:80
CoreIdBitSet()=default
Default constructor - creates an empty set.
BroadcastId(uint32_t const core_id) noexcept
Constructor for BroadcastId.
Definition ActorId.h:453
CoreIdBitSet(std::initializer_list< CoreId > ids)
Constructor from an initializer list.
Definition ActorId.h:116
std::ostream & operator<<(std::ostream &os, qb::Actor const &actor)
Stream output operator for Actor objects.
CoreIdBitSet(const qb::unordered_set< CoreId > &coreIds)
Constructor from a set of core IDs.
Definition ActorId.h:105
std::unordered_set< K, H, E, A > unordered_set
The primary unordered set implementation.
Definition unordered_set.h:81
std::vector< ActorId > ActorIdList
List of actor identifiers.
Definition ActorId.h:463
uint16_t CoreId
Type definition for core identifiers.
Definition ActorId.h:51
uint16_t TypeId
Type definition for type identifiers.
Definition ActorId.h:67
CoreId core_id
Alias for CoreId.
Definition ActorId.h:479
uint16_t ServiceId
Type definition for service identifiers.
Definition ActorId.h:59
std::unordered_set< ActorId > ActorIdSet
Set of unique actor identifiers.
Definition ActorId.h:471
CoreIdSet core_id_set
Alias for CoreIdSet.
Definition ActorId.h:527
ActorId actor_id
Alias for ActorId.
Definition ActorId.h:495
BroadcastId broadcast_id
Alias for BroadcastId.
Definition ActorId.h:503
ServiceId service_id
Alias for ServiceId.
Definition ActorId.h:487
ActorIdSet actor_is_set
Alias for ActorIdSet.
Definition ActorId.h:519
TypeId EventId
Type definition for event identifiers.
Definition ActorId.h:75
ActorIdList actor_id_list
Alias for ActorIdList.
Definition ActorId.h:511
CoreIdBitSet CoreIdSet
Efficient set implementation for storing CoreId values.
Definition ActorId.h:363
Core I/O and logging utilities for the qb framework.
Platform-specific alignment macros, cache-line definitions, and related utilities.
std::size_t operator()(qb::ActorId const &val) const noexcept
Hash function operator for ActorId.
Definition ActorId.h:551
Optimized unordered set implementations.