GOG GALAXY SDK Documentation
GalaxyID.h
Go to the documentation of this file.
1 #ifndef GALAXY_GALAXY_ID_H
2 #define GALAXY_GALAXY_ID_H
3 
10 #include "stdint.h"
11 #include <assert.h>
12 
13 namespace galaxy
14 {
15  namespace api
16  {
22 #pragma pack( push, 1 )
23 
29  class GalaxyID
30  {
31  public:
32 
36  enum IDType {
37  ID_TYPE_UNASSIGNED,
38  ID_TYPE_LOBBY,
39  ID_TYPE_USER
40  };
41 
45  static const uint64_t UNASSIGNED_VALUE = 0;
46 
54  static GalaxyID FromRealID(IDType type, uint64_t value)
55  {
56  assert(type != ID_TYPE_UNASSIGNED);
57  assert(value != UNASSIGNED_VALUE);
58  assert(static_cast<IDType>(value >> 56) == ID_TYPE_UNASSIGNED);
59  return GalaxyID(static_cast<uint64_t>(type) << 56 | value);
60  }
61 
67  GalaxyID(void) : value(UNASSIGNED_VALUE)
68  {
69  }
70 
76  GalaxyID(uint64_t _value) : value(_value)
77  {
78  }
79 
87  GalaxyID(const GalaxyID& galaxyID) : value(galaxyID.value)
88  {
89  }
90 
97  GalaxyID& operator=(const GalaxyID& other)
98  {
99  value = other.value;
100  return *this;
101  }
102 
110  bool operator<(const GalaxyID& other) const
111  {
112  assert(IsValid() && other.IsValid());
113  return value < other.value;
114  }
115 
122  bool operator==(const GalaxyID& other) const
123  {
124  return value == other.value;
125  }
126 
133  bool operator!=(const GalaxyID& other) const
134  {
135  return !(*this == other);
136  }
137 
143  bool IsValid() const
144  {
145  return value != UNASSIGNED_VALUE;
146  }
147 
158  uint64_t ToUint64() const
159  {
160  return value;
161  }
162 
170  uint64_t GetRealID() const
171  {
172  return value & 0xffffffffffffff;
173  }
174 
181  {
182  return static_cast<IDType>(value >> 56);
183  }
184 
185  private:
186 
187  uint64_t value;
188  };
189 
190 #pragma pack( pop )
191 
193  }
194 }
195 
196 #endif
Represents the ID of an entity used by Galaxy Peer.
Definition: GalaxyID.h:30
static GalaxyID FromRealID(IDType type, uint64_t value)
Creates GalaxyID from real ID and type.
Definition: GalaxyID.h:54
GalaxyID(void)
Default constructor.
Definition: GalaxyID.h:67
bool operator<(const GalaxyID &other) const
The lower operator.
Definition: GalaxyID.h:110
bool operator==(const GalaxyID &other) const
The equality operator.
Definition: GalaxyID.h:122
static const uint64_t UNASSIGNED_VALUE
The numerical value used when the instance of GalaxyID is not valid.
Definition: GalaxyID.h:45
IDType GetIDType() const
Returns the type of the ID.
Definition: GalaxyID.h:180
uint64_t GetRealID() const
Returns the numerical value of the real ID, without any extra flags.
Definition: GalaxyID.h:170
IDType
The type of the ID.
Definition: GalaxyID.h:36
GalaxyID & operator=(const GalaxyID &other)
The assignment operator.
Definition: GalaxyID.h:97
bool IsValid() const
Checks if the ID is valid and is assigned to an entity.
Definition: GalaxyID.h:143
GalaxyID(uint64_t _value)
Creates an instance of GalaxyID of a specified value.
Definition: GalaxyID.h:76
GalaxyID(const GalaxyID &galaxyID)
Copy constructor.
Definition: GalaxyID.h:87
bool operator!=(const GalaxyID &other) const
The inequality operator.
Definition: GalaxyID.h:133
uint64_t ToUint64() const
Returns the numerical value of the ID.
Definition: GalaxyID.h:158