Class for creating, storing, and managing unique identifiers.
Unique identifiers (UID) can be compared and follow a strict total order (==, !=, >, >=, <, <=). Additionally, every UID is associated with a unique identifier string, meaning that two UIDs that share the same numerical representation (uid_) are also associated with the same identifier string. Furthermore, it is not possible to create two UIDs that have different numerical representations but are both associated with the same identifier string. In other words: two UIDs / UID objects either have the same numerical representation (uid_) and the same identifier string or they have a different numerical representation and a different identifier string.
In addition to being constructed via constructor, UIDs can also be constructed via two static member functions:
For more information on how to create UIDs see the documentation of constructors and these two functions (UIDs can also be copied / copy constructed).
The template T specifies a class that is used to generate the numerical representations (uid_) for all UID<T>s. T must be an implementation of a UID generator class (see "UIDGenerators.h"). Every UID generator implements a static member function "uint_type generatUID()" which returns a new UID every time it is called. Additionally, UID generators implement a static member function "uint_type toIndex( const uint_type uid )" which translates the numerical representations of a given UID into an index which, for example, can be used for array access/storage. Moreover, UID generators implement a static member function "uint_type toBitMask( const uint_type uid )" which translates the numerical UID representations into a bit mask. For further information see the documentation of the two member functions "toIndex()" and "toBitMask()" of this class.
The class UID is thread safe and follows a multiple-readers / single-writer pattern.
#include <InitializationManager.h>
Public Types | |
using | uint_type = typename T::uint_type |
Public Member Functions | |
UID (const char *const identifier, const bool newUid=false, const bool appendUIDtoIdentifier=false) | |
For documentation see member function 'init'. More... | |
UID (const std::string &identifier, const bool newUid=false, const bool appendUIDtoIdentifier=false) | |
For documentation see member function 'init'. More... | |
UID (const bool createAnonymousUID=false) | |
The default constructor (-> createAnonymousUID is false by default!) is used to create uninitialized, invalid UID objects (by just declaring a variable without initializing it at declaration: "UID<T> uid; [...]; uid = [...];"). More... | |
uint_type | getUid () const |
const std::string & | getIdentifier () const |
uint_type | toIndex () const |
Returns '0' for the first UID created by T::generateUID(), '1' for the second, '2' for the third, etc. More... | |
uint_type | toBitMask () const |
Returns '[...] 0001' for the first UID created by T::generateUID(), '[...] 0010' for the second, '[...] 0100' for the third, etc. More... | |
void | toStream (std::ostream &os) const |
std::string | toString () const |
bool | operator== (const UID< T > &uid) const |
bool | operator!= (const UID< T > &uid) const |
bool | operator> (const UID< T > &uid) const |
bool | operator>= (const UID< T > &uid) const |
bool | operator< (const UID< T > &uid) const |
bool | operator<= (const UID< T > &uid) const |
Static Public Member Functions | |
static bool | exists (const std::string &identifier) |
static UID< T > | getOrConstruct (const std::string &identifier) |
Either returns a copy of an existing UID or creates and returns a completely new UID depending on whether a UID that is associated with the identifier string "identifier" already exists or not. More... | |
static UID< T > | get (const std::string &identifier) |
Returns the UID that is associated with the identifier string "identifier". More... | |
Private Member Functions | |
UID (const uint_type uid) | |
Must not be made public! Do not use this constructor. More... | |
void | init (const std::string &identifier, const bool newUid, const bool appendUIDtoIdentifier) |
This function is called by two constructors in order to create new UIDs or to retrieve copies of existing UIDs. More... | |
Static Private Member Functions | |
static std::map< uint_type, std::string > & | uidToString () |
static std::map< std::string, uint_type > & | stringToUid () |
static std::shared_timed_mutex & | uidToStringMutex () |
static std::shared_timed_mutex & | stringToUidMutex () |
Private Attributes | |
uint_type | uid_ |
bool | valid_ |
using walberla::uid::UID< T >::uint_type = typename T::uint_type |
|
inline |
For documentation see member function 'init'.
Do not delete this constructor! This constructor is required, so that writing "UID<TYPE> uid("id")" does not lead to calling the constructor "UID( const bool createAnonymousUID )".
|
inline |
For documentation see member function 'init'.
|
explicit |
The default constructor (-> createAnonymousUID is false by default!) is used to create uninitialized, invalid UID objects (by just declaring a variable without initializing it at declaration: "UID<T> uid; [...]; uid = [...];").
In debug mode, every operation involving such an uninitialized UID will trigger an assertion and fail. If createAnonymousUID is true, a valid UID with an unspecified identifier string is created.
|
inlineexplicitprivate |
Must not be made public! Do not use this constructor.
This constructor is intended for internal use only.
|
inlinestatic |
|
inlinestatic |
|
inline |
|
static |
|
inline |
|
private |
This function is called by two constructors in order to create new UIDs or to retrieve copies of existing UIDs.
If newUid is true, a completely new UID is created and associated with the string "identifier". In debug mode, creation of a new UID will trigger an assertion and fail if another UID with the same identifier string already exists. If newUid is false (-> default value, can be omitted), a copy of an existing UID is returned if the identifier string already exists, otherwise a new UID is created and associated with "identifier" (this behavior is identical to the static member function "getOrConstruct"). If newUid is true AND appendUIDtoIdentifier is also true, the newly created UID is appended to the provided identifier string.
Must not be made public! Do not use this function. This function is intended for internal use only.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
private |
|
private |