# Poco

# class ULID

Library: Foundation
Package: ULID
Header: Poco/ULID.h

## Description

This class implements a [Universally Unique Lexicographically Sortable Identifier](https://github.com/ulid/spec) (ULID).

To generate a new random ULID, see ULIDGenerator::create().

## Member Summary

Member Functions: compare, copyFrom, copyTo, decode, isNull, null, operator !=, operator <, operator <=, operator =, operator ==, operator >, operator >=, parse, randomHigh, randomLow, swap, time, toString, tryParse

## Constructors

### ULID

ULID() = default;

Creates a nil (all zero) ULID.

### ULID

ULID(
const ULID & ulid
) = default;

Copy constructor.

### ULID

explicit ULID(
const std::string & ulid
);

Parses the ULID from a string.

### ULID

explicit ULID(
const char * ulid
);

Parses the ULID from a string.

### ULID

ULID(
UInt64 time,
UInt16 randomHigh,
UInt64 randomLow
);

Creates a ULID from its components.

## Destructor

### ~ULID

~ULID() = default;

Destroys the ULID.

## Member Functions

### copyFrom

void copyFrom(
const char * buffer
);

Copies the ULID (16 bytes) from a buffer or byte array. The ULID fields are expected to be stored in network byte order. The buffer need not be aligned.

### copyTo

void copyTo(
char * buffer
) const;

Copies the ULID to the buffer. The fields are in network byte order. The buffer need not be aligned. There must have room for at least 16 bytes.

### isNull

bool isNull() const;

Returns true iff the ULID is nil (in other words, consists of all zeros).

### null

static const ULID & null();

Returns a null/nil ULID.

### operator !=

bool operator != (
const ULID & ulid
) const;

### operator <

bool operator < (
const ULID & ulid
) const;

### operator <=

bool operator <= (
const ULID & ulid
) const;

### operator =

ULID & operator = (
const ULID & ulid
);

Assignment operator.

### operator ==

bool operator == (
const ULID & ulid
) const;

### operator >

bool operator > (
const ULID & ulid
) const;

### operator >=

bool operator >= (
const ULID & ulid
) const;

### parse

void parse(
const std::string & ulid
);

Parses the ULID from its string representation.

### randomHigh

Poco::UInt16 randomHigh() const;

Returns the most significant 16 bits of the 80-bit random part of the ULID.

### randomLow

Poco::UInt64 randomLow() const;

Returns the least significant 64 bits of the 80-bit random part of the ULID.

### swap

void swap(
ULID & ulid
) noexcept;

Swaps the ULID with another one.

### time

Poco::UInt64 time() const;

Returns the 48-bit time part of the ULID (milliseconds since Unix epoch).

### toString

std::string toString() const;

Returns a string representation of the ULID, using Crockford's Base 32 encoding.

### tryParse

bool tryParse(
const std::string & ulid
);

Tries to interpret the given string as an ULID. If the ULID is syntactically valid, assigns the members and returns true. Otherwise leaves the object unchanged and returns false.

### compare

int compare(
const ULID & ulid
) const;

### decode

template < typename T > static T decode(
char c
);