#ifndef SessionID_h
#define SessionID_h
#include <wtf/HashFunctions.h>
#include <wtf/HashTraits.h>
namespace WebCore {
class SessionID {
public:
SessionID()
: SessionID(emptySessionID()) { }
explicit SessionID(uint64_t sessionID)
: m_sessionID(sessionID) { }
bool isValid() const { return *this != emptySessionID(); }
bool isEphemeral() const { return *this != defaultSessionID(); }
uint64_t sessionID() const { return m_sessionID; }
bool operator==(SessionID sessionID) const { return m_sessionID == sessionID.m_sessionID; }
bool operator!=(SessionID sessionID) const { return m_sessionID != sessionID.m_sessionID; }
static SessionID emptySessionID() { return SessionID(0); }
static SessionID defaultSessionID() { return SessionID(1); }
static SessionID legacyPrivateSessionID() { return SessionID(2); }
private:
uint64_t m_sessionID;
};
}
namespace WTF {
struct SessionIDHash {
static unsigned hash(const WebCore::SessionID& p) { return (unsigned)p.sessionID(); }
static bool equal(const WebCore::SessionID& a, const WebCore::SessionID& b) { return a == b; }
static const bool safeToCompareToEmptyOrDeleted = true;
};
template<> struct HashTraits<WebCore::SessionID> : GenericHashTraits<WebCore::SessionID> {
static const uint64_t deletedValueIdentifier = 0xffffffffffffffff;
static const bool needsDestruction = false;
static WebCore::SessionID emptyValue() { return WebCore::SessionID::emptySessionID(); }
static void constructDeletedValue(WebCore::SessionID& slot) { slot = WebCore::SessionID(deletedValueIdentifier); }
static bool isDeletedValue(const WebCore::SessionID& slot) { return slot == WebCore::SessionID(deletedValueIdentifier); }
};
template<> struct DefaultHash<WebCore::SessionID> {
typedef SessionIDHash Hash;
};
}
#endif // SessionID_h