| Apache Ignite C++

guid.h
Go to the documentation of this file.
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
23 #ifndef _IGNITE_GUID
24 #define _IGNITE_GUID
25
26 #include <stdint.h>
27 #include <iomanip>
28
29 #include <ignite/common/common.h>
30
31 namespace ignite
32 {
36 class IGNITE_IMPORT_EXPORT Guid
37 {
38 public:
42 Guid();
43
50 Guid(int64_t most, int64_t least);
51
57 int64_t GetMostSignificantBits() const;
58
64 int64_t GetLeastSignificantBits() const;
65
78 int32_t GetVersion() const;
79
92 int32_t GetVariant() const;
93
99 int32_t GetHashCode() const;
100
108 friend bool IGNITE_IMPORT_EXPORT operator== (const Guid& val1, const Guid& val2);
109
116 int64_t Compare(const Guid& other) const;
117
125 friend bool IGNITE_IMPORT_EXPORT operator==(const Guid& val1, const Guid& val2);
126
134 friend bool IGNITE_IMPORT_EXPORT operator!=(const Guid& val1, const Guid& val2);
135
143 friend bool IGNITE_IMPORT_EXPORT operator<(const Guid& val1, const Guid& val2);
144
152 friend bool IGNITE_IMPORT_EXPORT operator<=(const Guid& val1, const Guid& val2);
153
161 friend bool IGNITE_IMPORT_EXPORT operator>(const Guid& val1, const Guid& val2);
162
170 friend bool IGNITE_IMPORT_EXPORT operator>=(const Guid& val1, const Guid& val2);
171
172 private:
174 int64_t most;
175
177 int64_t least;
178 };
179
187 template<typename C>
188 ::std::basic_ostream<C>& operator<<(std::basic_ostream<C>& os, const Guid& guid)
189 {
190 uint32_t part1 = static_cast<uint32_t>(guid.GetMostSignificantBits() >> 32);
191 uint16_t part2 = static_cast<uint16_t>(guid.GetMostSignificantBits() >> 16);
192 uint16_t part3 = static_cast<uint16_t>(guid.GetMostSignificantBits());
193 uint16_t part4 = static_cast<uint16_t>(guid.GetLeastSignificantBits() >> 48);
194 uint64_t part5 = guid.GetLeastSignificantBits() & 0x0000FFFFFFFFFFFFU;
195
196 os << std::hex
197 << std::setfill<C>('0') << std::setw(8) << part1 << '-'
198 << std::setfill<C>('0') << std::setw(4) << part2 << '-'
199 << std::setfill<C>('0') << std::setw(4) << part3 << '-'
200 << std::setfill<C>('0') << std::setw(4) << part4 << '-'
201 << std::setfill<C>('0') << std::setw(12) << part5 << std::dec;
202
203 return os;
204 }
205
213 template<typename C>
214 ::std::basic_istream<C>& operator>>(std::basic_istream<C>& is, Guid& guid)
215 {
216 uint64_t parts[5];
217
218 C delim;
219
220 for (int i = 0; i < 4; ++i)
221 {
222 is >> std::hex >> parts[i] >> delim;
223
224 if (delim != static_cast<C>('-'))
225 return is;
226 }
227
228 is >> std::hex >> parts[4];
229
230 guid = Guid((parts[0] << 32) | (parts[1] << 16) | parts[2], (parts[3] << 48) | parts[4]);
231
232 return is;
233 }
234 }
235
236 #endif
ignite::Guid::GetLeastSignificantBits
int64_t GetLeastSignificantBits() const
Returns the least significant 64 bits of this instance.
Definition: guid.cpp:37
ignite::operator<
bool operator<(const Date &val1, const Date &val2)
Definition: date.cpp:64
ignite::operator!=
bool operator!=(const Date &val1, const Date &val2)
Definition: date.cpp:59
ignite::operator>=
bool operator>=(const Date &val1, const Date &val2)
Definition: date.cpp:79
ignite::operator>
bool operator>(const Date &val1, const Date &val2)
Definition: date.cpp:74
ignite::Guid
Global universally unique identifier (GUID).
Definition: guid.h:36
ignite::operator>>
::std::basic_istream< C > & operator>>(std::basic_istream< C > &is, Guid &guid)
Input operator.
Definition: guid.h:214
ignite::operator==
bool operator==(const Date &val1, const Date &val2)
Definition: date.cpp:54
ignite
Apache Ignite API.
Definition: cache.h:48
ignite::operator<=
bool operator<=(const Date &val1, const Date &val2)
Definition: date.cpp:69