Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
shambase::WithUUID< T, Tint, thread_safe > Class Template Reference

A class that provides unique identifiers (UUID) to instances. More...

#include <shambase/include/shambase/WithUUID.hpp>

Public Member Functions

Tint get_uuid () const
 Get the uuid of the class.
bool is_alive () const
 Whether this instance still holds a valid uuid (false once moved from).
void invalidate ()
 Marks this instance's uuid as invalid, e.g. to give up identity outside of a move.
 WithUUID ()
 Constructor of the class.
 WithUUID (const WithUUID &)=delete
 would duplicate the uuid
WithUUID & operator= (const WithUUID &)=delete
 would duplicate the uuid
 WithUUID (WithUUID &&other) noexcept
 Move constructor: transfers the uuid to this and invalidates other.
WithUUID & operator= (WithUUID &&other) noexcept
 Move assignment: transfers the uuid to this and invalidates other.

Static Public Attributes

static constexpr Tint invalid_uuid = std::numeric_limits<Tint>::max()

Protected Attributes

Tint uuid
 The unique identifier of the class.

Detailed Description

template<typename T, class Tint, bool thread_safe = true>
class shambase::WithUUID< T, Tint, thread_safe >

A class that provides unique identifiers (UUID) to instances.

Template Parameters
TThe class type to which the UUID will be assigned
TintThe data type for the UUID
thread_safeWhether the UUID constructor should be thread-safe

Example usage:

class A1 : public WithUUID<A1, u64> {};
...
std::cout << "Instance1 UUID: " << A1{}.get_uuid() << std::endl;
WithUUID()
Constructor of the class.
Definition WithUUID.hpp:72

Copy is deleted (would duplicate the uuid). Move transfers the uuid and invalidates the source, so check is_alive() rather than assuming a moved-from instance still has one.

Definition at line 41 of file WithUUID.hpp.

Constructor & Destructor Documentation

◆ WithUUID() [1/2]

template<typename T, class Tint, bool thread_safe = true>
shambase::WithUUID< T, Tint, thread_safe >::WithUUID ( )
inline

Constructor of the class.

Assigns a unique identifier to the class

Definition at line 72 of file WithUUID.hpp.

◆ WithUUID() [2/2]

template<typename T, class Tint, bool thread_safe = true>
shambase::WithUUID< T, Tint, thread_safe >::WithUUID ( WithUUID< T, Tint, thread_safe > && other)
inlinenoexcept

Move constructor: transfers the uuid to this and invalidates other.

Definition at line 90 of file WithUUID.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ get_uuid()

template<typename T, class Tint, bool thread_safe = true>
Tint shambase::WithUUID< T, Tint, thread_safe >::get_uuid ( ) const
inline

Get the uuid of the class.

Returns
The uuid of the class

Definition at line 59 of file WithUUID.hpp.

◆ invalidate()

template<typename T, class Tint, bool thread_safe = true>
void shambase::WithUUID< T, Tint, thread_safe >::invalidate ( )
inline

Marks this instance's uuid as invalid, e.g. to give up identity outside of a move.

Definition at line 65 of file WithUUID.hpp.

◆ is_alive()

template<typename T, class Tint, bool thread_safe = true>
bool shambase::WithUUID< T, Tint, thread_safe >::is_alive ( ) const
inline

Whether this instance still holds a valid uuid (false once moved from).

Definition at line 62 of file WithUUID.hpp.

◆ operator=()

template<typename T, class Tint, bool thread_safe = true>
WithUUID & shambase::WithUUID< T, Tint, thread_safe >::operator= ( WithUUID< T, Tint, thread_safe > && other)
inlinenoexcept

Move assignment: transfers the uuid to this and invalidates other.

Definition at line 93 of file WithUUID.hpp.

Here is the call graph for this function:

Member Data Documentation

◆ invalid_uuid

template<typename T, class Tint, bool thread_safe = true>
Tint shambase::WithUUID< T, Tint, thread_safe >::invalid_uuid = std::numeric_limits<Tint>::max()
staticconstexpr

Sentinel marking an invalidated/moved-from instance (0 is a valid uuid, so max is used instead).

Definition at line 52 of file WithUUID.hpp.

◆ uuid

template<typename T, class Tint, bool thread_safe = true>
Tint shambase::WithUUID< T, Tint, thread_safe >::uuid
protected

The unique identifier of the class.

Definition at line 47 of file WithUUID.hpp.


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