62 assert(type !=
ObjectType::Debug &&
"generateId called with reserved ObjectType::Debug");
65 uint64_t count = _counter.fetch_add(1, std::memory_order_relaxed);
66 constexpr uint64_t MAX_COUNTER_VALUE = 0x0000FFFFFFFFFFFF;
67 if (count >= MAX_COUNTER_VALUE)
69 throw std::overflow_error(
"FERS object ID counter has overflowed the 48-bit space.");
73 count &= MAX_COUNTER_VALUE;
76 const uint64_t type_bits =
static_cast<uint64_t
>(type) << 48;
77 return type_bits | count;
87 uint64_t count = _counter.fetch_add(1, std::memory_order_relaxed);
88 constexpr uint64_t MAX_COUNTER_VALUE = 0x0000FFFFFFFFFFFF;
89 if (count >= MAX_COUNTER_VALUE)
91 throw std::overflow_error(
"FERS object ID counter has overflowed the 48-bit space.");
95 count &= MAX_COUNTER_VALUE;
99 return type_bits | count;
114 std::atomic<uint64_t> _counter{1};
Thread-safe Meyers singleton for generating unique object IDs.
SimId generateId(ObjectType type)
Generate a unique SimId for a given object type.
static SimIdGenerator & instance()
Get the singleton instance of SimIdGenerator.
static ObjectType getType(const SimId id)
Extract object type from SimId.
SimId generateDebugId()
Generate a debug SimId.
static uint64_t getCounter(const SimId id)
Extract counter from SimId.
uint64_t SimId
64-bit Unique Simulation ID.
ObjectType
Categorizes objects for ID generation.