EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
IDAllocator.hpp
Go to the documentation of this file.
1
9
10#ifndef ECHOMAP_IDALLOCATOR_HPP
11#define ECHOMAP_IDALLOCATOR_HPP
12
13#include <atomic>
14#include <cassert>
15#include <cstdint>
16#include <limits>
17
18namespace echomap
19{
20
21using id_type = std::uint64_t;
22
26template<typename>
28{
29public:
35 static constexpr id_type invalid_id = std::numeric_limits<id_type>::max();
36
43 [[nodiscard]] static id_type allocate() noexcept
44 {
45 const auto allocated = next_id.fetch_add(1, std::memory_order_relaxed);
46 assert(allocated != invalid_id);
47 return allocated;
48 }
49
50private:
51 inline static std::atomic<id_type> next_id = 0;
52};
53
54} // namespace echomap
55
56#endif // ECHOMAP_IDALLOCATOR_HPP
Provides a simple thread-safe runtime ID generator for Object managers.
static constexpr id_type invalid_id
Sentinel ID used by invalidated (moved-from) objects.
static id_type allocate() noexcept
Allocate the next ID.
T max(T... args)
The main EchoMap outermost namespace for all non-exported symbols.