BackForwardItemIdentifier.h [plain text]
#pragma once
#include "ProcessIdentifier.h"
#include <wtf/DebugUtilities.h>
#include <wtf/Hasher.h>
#include <wtf/text/StringConcatenateNumbers.h>
namespace WebCore {
struct BackForwardItemIdentifier {
ProcessIdentifier processIdentifier;
enum ItemIdentifierType { };
ObjectIdentifier<ItemIdentifierType> itemIdentifier;
unsigned hash() const;
explicit operator bool() const { return processIdentifier && itemIdentifier; }
template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static Optional<BackForwardItemIdentifier> decode(Decoder&);
String string() const { return makeString(processIdentifier.toUInt64(), '-', itemIdentifier.toUInt64()); }
WEBCORE_EXPORT bool isValid() const;
#if !LOG_DISABLED
const char* logString() const;
#endif
};
#if !LOG_DISABLED
inline const char* BackForwardItemIdentifier::logString() const
{
return debugString(makeString(processIdentifier.toUInt64(), '-', itemIdentifier.toUInt64()));
}
#endif
inline bool operator==(const BackForwardItemIdentifier& a, const BackForwardItemIdentifier& b)
{
return a.processIdentifier == b.processIdentifier && a.itemIdentifier == b.itemIdentifier;
}
inline bool operator!=(const BackForwardItemIdentifier& a, const BackForwardItemIdentifier& b)
{
return !(a == b);
}
template<class Encoder>
void BackForwardItemIdentifier::encode(Encoder& encoder) const
{
encoder << processIdentifier << itemIdentifier;
}
template<class Decoder>
Optional<BackForwardItemIdentifier> BackForwardItemIdentifier::decode(Decoder& decoder)
{
Optional<ProcessIdentifier> processIdentifier;
decoder >> processIdentifier;
if (!processIdentifier)
return WTF::nullopt;
Optional<ObjectIdentifier<ItemIdentifierType>> itemIdentifier;
decoder >> itemIdentifier;
if (!itemIdentifier)
return WTF::nullopt;
BackForwardItemIdentifier result = { WTFMove(*processIdentifier), WTFMove(*itemIdentifier) };
if (!result.isValid())
return WTF::nullopt;
return result;
}
inline unsigned BackForwardItemIdentifier::hash() const
{
return computeHash(processIdentifier.toUInt64(), itemIdentifier.toUInt64());
}
}
namespace WTF {
struct BackForwardItemIdentifierHash {
static unsigned hash(const WebCore::BackForwardItemIdentifier& key) { return key.hash(); }
static bool equal(const WebCore::BackForwardItemIdentifier& a, const WebCore::BackForwardItemIdentifier& b) { return a == b; }
static const bool safeToCompareToEmptyOrDeleted = true;
};
template<> struct HashTraits<WebCore::BackForwardItemIdentifier> : GenericHashTraits<WebCore::BackForwardItemIdentifier> {
static WebCore::BackForwardItemIdentifier emptyValue() { return { }; }
static void constructDeletedValue(WebCore::BackForwardItemIdentifier& slot) { slot.processIdentifier = ObjectIdentifier<WebCore::ProcessIdentifierType>(HashTableDeletedValue); }
static bool isDeletedValue(const WebCore::BackForwardItemIdentifier& slot) { return slot.processIdentifier.toUInt64() == std::numeric_limits<uint64_t>::max(); }
};
template<> struct DefaultHash<WebCore::BackForwardItemIdentifier> : BackForwardItemIdentifierHash { };
}