gwnavruntime/base/kyguid.h Source File

kyguid.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 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 
8 #ifndef Navigation_KyGuid_H
9 #define Navigation_KyGuid_H
10 
15 
16 
17 namespace Kaim
18 {
19 
22 class KyGuid
23 {
24  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
25  KY_ROOT_BLOB_CLASS(NavData, KyGuid, 0)
26 public:
27  static const KyGuid& GetDefaultGuid();
28  static const KyGuid& GetInvalidGuid();
29 
31  KyGuid();
32 
36  explicit KyGuid(const char guidString[/*37*/]);
37 
39  KyGuid(const KyGuid& rhs) { *this = rhs; }
40 
43  explicit KyGuid(KyUInt8 values[16]);
44 
47  explicit KyGuid(KyUInt16 values[8]);
48 
51  explicit KyGuid(KyUInt32 values[4]);
52 
55  explicit KyGuid(KyUInt64 values[2]);
56 
58  explicit KyGuid(void* src); //will memcpy from src to &m_uuid on sizeof(m_uuid)
59 
61  void Init(KyUInt32 a, KyUInt32 b, KyUInt32 c, KyUInt32 d);
62 
63  bool operator < (const KyGuid& rhs) const { return memcmp(m_uuid, rhs.m_uuid, sizeof (m_uuid)) < 0; }
64  bool operator <=(const KyGuid& rhs) const { return memcmp(m_uuid, rhs.m_uuid, sizeof (m_uuid)) <= 0; }
65  bool operator > (const KyGuid& rhs) const { return !operator<=(rhs); }
66  bool operator >=(const KyGuid& rhs) const { return !operator<(rhs); }
67  bool operator ==(const KyGuid& rhs) const { return memcmp(m_uuid, rhs.m_uuid, sizeof (m_uuid)) == 0; }
68  bool operator !=(const KyGuid& rhs) const { return !operator==(rhs); }
69 
70  KyGuid& operator = (const KyGuid& rhs) { memcpy(m_uuid, rhs.m_uuid, sizeof (m_uuid)); return *this; }
71 
73  bool IsValid() const { return *this != GetInvalidGuid(); }
74 
76  void ToString(char guidString[/*37*/]) const;
77 
79  void InitFromString(const char guidString[/*37*/]);
80 
81 
82 private:
83  // set [... a, b, c, d ...] a = value_most_significant_byte d = value_least_significant_byte
84  // |
85  // idx*4 idx must be in [0..3]
86  void SetUInt32(KyUInt32 idx, KyUInt32 value);
87 
88  // set [... a, b, ...] a = value_most_significant_byte d = value_least_significant_byte
89  // |
90  // idx*2 idx must be in [0..7]
91  void SetUInt16(KyUInt32 idx, KyUInt16 value);
92 
93 private:
94  KyUInt8 m_uuid[16];
95 };
96 
97 inline void SwapEndianness(Endianness::Target /*e*/, KyGuid& /*self*/)
98 {
99  //no swap needed on guid
100 }
101 
103 bool IsValidGuidString(const char guidStr[/*37*/]);
104 
105 template <class OSTREAM>
106 inline OSTREAM& operator<<(OSTREAM& os, const KyGuid& guid)
107 {
108  char guidString[37];
109  guid.ToString(guidString);
110  os << guidString;
111  return os;
112 }
113 
114 
115 } // namespace Kaim
116 
117 #endif
bool IsValidGuidString(const char guidStr[])
KyGuid()
Creates an invalid KyGuid.
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:35
The NavData class is the object containing navigation data that will be added to one Database...
Definition: navdata.h:44
unsigned __int64 KyUInt64
Type used internally to represent an unsigned 64-bit integer.
Definition: types.h:38
bool IsValid() const
Indicates whether the specified KyGuid is valid.
Definition: kyguid.h:75
static const KyGuid & GetInvalidGuid()
Returns the invalid KyGuid value.
unsigned char KyUInt8
Type used internally to represent an unsigned 8-bit integer.
Definition: types.h:41
Definition: gamekitcrowddispersion.h:20
The KyGuid class represents a globally unique ID.
Definition: kyguid.h:22
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
void InitFromString(const char guidString[])
Initializes this GUID using the specified string.
unsigned short KyUInt16
Type used internally to represent an unsigned 16-bit integer.
Definition: types.h:40
void ToString(char guidString[]) const
Converts this GUID to a string.
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
static const KyGuid & GetDefaultGuid()
Returns the default KyGuid value.