gwnavruntime/base/kyguid.h Source File

kyguid.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 #pragma once
8 
13 #include <string.h>
14 
15 namespace Kaim
16 {
17 
20 class KyGuid
21 {
22  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
23  KY_ROOT_BLOB_CLASS(NavData, KyGuid, 0)
24 public:
25  static const KyGuid& GetDefaultGuid();
26  static const KyGuid& GetInvalidGuid();
27 
29  KyGuid();
30 
34  explicit KyGuid(const char guidString[/*37*/]);
35 
37  KyGuid(const KyGuid& rhs) { *this = rhs; }
38 
41  explicit KyGuid(KyUInt8 values[16]);
42 
45  explicit KyGuid(KyUInt16 values[8]);
46 
49  explicit KyGuid(KyUInt32 values[4]);
50 
53  explicit KyGuid(KyUInt64 values[2]);
54 
56  explicit KyGuid(void* src); //will memcpy from src to &m_uuid on sizeof(m_uuid)
57 
59  void Init(KyUInt32 a, KyUInt32 b, KyUInt32 c, KyUInt32 d);
60 
61  bool operator < (const KyGuid& rhs) const { return memcmp(m_uuid, rhs.m_uuid, sizeof (m_uuid)) < 0; }
62  bool operator <=(const KyGuid& rhs) const { return memcmp(m_uuid, rhs.m_uuid, sizeof (m_uuid)) <= 0; }
63  bool operator > (const KyGuid& rhs) const { return !operator<=(rhs); }
64  bool operator >=(const KyGuid& rhs) const { return !operator<(rhs); }
65  bool operator ==(const KyGuid& rhs) const { return memcmp(m_uuid, rhs.m_uuid, sizeof (m_uuid)) == 0; }
66  bool operator !=(const KyGuid& rhs) const { return !operator==(rhs); }
67 
68  KyGuid& operator = (const KyGuid& rhs) { memcpy(m_uuid, rhs.m_uuid, sizeof (m_uuid)); return *this; }
69 
71  bool IsValid() const { return *this != GetInvalidGuid(); }
72 
74  void ToString(char guidString[/*37*/]) const;
75 
77  void InitFromString(const char guidString[/*37*/]);
78 
79 
80 private:
81  // set [... a, b, c, d ...] a = value_most_significant_byte d = value_least_significant_byte
82  // |
83  // idx*4 idx must be in [0..3]
84  void SetUInt32(KyUInt32 idx, KyUInt32 value);
85 
86  // set [... a, b, ...] a = value_most_significant_byte d = value_least_significant_byte
87  // |
88  // idx*2 idx must be in [0..7]
89  void SetUInt16(KyUInt32 idx, KyUInt16 value);
90 
91 private:
92  KyUInt8 m_uuid[16];
93 };
94 
95 inline void SwapEndianness(Endianness::Target /*e*/, KyGuid& /*self*/)
96 {
97  //no swap needed on guid
98 }
99 
101 bool IsValidGuidString(const char guidStr[/*37*/]);
102 
103 template <class OSTREAM>
104 inline OSTREAM& operator<<(OSTREAM& os, const KyGuid& guid)
105 {
106  char guidString[37];
107  guid.ToString(guidString);
108  os << guidString;
109  return os;
110 }
111 
112 
113 } // namespace Kaim
114 
KyGuid(const KyGuid &rhs)
Creates a new KyGuid copying the specified KyGuid.
Definition: kyguid.h:37
std::uint64_t KyUInt64
uint64_t
Definition: types.h:30
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
bool IsValidGuidString(const char guidStr[])
Definition: kyguid.cpp:52
KyGuid()
Creates an invalid KyGuid.
Definition: kyguid.cpp:72
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
std::uint16_t KyUInt16
uint16_t
Definition: types.h:28
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
The NavData class is the object containing navigation data that will be added to one Database...
Definition: navdata.h:39
bool IsValid() const
Indicates whether the specified KyGuid is valid.
Definition: kyguid.h:71
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
The KyGuid class represents a globally unique ID.
Definition: kyguid.h:20
static const KyGuid & GetInvalidGuid()
Returns the invalid KyGuid value.
Definition: kyguid.cpp:21
void InitFromString(const char guidString[])
Initializes this GUID using the specified string.
Definition: kyguid.cpp:173
static const KyGuid & GetDefaultGuid()
Returns the default KyGuid value.
Definition: kyguid.cpp:15
void ToString(char guidString[]) const
Converts this GUID to a string.
Definition: kyguid.cpp:157
std::uint8_t KyUInt8
uint8_t
Definition: types.h:27