12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #ifndef BASE_TOKEN_H_
- #define BASE_TOKEN_H_
- #include <stdint.h>
- #include <string>
- #include <tuple>
- #include "base/base_export.h"
- #include "base/hash/hash.h"
- #include "base/optional.h"
- namespace base {
- class BASE_EXPORT Token {
- public:
-
- constexpr Token() = default;
-
- constexpr Token(uint64_t high, uint64_t low) : high_(high), low_(low) {}
- constexpr Token(const Token&) = default;
- constexpr Token& operator=(const Token&) = default;
- constexpr Token(Token&&) noexcept = default;
- constexpr Token& operator=(Token&&) = default;
-
-
- static Token CreateRandom();
-
- constexpr uint64_t high() const { return high_; }
- constexpr uint64_t low() const { return low_; }
- constexpr bool is_zero() const { return high_ == 0 && low_ == 0; }
- constexpr bool operator==(const Token& other) const {
- return high_ == other.high_ && low_ == other.low_;
- }
- constexpr bool operator!=(const Token& other) const {
- return !(*this == other);
- }
- constexpr bool operator<(const Token& other) const {
- return std::tie(high_, low_) < std::tie(other.high_, other.low_);
- }
-
- std::string ToString() const;
- private:
-
-
-
- uint64_t high_ = 0;
- uint64_t low_ = 0;
- };
- struct TokenHash {
- size_t operator()(const base::Token& token) const {
- return base::HashInts64(token.high(), token.low());
- }
- };
- class Pickle;
- class PickleIterator;
- BASE_EXPORT void WriteTokenToPickle(Pickle* pickle, const Token& token);
- BASE_EXPORT Optional<Token> ReadTokenFromPickle(
- PickleIterator* pickle_iterator);
- }
- #endif
|