AnCH Framework 0.1
Another C++ Hack Framework
Loading...
Searching...
No Matches
uuid.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <http://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include <iostream>
23#include <iomanip>
24#include <sstream>
25#include <random>
26#include <functional>
27#include <atomic>
28#include <mutex>
29#include <map>
30#include <cinttypes>
31
32
33namespace anch {
34
46 class UUID {
47 public:
83
84 // Attributes +
85 public:
87 static const uint64_t TIME_LOW_MASK = 0x00000000FFFFFFFF;
88
90 static const uint64_t TIME_MID_MASK = 0x000000000000FFFF;
91
93 static const uint64_t TIME_HIGH_MASK = 0x0000000000000FFF;
94
96 static const uint64_t VERSION_MASK = 0x000000000000F000;
97
99 static const uint32_t SEQ_LOW_MASK = 0x00FF;
100
102 static const uint32_t SEQ_HIGH_MASK = 0x3F00;
103
104 private:
106 static std::mutex _mutex;
107
109 static std::atomic_bool _seeded;
110
112 static std::map<UUID::Version, std::function<UUID(const std::string&)>> _providers;
113
115 uint32_t _lowTime;
116
118 uint16_t _midTime;
119
121 uint16_t _highTime;
122
124 uint16_t _clockSeqLow;
125
127 uint16_t _clockSeqHighRes;
128
130 uint64_t _node;
131
133 anch::UUID::Version _version;
134 // Attributes -
135
136
137 // Constructors +
138 public:
143
149 UUID(const UUID& uuid);
150
156 UUID(UUID&& uuid);
157
166 UUID(const std::string& uuid);
167
179 UUID(uint32_t lowTime,
180 uint16_t midTime,
181 uint16_t highTime,
182 uint16_t clockSeqLow,
183 uint16_t clockSeqHighRes,
184 uint64_t node,
185 UUID::Version version);
186 // Constructors -
187
188 // Destructor +
189 public:
193 virtual ~UUID();
194 // Destructor -
195
196 // Methods +
197 public:
204 static void registerProvider(UUID::Version version, std::function<UUID(const std::string&)> provider);
205
216 static UUID generateUUID(anch::UUID::Version version, const std::string& data = "");
217
223 static UUID random();
224
230 static UUID randomTime();
231
237 static uint64_t getUtcTimestamp();
238
244 static std::random_device& getRandomEngine();
245
251 static std::uniform_int_distribution<uint16_t>& getDistSeq();
252
260 static UUID parseUUID(const std::string& uuid);
261
267 void parse(const std::string& uuid);
268
274 std::string toString() const;
275
276 private:
280 static void registerRandomUUID();
281 // Methods -
282
283
284 // Operators +
285 public:
289 explicit operator std::string() const;
290
298 bool operator ==(const UUID& uuid) const;
299
307 bool operator !=(const UUID& uuid) const;
308
316 UUID& operator =(const UUID& uuid);
317 // Operators -
318
319
320 // Accessors +
321 public:
327 uint32_t getLowTime() const;
328
334 uint16_t getMidTime() const;
335
341 uint16_t getHighTime() const;
342
348 uint16_t getClockSeqLow() const;
349
355 uint16_t getClockSeqHighRes() const;
356
362 uint64_t getNode() const;
363
370 // Accessors -
371
372 };
373
374}
375
385template<class CharT, class Traits>
386std::basic_ostream<CharT, Traits>&
387operator<<(std::basic_ostream<CharT, Traits>& out, const anch::UUID& uuid);
388
389#include "impl/uuid.hpp"
UUID generator and parser.
Definition uuid.hpp:46
uint32_t getLowTime() const
static std::random_device & getRandomEngine()
bool operator==(const UUID &uuid) const
UUID(UUID &&uuid)
static std::uniform_int_distribution< uint16_t > & getDistSeq()
static const uint32_t SEQ_HIGH_MASK
Definition uuid.hpp:102
bool operator!=(const UUID &uuid) const
std::string toString() const
uint16_t getClockSeqLow() const
UUID(const std::string &uuid)
static const uint64_t TIME_LOW_MASK
Definition uuid.hpp:87
static uint64_t getUtcTimestamp()
static const uint32_t SEQ_LOW_MASK
Definition uuid.hpp:99
Version
Definition uuid.hpp:55
@ SHA1_HASH
Definition uuid.hpp:72
@ RANDOM
Definition uuid.hpp:69
@ NOT_SET
Definition uuid.hpp:57
@ MAC_ADDRESS
Definition uuid.hpp:60
@ MD5_HASH
Definition uuid.hpp:66
@ EXP
Definition uuid.hpp:81
@ RANDOM_TIME
Definition uuid.hpp:78
@ MAC_ADDRESS_R
Definition uuid.hpp:75
@ DCE_SECURITY
Definition uuid.hpp:63
UUID(uint32_t lowTime, uint16_t midTime, uint16_t highTime, uint16_t clockSeqLow, uint16_t clockSeqHighRes, uint64_t node, UUID::Version version)
static const uint64_t TIME_HIGH_MASK
Definition uuid.hpp:93
uint16_t getHighTime() const
anch::UUID::Version getVersion() const
static const uint64_t TIME_MID_MASK
Definition uuid.hpp:90
static UUID randomTime()
static UUID random()
static UUID generateUUID(anch::UUID::Version version, const std::string &data="")
UUID & operator=(const UUID &uuid)
uint64_t getNode() const
uint16_t getMidTime() const
virtual ~UUID()
void parse(const std::string &uuid)
UUID(const UUID &uuid)
static const uint64_t VERSION_MASK
Definition uuid.hpp:96
static void registerProvider(UUID::Version version, std::function< UUID(const std::string &)> provider)
static UUID parseUUID(const std::string &uuid)
uint16_t getClockSeqHighRes() const
AnCH framework base namespace.
Definition app.hpp:28