-
Notifications
You must be signed in to change notification settings - Fork 0
/
uuid.hpp
143 lines (113 loc) · 4.82 KB
/
uuid.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* \file uuid.hpp
*
* \brief This header contains an implementation of a universal identifier
* structure
*
* \author Matthew Rodusek ([email protected])
*/
#ifndef BIT_STL_UTILITIES_UTILITIES_UUID_HPP
#define BIT_STL_UTILITIES_UTILITIES_UUID_HPP
#include "byte.hpp"
#include <algorithm> // std::equal, std::lexicographical_compare
namespace bit {
namespace stl {
//////////////////////////////////////////////////////////////////////////
/// \class uuid
/// \brief A wrapper type to represent universally unique identifiers
///
//////////////////////////////////////////////////////////////////////////
class uuid
{
//----------------------------------------------------------------------
// Public Member Types
//----------------------------------------------------------------------
public:
using value_type = byte;
using reference = value_type&;
using pointer = value_type*;
using const_reference = const value_type&;
using const_pointer = const value_type*;
using iterator = const byte*;
using const_iterator = const byte*;
using size_type = std::size_t;
//----------------------------------------------------------------------
// Constructors
//----------------------------------------------------------------------
public:
/// \brief Constructs a uuid without initializing any entries
uuid() noexcept;
/// \brief Constructs a uuid from an array of 16 bytes
///
/// \param array a reference to an array containing 16 bytes
constexpr uuid( const value_type(&array)[16] ) noexcept;
/// \brief Copy-constructs a uuid from another uuid
///
/// \param other the other uuid to copy
constexpr uuid( const uuid& other ) noexcept = default;
/// \brief Move-constructs a uuid from another uuid
///
/// \param other the other uuid to move
constexpr uuid( uuid&& other ) noexcept = default;
//----------------------------------------------------------------------
// Assignment
//----------------------------------------------------------------------
public:
/// \brief Assigns a uuid from an array of 16 bytes
///
/// \param array a reference to an array containing 16 bytes
/// \return a reference to \c (*this)
uuid& operator=( const value_type(&)[16] ) noexcept;
/// \brief Copy-assigns this uuid from another uuid
///
/// \param other the other uuid to copy
/// \return a reference to \c (*this)
uuid& operator=( const uuid& other ) noexcept = default;
/// \brief Move-assigns this uuid from another uuid
///
/// \param other the other uuid to move
/// \return a reference to \c (*this)
uuid& operator=( uuid&& other ) noexcept = default;
//----------------------------------------------------------------------
// Capacity
//----------------------------------------------------------------------
public:
/// \brief Returns the size of this uuid
///
/// \return 16
constexpr size_type size() const noexcept;
//----------------------------------------------------------------------
// Iterators
//----------------------------------------------------------------------
public:
/// \brief Returns an iterator to the beginning of the uuid sequence
///
/// \return iterator to the beginning
constexpr iterator begin() const noexcept;
/// \brief Returns an iterator to the end of the uuid sequence
///
/// \return iterator to the end
constexpr iterator end() const noexcept;
/// \copydoc uuid::begin() const noexcept
constexpr iterator cbegin() const noexcept;
/// \copydoc uuid::end() const noexcept
constexpr iterator cend() const noexcept;
//----------------------------------------------------------------------
// Private Members
//----------------------------------------------------------------------
private:
value_type m_storage[16]; ///< the storage of the uuid bytes
};
//------------------------------------------------------------------------
// Comparison Operators
//------------------------------------------------------------------------
bool operator==(const uuid& lhs, const uuid& rhs) noexcept;
bool operator!=(const uuid& lhs, const uuid& rhs) noexcept;
bool operator<(const uuid& lhs, const uuid& rhs) noexcept;
bool operator>(const uuid& lhs, const uuid& rhs) noexcept;
bool operator<=(const uuid& lhs, const uuid& rhs) noexcept;
bool operator>=(const uuid& lhs, const uuid& rhs) noexcept;
} // namespace stl
} // namespace bit
#include "detail/uuid.inl"
#endif /* BIT_STL_UTILITIES_UTILITIES_UUID_HPP */