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();
349 struct hash< servus::uint128_t >
351 typedef size_t result_type;
355 hash< uint64_t > forward;
356 return forward( in.
high( )) ^ forward( in.
low( ));
361 #endif // SERVUS_UINT128_H
const uint64_t & low() const
Defines export visibility macros for 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.