PLCnext API Documentation  22.9.0.33
Uuid.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include <boost/uuid/uuid.hpp>
9 #include <iostream>
10 
11 namespace Arp { namespace System { namespace Commons { namespace Configuration
12 {
13 
18 class Uuid
19 {
20 public: // typedefs/usings
21  using BasicUuid = boost::uuids::uuid;
22 
23 public: // construction/destruction
25  Uuid(void);
27  Uuid(const Uuid& arg) = default;
29  Uuid(Uuid&& arg) = default;
31  Uuid& operator=(const Uuid& arg) = default;
33  ~Uuid(void) = default;
34 
35 public: // global compare operators
36  friend bool operator==(const Uuid& lhs, const Uuid& rhs)noexcept;
37  friend bool operator!=(const Uuid& lhs, const Uuid& rhs)noexcept;
38  friend bool operator<(const Uuid& lhs, const Uuid& rhs)noexcept;
39  friend bool operator>(const Uuid& lhs, const Uuid& rhs)noexcept;
40  friend bool operator<=(const Uuid& lhs, const Uuid& rhs)noexcept;
41  friend bool operator>=(const Uuid& lhs, const Uuid& rhs)noexcept;
42 
43 public: // global stream operators
44  friend std::ostream& operator<<(std::ostream& os, const Uuid& id);
45  friend std::istream& operator>>(std::istream& is, Uuid& id);
46 
47 public: // static properties
49  static Uuid Empty(void);
50 
51 public: // static operations
53  static Uuid CreateNew(void);
54 
56  static Uuid Create(const byte* pBuffer);
57 
59  static Uuid CreateFromLittleEndian(const byte* pBuffer);
60 
71  static Uuid Parse(const String& input);
72 
78  static bool TryParse(const String& input, Uuid& result);
79 
80 public: // properties
83  bool IsEmpty(void)const;
84 
85 public: // operations
88  String ToString(void)const;
89 
92  size_t GetHashValue(void)const;
93 
95  void Clear(void);
96 
100  void CopyTo(byte* pBuffer)const;
101 
105  void CopyLittleEndianTo(byte* pBuffer)const;
106 
107 private: // fields
108  BasicUuid basicId;
109 };
110 
112 // inline methods of class Uuid
113 inline bool Uuid::IsEmpty()const
114 {
115  return basicId.is_nil();
116 }
117 
118 // global operators
119 inline bool operator==(const Uuid& lhs, const Uuid& rhs) noexcept
120 {
121  return lhs.basicId == rhs.basicId;
122 }
123 
124 inline bool operator!=(const Uuid& lhs, const Uuid& rhs) noexcept
125 {
126  return lhs.basicId != rhs.basicId;
127 }
128 
129 inline bool operator<(const Uuid& lhs, const Uuid& rhs) noexcept
130 {
131  return lhs.basicId < rhs.basicId;
132 }
133 
134 inline bool operator>(const Uuid& lhs, const Uuid& rhs) noexcept
135 {
136  return lhs.basicId > rhs.basicId;
137 }
138 
139 inline bool operator<=(const Uuid& lhs, const Uuid& rhs) noexcept
140 {
141  return lhs.basicId <= rhs.basicId;
142 }
143 
144 inline bool operator>=(const Uuid& lhs, const Uuid& rhs) noexcept
145 {
146  return lhs.basicId >= rhs.basicId;
147 }
148 
149 }}}} // end of namespace Arp::System::Commons::Configuration
150 
152 // standard template specializations of class Uuid
153 namespace std
154 {
155 
156 // std hash functor of class Uuid
157 template<>
158 struct hash<Arp::System::Commons::Configuration::Uuid>
159 {
160 public:
162  typedef size_t result_type;
163 
164 public:
165  result_type operator()(const argument_type& key) const
166  {
167  return key.GetHashValue();
168  }
169 };
170 }
This is a small immutable wrapper around the boost::uuids::uuid class and represents a universal uniq...
Definition: Uuid.hpp:19
static Uuid Empty(void)
Returns an empty (zero'ed) Uuid instance.
static Uuid CreateNew(void)
Creates a new unique id.
static Uuid Create(const byte *pBuffer)
Creates a unique id from the as argument passed binary representation in big endian.
static Uuid CreateFromLittleEndian(const byte *pBuffer)
Creates a unique id from the as argument passed binary representation in little endian.
void Clear(void)
Cleas this instance to an empty/zero'ed uuid.
size_t GetHashValue(void) const
Gets the hash value for this uuid.
~Uuid(void)=default
Destructs this instance and frees all resources.
Uuid(const Uuid &arg)=default
Copy constructor.
Uuid & operator=(const Uuid &arg)=default
Assignment operator.
static Uuid Parse(const String &input)
Creates a new unique id from the given input string.
void CopyLittleEndianTo(byte *pBuffer) const
Copies the binary representation to the given buffer in little endian.
Uuid(void)
Constructs an empty (zero'ed) Uuid instance.
static bool TryParse(const String &input, Uuid &result)
Creates a new unique id.
bool IsEmpty(void) const
Checks if this uuid is emtpy (zero'ed).
Definition: Uuid.hpp:113
Uuid(Uuid &&arg)=default
Move constructor.
String ToString(void) const
Creates a string representation of this uuid.
void CopyTo(byte *pBuffer) const
Copies the binary representation to the given buffer in big endian.
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API
Namespace of the C++ standard library