DirectZ
Loading...
Searching...
No Matches
dz::GlobalUID Struct Reference

Thread-safe UID generator that increments globally across the application. More...

#include <GlobalUID.hpp>

Inheritance diagram for dz::GlobalUID:
dz::StaticRestorable

Static Public Member Functions

static size_t GetNew ()
 Returns a new unique identifier.
static size_t GetNew (const std::string &key)
 Returns a new unique identifier incrementing the given Keys count.
Static Public Member Functions inherited from dz::StaticRestorable
template<typename T>
static int GetSID ()
template<typename T>
static void InitStaticRestorable ()

Static Public Attributes

static int SID = 1
static std::function< bool(Serial &)> RestoreFunction
static std::function< bool(Serial &)> BackupFunction

Detailed Description

Thread-safe UID generator that increments globally across the application.

Member Function Documentation

◆ GetNew() [1/2]

size_t dz::GlobalUID::GetNew ( )
inlinestatic

Returns a new unique identifier.

Returns
A size_t representing a new unique ID.

◆ GetNew() [2/2]

size_t dz::GlobalUID::GetNew ( const std::string & key)
inlinestatic

Returns a new unique identifier incrementing the given Keys count.

Returns
A size_t representing a new unique ID.

Member Data Documentation

◆ BackupFunction

std::function<bool(Serial&)> dz::GlobalUID::BackupFunction
inlinestatic
Initial value:
= [](auto& serial) {
serial << Count;
serial << KeyedCounts.size();
for (auto& [key, key_count] : KeyedCounts)
serial << key << key_count;
return true;
}

◆ RestoreFunction

std::function<bool(Serial&)> dz::GlobalUID::RestoreFunction
inlinestatic
Initial value:
= [](auto& serial) {
serial >> Count;
auto keyed_counts_size = KeyedCounts.size();
serial >> keyed_counts_size;
for (size_t count = 1; count <= keyed_counts_size; ++count) {
std::string key;
size_t key_count = 0;
serial >> key >> key_count;
KeyedCounts[key] = key_count;
}
return true;
}

◆ SID

int dz::GlobalUID::SID = 1
inlinestatic

The documentation for this struct was generated from the following file: