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:
71
72 // Attributes +
73 public:
75 static const uint64_t TIME_LOW_MASK = 0x00000000FFFFFFFF;
76
78 static const uint64_t TIME_MID_MASK = 0x000000000000FFFF;
79
81 static const uint64_t TIME_HIGH_MASK = 0x0000000000000FFF;
82
84 static const uint64_t VERSION_MASK = 0x000000000000F000;
85
87 static const uint32_t SEQ_LOW_MASK = 0x00FF;
88
90 static const uint32_t SEQ_HIGH_MASK = 0x3F00;
91
92 private:
94 static std::mutex _mutex;
95
97 static std::atomic_bool _seeded;
98
100 static std::map<UUID::Version, std::function<UUID(const std::string&)>> _providers;
101
103 uint32_t _lowTime;
104
106 uint16_t _midTime;
107
109 uint16_t _highTime;
110
112 uint16_t _clockSeqLow;
113
115 uint16_t _clockSeqHighRes;
116
118 uint64_t _node;
119
121 anch::UUID::Version _version;
122 // Attributes -
123
124
125 // Constructors +
126 public:
131
137 UUID(const UUID& uuid);
138
147 UUID(const std::string& uuid);
148
160 UUID(uint32_t lowTime, uint16_t midTime, uint16_t highTime, uint16_t clockSeqLow, uint16_t clockSeqHighRes, uint64_t node, UUID::Version version);
161 // Constructors -
162
163 // Destructor +
164 public:
168 virtual ~UUID();
169 // Destructor -
170
171 // Methods +
172 public:
179 static void registerProvider(UUID::Version version, std::function<UUID(const std::string&)> provider);
180
191 static UUID generateUUID(anch::UUID::Version version, const std::string& data = "");
192
198 static UUID random();
199
205 static uint64_t getUtcTimestamp();
206
212 static std::random_device& getRandomEngine();
213
219 static std::uniform_int_distribution<uint16_t>& getDistSeq();
220
226 std::string toString() const;
227
228 private:
232 static void registerRandomUUID();
233 // Methods -
234
235
236 // Operators +
237 public:
241 explicit operator std::string() const;
242 // Operators -
243
244
245 // Accessors +
246 public:
252 uint32_t getLowTime() const;
253
259 uint16_t getMidTime() const;
260
266 uint16_t getHighTime() const;
267
273 uint16_t getClockSeqLow() const;
274
280 uint16_t getClockSeqHighRes() const;
281
287 uint64_t getNode() const;
288
295 // Accessors -
296
297 };
298
299}
300
310template<class CharT, class Traits>
311std::basic_ostream<CharT, Traits>&
312operator<<(std::basic_ostream<CharT, Traits>& out, const anch::UUID& uuid);
313
314#include "impl/uuid.hpp"
UUID generator and parser.
Definition uuid.hpp:46
uint32_t getLowTime() const
static std::random_device & getRandomEngine()
static std::uniform_int_distribution< uint16_t > & getDistSeq()
static const uint32_t SEQ_HIGH_MASK
Definition uuid.hpp:90
std::string toString() const
uint16_t getClockSeqLow() const
UUID(const std::string &uuid)
static const uint64_t TIME_LOW_MASK
Definition uuid.hpp:75
static uint64_t getUtcTimestamp()
static const uint32_t SEQ_LOW_MASK
Definition uuid.hpp:87
Version
Definition uuid.hpp:55
@ SHA1_HASH
Definition uuid.hpp:69
@ RANDOM
Definition uuid.hpp:66
@ MAC_ADDRESS
Definition uuid.hpp:57
@ MD5_HASH
Definition uuid.hpp:63
@ DCE_SECURITY
Definition uuid.hpp:60
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:81
uint16_t getHighTime() const
anch::UUID::Version getVersion() const
static const uint64_t TIME_MID_MASK
Definition uuid.hpp:78
static UUID random()
static UUID generateUUID(anch::UUID::Version version, const std::string &data="")
uint64_t getNode() const
uint16_t getMidTime() const
virtual ~UUID()
UUID(const UUID &uuid)
static const uint64_t VERSION_MASK
Definition uuid.hpp:84
static void registerProvider(UUID::Version version, std::function< UUID(const std::string &)> provider)
uint16_t getClockSeqHighRes() const
AnCH framework base namespace.
Definition app.hpp:28