stub_analytics_plugin  1.6
Network Optix Video Analytics SDK
uuid_helper.h
1 #pragma once
2 
3 #include <cstring>
4 #include <string>
5 
6 #include <nx/sdk/uuid.h>
7 
8 namespace nx {
9 namespace sdk {
10 
11 namespace UuidHelper
12 {
14  template<typename Byte>
15  Uuid fromRawData(const Byte* data)
16  {
17  static_assert(sizeof(Byte) == 1, "Expected pointer to array of byte-sized items");
18  Uuid result;
19  memcpy(&result, data, sizeof(result));
20  return result;
21  }
22 
24  Uuid fromStdString(const std::string& str);
25 
26  enum FormatOptions
27  {
28  none = 0,
29  uppercase = 1 << 0,
30  hyphens = 1 << 1,
31  braces = 1 << 2,
32  all = 0xFF
33  };
34 
36  std::string toStdString(const Uuid& uuid, FormatOptions formatOptions = FormatOptions::all);
37 
38  Uuid randomUuid();
39 }
40 
41 } // namespace sdk
42 } // namespace nx
43 
44 //-------------------------------------------------------------------------------------------------
45 // Functions that need to be in namespace std for compatibility with STL features.
46 
47 namespace std {
48 
49 inline std::ostream& operator<<(std::ostream& os, const nx::sdk::Uuid& uuid)
50 {
51  return os << nx::sdk::UuidHelper::toStdString(uuid);
52 }
53 
54 template<>
55 struct hash<nx::sdk::Uuid>
56 {
57  size_t operator()(const nx::sdk::Uuid& uuid) const
58  {
59  size_t h = 0;
60  for (const auto b: uuid)
61  h = (h + (324723947 + b)) ^ 93485734985;
62  return h;
63  }
64 };
65 
66 } // namespace std
Definition: to_string.h:44
Definition: uuid.h:17
Definition: debug.cpp:13