21 #ifndef SERVUS_UINT128_H
22 #define SERVUS_UINT128_H
31 typedef UINT64 uint64_t;
39 std::ostream& operator << ( std::ostream& os,
const uint128_t&
id );
52 explicit uint128_t(
const unsigned long long low_ = 0 )
53 : _high( 0 ), _low( low_ ) {}
58 explicit uint128_t(
const unsigned long low_ ) : _high( 0 ), _low( low_ ) {}
63 explicit uint128_t(
const int low_ ) : _high( 0 ), _low( low_ ) {}
68 uint128_t(
const uint64_t high_,
const uint64_t low_ )
69 : _high( high_ ), _low( low_ ) {}
75 : _high( 0 ), _low( 0 ) { *
this = string; }
114 {
return _high == rhs._high && _low == rhs._low; }
120 {
return _high != rhs._high || _low != rhs._low; }
139 if( _high < rhs._high )
141 if( _high > rhs._high )
143 return _low < rhs._low;
151 if( _high > rhs._high )
153 if( _high < rhs._high )
155 return _low > rhs._low;
164 if( _high < rhs._high )
166 if( _high > rhs._high )
168 return _low <= rhs._low;
177 if( _high > rhs._high )
179 if( _high < rhs._high )
181 return _low >= rhs._low;
206 const uint64_t oldLow = _low;
209 _high += rhs._high + 1;
216 const uint64_t&
low()
const {
return _low; }
218 const uint64_t&
high()
const {
return _high; }
221 uint64_t&
low() {
return _low; }
223 uint64_t&
high() {
return _high; }
228 std::stringstream stream;
229 stream << std::hex << _high << _low;
230 const std::string str = stream.str();
231 return str.substr( 0, 3 ) +
".." +
232 str.substr( str.length() - 3, std::string::npos );
238 std::stringstream stream;
244 template<
class Archive >
257 inline std::ostream& operator << ( std::ostream& os,
const uint128_t&
id )
260 os << std::hex <<
id.low() << std::dec;
262 os << std::hex <<
id.high() <<
':' <<
id.low() << std::dec;
267 inline std::istream& operator >> ( std::istream& is, uint128_t&
id )
278 uint128_t result = a;
280 if( result.low() < a.
low( ))
289 uint128_t result = a;
297 uint128_t result = a;
299 if( result.low() > a.
low( ))
308 uint128_t result = a;
310 result.low() &= b.
low();
318 uint128_t result = a;
320 result.low() |= b.
low();
331 SERVUS_API uint128_t make_uint128(
const char*
string );
334 inline uint128_t make_uint128(
const std::string&
string )
335 {
return make_uint128(
string.c_str( )); }
341 SERVUS_API uint128_t make_UUID();
345 #if __cplusplus >= 201103L || _MSC_VER > 1500
347 # define SERVUS_HASH_NAMESPACE_OPEN namespace std {
348 # define SERVUS_HASH_NAMESPACE_CLOSE }
349 # define SERVUS_HASH_USE_STRUCT
350 # include <functional>
351 #elif defined __clang__ || defined __xlC__ || defined __GNUC__
353 # define SERVUS_HASH_NAMESPACE_OPEN namespace std { namespace tr1 {
354 # define SERVUS_HASH_NAMESPACE_CLOSE }}
355 # define SERVUS_HASH_USE_STRUCT
356 # include <tr1/unordered_set>
357 #elif _MSC_VER < 1600
359 # define SERVUS_HASH_NAMESPACE_OPEN namespace std {
360 # define SERVUS_HASH_NAMESPACE_CLOSE }
361 # define SERVUS_HASH_USE_FUNCTORS
364 # define SERVUS_HASH_NONE
367 #ifndef SERVUS_HASH_NONE
368 SERVUS_HASH_NAMESPACE_OPEN
369 # ifdef SERVUS_HASH_USE_STRUCT
371 template<>
struct hash<
servus::uint128_t >
373 typedef size_t result_type;
377 hash< uint64_t > forward;
378 return forward( in.
high( )) ^ forward( in.
low( ));
382 # else // SERVUS_HASH_USE_FUNCTORS
384 template<>
inline size_t hash_compare< servus::uint128_t >::operator()
387 return static_cast< size_t >( key.high() ^ key.low( ));
391 {
return static_cast< size_t >( key.
high() ^ key.
low( )); }
394 SERVUS_HASH_NAMESPACE_CLOSE
396 #endif // SERVUS_HASH
397 #endif // SERVUS_UINT128_H
const uint64_t & low() const
Defines export visibility macros for library Servus.
uint128_t & operator++()
Increment the value.
std::string getString() const
bool operator==(const servus::uint128_t &rhs) const
uint128_t(const int low_)
Construct a new 128 bit integer with a default value.
void serialize(Archive &ar, const unsigned int)
Serialize this object to a boost archive.
uint128_t & operator--()
Decrement the value.
uint128_t & operator+=(const servus::uint128_t &rhs)
Add value and return the new value.
bool operator<(const servus::uint128_t &rhs) const
bool operator>=(const servus::uint128_t &rhs) const
bool operator!=(const servus::uint128_t &rhs) const
const uint64_t & high() const
std::string getShortString() const
bool operator>(const servus::uint128_t &rhs) const
uint128_t(const std::string &string)
Construct a new 128 bit integer from a string representation.
bool operator<=(const servus::uint128_t &rhs) const
uint128_t(const unsigned long long low_=0)
Construct a new 128 bit integer with a default value.
uint128_t(const unsigned long low_)
Construct a new 128 bit integer with a default value.
A base type for 128 bit unsigned integer values.
uint128_t(const uint64_t high_, const uint64_t low_)
Construct a new 128 bit integer with default values.
uint128_t & operator=(const servus::uint128_t &rhs)
Assign another 128 bit value.