21 #ifndef SERVUS_UINT128_H 22 #define SERVUS_UINT128_H 25 #include <servus/types.h> 32 typedef UINT64 uint64_t;
33 #define snprintf _snprintf 41 std::ostream& operator<<(std::ostream& os,
const uint128_t&
id);
54 explicit uint128_t(
const unsigned long long low_ = 0)
81 uint128_t(
const uint64_t high_,
const uint64_t low_)
134 return _high == rhs._high && _low == rhs._low;
142 return _high != rhs._high || _low != rhs._low;
166 if (_high < rhs._high)
168 if (_high > rhs._high)
170 return _low < rhs._low;
178 if (_high > rhs._high)
180 if (_high < rhs._high)
182 return _low > rhs._low;
191 if (_high < rhs._high)
193 if (_high > rhs._high)
195 return _low <= rhs._low;
204 if (_high > rhs._high)
206 if (_high < rhs._high)
208 return _low >= rhs._low;
233 const uint64_t oldLow = _low;
236 _high += rhs._high + 1;
243 const uint64_t&
low()
const {
return _low; }
245 const uint64_t&
high()
const {
return _high; }
247 uint64_t&
low() {
return _low; }
249 uint64_t&
high() {
return _high; }
253 std::stringstream stream;
254 stream << std::hex << _high << _low;
255 const std::string str = stream.str();
256 return str.substr(0, 3) +
".." +
257 str.substr(str.length() - 3, std::string::npos);
265 snprintf(buffer, 34,
"%llx:%llx", ull_t(
high()), ull_t(
low()));
266 return std::string(buffer);
270 template <
class Archive>
283 inline std::ostream& operator<<(std::ostream& os,
const uint128_t&
id)
286 os << std::hex <<
id.low() << std::dec;
288 os << std::hex <<
id.high() <<
':' <<
id.low() << std::dec;
293 inline std::istream& operator>>(std::istream& is,
uint128_t&
id)
306 if (result.
low() < a.
low())
325 if (result.
low() > a.
low())
357 SERVUS_API
uint128_t make_uint128(
const char*
string);
360 inline uint128_t make_uint128(
const std::string&
string)
362 return make_uint128(
string.c_str());
377 typedef size_t result_type;
381 hash<uint64_t> forward;
382 return forward(in.
high()) ^ forward(in.
low());
392 #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.
bool operator!=(const unsigned long long &low_) const
A base type for 128 bit unsigned integer values.
uint128_t & operator=(const int rhs)
Assign an integer value.
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.
bool operator==(const unsigned long long &low_) const
uint128_t & operator=(const uint64_t rhs)
Assign another 64 bit value.