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  private:
111  int64_t most;
112 
114  int64_t least;
115  };
116 
124  template<typename C>
125  ::std::basic_ostream<C>& operator<<(std::basic_ostream<C>& os, const Guid& guid)
126  {
127  uint32_t part1 = static_cast<uint32_t>(guid.GetMostSignificantBits() >> 32);
128  uint16_t part2 = static_cast<uint16_t>(guid.GetMostSignificantBits() >> 16);
129  uint16_t part3 = static_cast<uint16_t>(guid.GetMostSignificantBits());
130  uint16_t part4 = static_cast<uint16_t>(guid.GetLeastSignificantBits() >> 48);
131  uint64_t part5 = guid.GetLeastSignificantBits() & 0x0000FFFFFFFFFFFFULL;
132 
133  os << std::setfill<C>('0') << std::setw(8) << std::hex << part1 << '-'
134  << std::setfill<C>('0') << std::setw(4) << std::hex << part2 << '-'
135  << std::setfill<C>('0') << std::setw(4) << std::hex << part3 << '-'
136  << std::setfill<C>('0') << std::setw(4) << std::hex << part4 << '-'
137  << std::setfill<C>('0') << std::setw(12) << std::hex << part5;
138 
139  return os;
140  }
141 
149  template<typename C>
150  ::std::basic_istream<C>& operator>>(std::basic_istream<C>& is, Guid& guid)
151  {
152  uint64_t parts[5];
153 
154  C delim;
155 
156  for (int i = 0; i < 4; ++i)
157  {
158  is >> std::hex >> parts[i] >> delim;
159 
160  if (delim != static_cast<C>('-'))
161  return is;
162  }
163 
164  is >> std::hex >> parts[4];
165 
166  guid = Guid((parts[0] << 32) | (parts[1] << 16) | parts[2], (parts[3] << 48) | parts[4]);
167 
168  return is;
169  }
170 }
171 
172 #endif
int64_t GetLeastSignificantBits() const
Returns the least significant 64 bits of this instance.
Definition: guid.cpp:37
Global universally unique identifier (GUID).
Definition: guid.h:36
::std::basic_istream< C > & operator>>(std::basic_istream< C > &is, Guid &guid)
Input operator.
Definition: guid.h:150
bool operator==(const Date &val1, const Date &val2)
Definition: date.cpp:54
Apache Ignite API.
Definition: cache.h:48