RandomUuid.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_SRC_BASE_RANDOMUUID_H
10#define SQUID_SRC_BASE_RANDOMUUID_H
11
12#include <array>
13#include <iosfwd>
14
18{
19public:
21 using Serialized = std::array<uint8_t, 128/8>;
22
24 RandomUuid();
25
27 explicit RandomUuid(const Serialized &);
28
29 RandomUuid(RandomUuid &&) = default;
31
32 // (Implicit) public copying is prohibited to prevent accidental duplication
33 // of supposed-to-be-unique values. Use clone() when duplication is needed.
34 RandomUuid &operator=(const RandomUuid &) = delete;
35
37 Serialized serialize() const;
38
39 bool operator ==(const RandomUuid &) const;
40 bool operator !=(const RandomUuid &other) const { return !(*this == other); }
41
43 RandomUuid clone() const { return *this; }
44
46 void print(std::ostream &os) const;
47
48private:
49 RandomUuid(const RandomUuid &) = default;
50
52 char *raw() { return reinterpret_cast<char*>(this); }
53
55 const char *raw() const { return reinterpret_cast<const char*>(this); }
56
58 bool sane() const;
59
60 /*
61 * These field sizes and names come from RFC 4122 Section 4.1.2. They do not
62 * accurately represent the actual UUID version 4 structure which, the six
63 * version/variant bits aside, contains just random bits.
64 */
65 uint32_t timeLow;
66 uint16_t timeMid;
69 uint8_t clockSeqLow;
70 uint8_t node[6];
71};
72
73std::ostream &operator<<(std::ostream &os, const RandomUuid &uuid);
74
75#endif /* SQUID_SRC_BASE_RANDOMUUID_H */
76
std::ostream & operator<<(std::ostream &os, const RandomUuid &uuid)
Definition: RandomUuid.cc:119
RandomUuid & operator=(const RandomUuid &)=delete
RandomUuid()
creates a new unique ID (i.e. not a "nil UUID" in RFC 4122 terminology)
Definition: RandomUuid.cc:27
RandomUuid & operator=(RandomUuid &&)=default
uint32_t timeLow
Definition: RandomUuid.h:65
uint8_t clockSeqHiAndReserved
Definition: RandomUuid.h:68
const char * raw() const
read-only access to storage bytes
Definition: RandomUuid.h:55
void print(std::ostream &os) const
writes a human-readable representation
Definition: RandomUuid.cc:92
bool sane() const
whether this (being constructed) object follows UUID version 4 variant 1 format
Definition: RandomUuid.cc:68
uint8_t clockSeqLow
Definition: RandomUuid.h:69
Serialized serialize() const
exports UUID value; suitable for long-term storage
Definition: RandomUuid.cc:79
std::array< uint8_t, 128/8 > Serialized
UUID representation independent of machine byte-order architecture.
Definition: RandomUuid.h:21
RandomUuid clone() const
creates a UUID object with the same value as this UUID
Definition: RandomUuid.h:43
bool operator!=(const RandomUuid &other) const
Definition: RandomUuid.h:40
bool operator==(const RandomUuid &) const
Definition: RandomUuid.cc:113
char * raw()
read/write access to storage bytes
Definition: RandomUuid.h:52
RandomUuid(const RandomUuid &)=default
RandomUuid(RandomUuid &&)=default
uint16_t timeMid
Definition: RandomUuid.h:66
uint16_t timeHiAndVersion
Definition: RandomUuid.h:67
Definition: parse.c:104

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors