Logo ROOT  
Reference Guide
UniqueId< Class > Struct Template Reference

template<class Class>
struct UniqueId< Class >

A UniqueId can be added as a class member to enhance any class with a unique identifier for each instantiated object.

Example:

class MyClass {
public:
/// Return unique ID by reference.
/// Please always use the name `uniqueId` for the getter.
UniqueId<MyClass> const& uniqueId() const { return _uniqueId; }
private:
const UniqueId<MyClass> _uniqueId; //! should be non-persistent
};
A UniqueId can be added as a class member to enhance any class with a unique identifier for each inst...
Definition: UniqueId.h:27

Definition at line 27 of file UniqueId.h.

Public Types

using Value_t = unsigned long
 

Public Member Functions

 UniqueId ()
 Create a new UniqueId with the next value from the static counter. More...
 
 UniqueId (const UniqueId &)=delete
 
 UniqueId (UniqueId &&)=delete
 
 operator Value_t () const
 
bool operator< (UniqueId const &other) const
 
UniqueIdoperator= (const UniqueId &)=delete
 
UniqueIdoperator= (UniqueId &&)=delete
 
bool operator== (UniqueId const &other) const
 
constexpr Value_t value () const
 Return numerical value of ID. More...
 

Static Public Attributes

static const UniqueId nullid {UniqueId<Class>::nullval}
 
static constexpr Value_t nullval = 0UL
 An ID that is less than the ID of any object (similar to nullptr). More...
 

Private Attributes

Value_t _val
 The value of the nullid. More...
 

Static Private Attributes

static std::atomic< Value_tcounter {UniqueId<Class>::nullval}
 Numerical value of the ID. More...
 

#include <UniqueId.h>

Member Typedef Documentation

◆ Value_t

template<class Class >
using UniqueId< Class >::Value_t = unsigned long

Definition at line 29 of file UniqueId.h.

Constructor & Destructor Documentation

◆ UniqueId() [1/3]

template<class Class >
UniqueId< Class >::UniqueId ( )
inline

Create a new UniqueId with the next value from the static counter.

Definition at line 32 of file UniqueId.h.

◆ UniqueId() [2/3]

template<class Class >
UniqueId< Class >::UniqueId ( const UniqueId< Class > &  )
delete

◆ UniqueId() [3/3]

template<class Class >
UniqueId< Class >::UniqueId ( UniqueId< Class > &&  )
delete

Member Function Documentation

◆ operator Value_t()

template<class Class >
UniqueId< Class >::operator Value_t ( ) const
inline

Definition at line 40 of file UniqueId.h.

◆ operator<()

template<class Class >
bool UniqueId< Class >::operator< ( UniqueId< Class > const &  other) const
inline

Definition at line 50 of file UniqueId.h.

◆ operator=() [1/2]

template<class Class >
UniqueId & UniqueId< Class >::operator= ( const UniqueId< Class > &  )
delete

◆ operator=() [2/2]

template<class Class >
UniqueId & UniqueId< Class >::operator= ( UniqueId< Class > &&  )
delete

◆ operator==()

template<class Class >
bool UniqueId< Class >::operator== ( UniqueId< Class > const &  other) const
inline

Definition at line 49 of file UniqueId.h.

◆ value()

template<class Class >
constexpr Value_t UniqueId< Class >::value ( ) const
inlineconstexpr

Return numerical value of ID.

Use only if necessary, as the UniqueId type information is lost and copying/moving is not prohibited for the value type. Please don't turn this into a cast operator, as a function with an explicit name is easier to track in the codebase.

Definition at line 47 of file UniqueId.h.

Member Data Documentation

◆ _val

template<class Class >
Value_t UniqueId< Class >::_val
private

The value of the nullid.

Definition at line 56 of file UniqueId.h.

◆ counter

template<class Class >
std::atomic< typename UniqueId< Class >::Value_t > UniqueId< Class >::counter {UniqueId<Class>::nullval}
staticprivate

Numerical value of the ID.

Definition at line 58 of file UniqueId.h.

◆ nullid

template<class Class >
const UniqueId< Class > UniqueId< Class >::nullid {UniqueId<Class>::nullval}
static

Definition at line 52 of file UniqueId.h.

◆ nullval

template<class Class >
constexpr Value_t UniqueId< Class >::nullval = 0UL
staticconstexpr

An ID that is less than the ID of any object (similar to nullptr).

Definition at line 53 of file UniqueId.h.

Collaboration diagram for UniqueId< Class >:
[legend]

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