|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Unique identifier for distributed systems. More...
#include <uid.H>
Public Member Functions | |
| Uid ()=default | |
| Default constructor. | |
| Uid (const Aleph::IPv4_Address &_ipAddr, const uint64_t &_counter, const uint32_t &_port_number) | |
| Construct UID from components. | |
| Uid (const Aleph::IPv4_Address &_ipAddr, const unsigned int &_counter, const unsigned int &_port_number) | |
| Backward-compatible constructor with legacy parameter types. | |
| Uid (char *str) | |
| Construct UID from string representation. | |
| bool | operator== (const Uid &uid) const noexcept |
| Compare two UIDs for equality. | |
| char * | getStringUid (char *str, const size_t &size) const |
| Convert UID to hexadecimal string representation. | |
| const Aleph::IPv4_Address & | getIpAddr () const noexcept |
| Get IP address component. | |
| const uint32_t & | get_port_number () const noexcept |
| Get port number component. | |
| const uint64_t & | get_counter () const noexcept |
| Get counter component. | |
| const uint64_t & | get_random_number () const noexcept |
| Get a random number component. | |
| void | print () const |
| Print UID components to standard output. | |
Static Public Attributes | |
| static constexpr int | stringSize |
| Required buffer size for string representation. | |
Private Member Functions | |
| char * | stringficate (char *buffer, const size_t &src_size) const |
| Convert UID components to hexadecimal string. | |
| void | destringficate (char *str) |
| Parse hexadecimal string and populate UID components. | |
Private Attributes | |
| Aleph::IPv4_Address | ipAddr = 0 |
| IPv4 address component. | |
| uint32_t | port_number = 0 |
| Port number component. | |
| uint64_t | counter = 0 |
| Counter component. | |
| uint64_t | random_number = 0 |
| Random number component. | |
Friends | |
| struct | Uid_Offsets |
Unique identifier for distributed systems.
The Uid class generates and manages globally unique identifiers by combining:
This combination ensures uniqueness even across multiple machines and processes running simultaneously in a distributed system.
UIDs can be converted to/from hexadecimal string format for storage and transmission. The string size is fixed at stringSize bytes.
|
default |
Default constructor.
Creates a zero-initialized UID. All components (ipAddr, port_number, counter, random_number) are set to 0. Components can be overwritten later via assignment or other methods.
| none |
Referenced by destringficate(), and stringficate().
| Uid::Uid | ( | const Aleph::IPv4_Address & | _ipAddr, |
| const uint64_t & | _counter, | ||
| const uint32_t & | _port_number | ||
| ) |
Construct UID from components.
Creates a unique identifier from the provided components.
| _ipAddr | IPv4 address of the originating machine |
| _counter | sequence counter (typically incremented per UID) |
| _port_number | port number of the generating process |
| none |
Definition at line 92 of file uid.C.
References random_number.
|
inline |
Backward-compatible constructor with legacy parameter types.
This overload preserves source compatibility with older code that used unsigned int for the counter and port number. It delegates to the constructor taking uint64_t and uint32_t.
| none |
| Uid::Uid | ( | char * | str | ) |
Construct UID from string representation.
Reconstructs a UID from its hexadecimal string format.
| str | hexadecimal string (must be at least stringSize bytes) |
| std::invalid_argument | if the string format is invalid |
Definition at line 112 of file uid.C.
References ah_invalid_argument_if, destringficate(), and stringSize.
|
private |
Parse hexadecimal string and populate UID components.
| str | input string in hexadecimal format |
Definition at line 82 of file uid.C.
References Uid(), and unhexadecimalize().
Referenced by Uid().
|
inlinenoexcept |
|
inlinenoexcept |
Get port number component.
| none |
Definition at line 224 of file uid.H.
References port_number.
|
inlinenoexcept |
Get a random number component.
| none |
Definition at line 240 of file uid.H.
References random_number.
Referenced by main().
|
inlinenoexcept |
| char * Uid::getStringUid | ( | char * | str, |
| const size_t & | size | ||
| ) | const |
Convert UID to hexadecimal string representation.
Generates a string representation suitable for storage or transmission.
| str | output buffer (must be at least stringSize bytes) |
| size | size of output buffer |
| std::range_error | if buffer size is insufficient |
Definition at line 136 of file uid.C.
References ah_range_error_if, stringficate(), and stringSize.
|
noexcept |
|
inline |
Print UID components to standard output.
Prints all four components in human-readable format for debugging.
Definition at line 246 of file uid.H.
References counter, ipAddr, port_number, and random_number.
Referenced by main().
|
private |
Convert UID components to hexadecimal string.
| buffer | output buffer for string |
| src_size | size of output buffer |
Definition at line 62 of file uid.C.
References Uid(), ah_range_error_if, and hexadecimalize().
Referenced by getStringUid().
|
private |
|
private |
IPv4 address component.
Definition at line 98 of file uid.H.
Referenced by getIpAddr(), and print().
|
private |
Port number component.
Definition at line 99 of file uid.H.
Referenced by get_port_number(), and print().
|
private |
Random number component.
Definition at line 101 of file uid.H.
Referenced by Uid(), get_random_number(), and print().
|
staticconstexpr |
Required buffer size for string representation.
The string representation uses hexadecimal encoding, requiring 2 characters per byte plus null terminator.
Definition at line 109 of file uid.H.
Referenced by Uid(), getStringUid(), TEST(), and TEST().