GridGain C++
guid.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 GridGain Systems, Inc. and Contributors.
3  *
4  * Licensed under the GridGain Community Edition License (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 #ifndef _IGNITE_GUID
23 #define _IGNITE_GUID
24 
25 #include <stdint.h>
26 #include <iomanip>
27 
28 #include <ignite/common/common.h>
29 
30 namespace ignite
31 {
35  class IGNITE_IMPORT_EXPORT Guid
36  {
37  public:
41  Guid();
42 
49  Guid(int64_t most, int64_t least);
50 
56  int64_t GetMostSignificantBits() const;
57 
63  int64_t GetLeastSignificantBits() const;
64 
77  int32_t GetVersion() const;
78 
91  int32_t GetVariant() const;
92 
98  int32_t GetHashCode() const;
99 
107  friend bool IGNITE_IMPORT_EXPORT operator== (const Guid& val1, const Guid& val2);
108 
115  int64_t Compare(const Guid& other) const;
116 
124  friend bool IGNITE_IMPORT_EXPORT operator==(const Guid& val1, const Guid& val2);
125 
133  friend bool IGNITE_IMPORT_EXPORT operator!=(const Guid& val1, const Guid& val2);
134 
142  friend bool IGNITE_IMPORT_EXPORT operator<(const Guid& val1, const Guid& val2);
143 
151  friend bool IGNITE_IMPORT_EXPORT operator<=(const Guid& val1, const Guid& val2);
152 
160  friend bool IGNITE_IMPORT_EXPORT operator>(const Guid& val1, const Guid& val2);
161 
169  friend bool IGNITE_IMPORT_EXPORT operator>=(const Guid& val1, const Guid& val2);
170 
171  private:
173  int64_t most;
174 
176  int64_t least;
177  };
178 
186  template<typename C>
187  ::std::basic_ostream<C>& operator<<(std::basic_ostream<C>& os, const Guid& guid)
188  {
189  uint32_t part1 = static_cast<uint32_t>(guid.GetMostSignificantBits() >> 32);
190  uint16_t part2 = static_cast<uint16_t>(guid.GetMostSignificantBits() >> 16);
191  uint16_t part3 = static_cast<uint16_t>(guid.GetMostSignificantBits());
192  uint16_t part4 = static_cast<uint16_t>(guid.GetLeastSignificantBits() >> 48);
193  uint64_t part5 = guid.GetLeastSignificantBits() & 0x0000FFFFFFFFFFFFU;
194 
195  os << std::hex
196  << std::setfill<C>('0') << std::setw(8) << part1 << '-'
197  << std::setfill<C>('0') << std::setw(4) << part2 << '-'
198  << std::setfill<C>('0') << std::setw(4) << part3 << '-'
199  << std::setfill<C>('0') << std::setw(4) << part4 << '-'
200  << std::setfill<C>('0') << std::setw(12) << part5 << std::dec;
201 
202  return os;
203  }
204 
212  template<typename C>
213  ::std::basic_istream<C>& operator>>(std::basic_istream<C>& is, Guid& guid)
214  {
215  uint64_t parts[5];
216 
217  C delim;
218 
219  for (int i = 0; i < 4; ++i)
220  {
221  is >> std::hex >> parts[i] >> delim;
222 
223  if (delim != static_cast<C>('-'))
224  return is;
225  }
226 
227  is >> std::hex >> parts[4];
228 
229  guid = Guid((parts[0] << 32) | (parts[1] << 16) | parts[2], (parts[3] << 48) | parts[4]);
230 
231  return is;
232  }
233 }
234 
235 #endif
ignite
Ignite API.
Definition: cache.h:47
ignite::Guid
Global universally unique identifier (GUID).
Definition: guid.h:35
ignite::operator<
bool operator<(const Date &val1, const Date &val2)
Definition: date.cpp:63
ignite::Guid::GetLeastSignificantBits
int64_t GetLeastSignificantBits() const
Returns the least significant 64 bits of this instance.
Definition: guid.cpp:36
ignite::operator>=
bool operator>=(const Date &val1, const Date &val2)
Definition: date.cpp:78
ignite::operator<<
::std::basic_ostream< C > & operator<<(std::basic_ostream< C > &os, const Guid &guid)
Output operator.
Definition: guid.h:187
ignite::operator<=
bool operator<=(const Date &val1, const Date &val2)
Definition: date.cpp:68
ignite::operator>
bool operator>(const Date &val1, const Date &val2)
Definition: date.cpp:73
ignite::operator>>
::std::basic_istream< C > & operator>>(std::basic_istream< C > &is, Guid &guid)
Input operator.
Definition: guid.h:213
ignite::operator!=
bool operator!=(const Date &val1, const Date &val2)
Definition: date.cpp:58
ignite::Guid::GetMostSignificantBits
int64_t GetMostSignificantBits() const
Returns the most significant 64 bits of this instance.
Definition: guid.cpp:31
ignite::operator==
bool operator==(const Date &val1, const Date &val2)
Definition: date.cpp:53