20 #ifndef LUNCHBOX_UINT128_H
21 #define LUNCHBOX_UINT128_H
24 #include <lunchbox/compiler.h>
31 typedef UINT64 uint64_t;
39 std::ostream&
operator << ( std::ostream& os,
const uint128_t&
id );
53 explicit uint128_t(
const unsigned long long low_ = 0 )
54 : _high( 0 ), _low( low_ ) {}
60 explicit uint128_t(
const unsigned long low_ ) : _high( 0 ), _low( low_ ) {}
66 explicit uint128_t(
const int low_ ) : _high( 0 ), _low( low_ ) {}
68 #ifdef LUNCHBOX_USE_V1_API
77 LUNCHBOX_API
explicit uint128_t(
const bool generate ) LB_DEPRECATED;
84 uint128_t(
const uint64_t high_,
const uint64_t low_ )
85 : _high( high_ ), _low( low_ ) {}
92 : _high( 0 ), _low( 0 ) { *
this = string; }
133 {
return _high == rhs._high && _low == rhs._low; }
140 {
return _high != rhs._high || _low != rhs._low; }
162 if( _high < rhs._high )
164 if( _high > rhs._high )
166 return _low < rhs._low;
175 if( _high > rhs._high )
177 if( _high < rhs._high )
179 return _low > rhs._low;
189 if( _high < rhs._high )
191 if( _high > rhs._high )
193 return _low <= rhs._low;
203 if( _high > rhs._high )
205 if( _high < rhs._high )
207 return _low >= rhs._low;
232 const uint64_t oldLow = _low;
235 _high += rhs._high + 1;
242 const uint64_t&
low()
const {
return _low; }
244 const uint64_t&
high()
const {
return _high; }
247 uint64_t&
low() {
return _low; }
249 uint64_t&
high() {
return _high; }
254 std::stringstream stream;
255 stream << std::hex << _high << _low;
256 const std::string str = stream.str();
257 return str.substr( 0, 3 ) +
".." +
258 str.substr( str.length() - 3, std::string::npos );
264 std::stringstream stream;
270 template<
class Archive >
277 #ifdef LUNCHBOX_USE_V1_API
281 bool isGenerated() const LB_DEPRECATED {
return high() != 0; }
284 static LUNCHBOX_API
const uint128_t ZERO LB_DEPRECATED;
296 os << std::hex <<
id.low() << std::dec;
298 os << std::hex <<
id.high() <<
':' <<
id.low() << std::dec;
316 if( result.
low() < a.
low( ))
335 if( result.
low() > a.
low( ))
368 LUNCHBOX_API uint128_t
make_uint128(
const char*
string );
378 #endif // LUNCHBOX_UINT128_H
void serialize(Archive &ar, const unsigned int)
Serialize this object to a boost archive.
Defines export visibility macros for Lunchbox.
uint128_t & operator--()
Decrement the value.
uint128_t operator|(const lunchbox::uint128_t &a, const lunchbox::uint128_t &b)
Bitwise or operation on two 128 bit values.
uint128_t(const unsigned long long low_=0)
Construct a new 128 bit integer with a default value.
uint128_t operator&(const lunchbox::uint128_t &a, const lunchbox::uint128_t &b)
Bitwise and operation on two 128 bit values.
const uint64_t & high() const
uint128_t & operator+=(const lunchbox::uint128_t &rhs)
Add value and return the new value.
bool operator>(const lunchbox::uint128_t &rhs) const
uint128_t & operator=(const lunchbox::uint128_t &rhs)
Assign another 128 bit value.
uint128_t(const uint64_t high_, const uint64_t low_)
Construct a new 128 bit integer with default values.
bool operator<(const lunchbox::uint128_t &rhs) const
bool operator<=(const lunchbox::uint128_t &rhs) const
const uint64_t & low() const
bool operator==(const lunchbox::uint128_t &rhs) const
std::ostream & operator<<(std::ostream &os, const Array< T > &array)
Pretty-print all members of the array.
std::string getShortString() const
A base type for 128 bit unsigned integer values.
bool operator!=(const lunchbox::uint128_t &rhs) const
uint128_t(const std::string &string)
Construct a new 128 bit integer from a string representation.
std::string getString() const
uint128_t operator+(const lunchbox::uint128_t &a, const uint64_t &b)
Add a 64 bit value to a 128 bit value.
uint128_t(const int low_)
Construct a new 128 bit integer with a default value.
std::istream & operator>>(std::istream &is, uint128_t &id)
istream operator for 128 bit unsigned integers.
uint128_t(const unsigned long low_)
Construct a new 128 bit integer with a default value.
LUNCHBOX_API uint128_t make_uint128(const char *string)
Create a 128 bit integer based on a string.
bool operator>=(const lunchbox::uint128_t &rhs) const
uint128_t operator-(const lunchbox::uint128_t &a, const uint64_t &b)
Subtract a 64 bit value from a 128 bit value.
uint128_t & operator++()
Increment the value.
LUNCHBOX_API uint128_t make_UUID()
Construct a new 128 bit integer with a generated universally unique identifier.