Bug 1879774 [wpt PR 44524] - WebKit export: Implement field-sizing support for input...
[gecko.git] / xpcom / ds / nsPointerHashKeys.h
blob0a4af3b2f87c0d0ca3750884f8d48a3b40c4af5a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* Definitions for nsPtrHashKey<T> and nsVoidPtrHashKey. */
9 #ifndef nsPointerHashKeys_h
10 #define nsPointerHashKeys_h
12 #include "nscore.h"
14 #include "mozilla/Attributes.h"
15 #include "mozilla/HashFunctions.h"
17 #include "PLDHashTable.h"
19 /**
20 * hashkey wrapper using T* KeyType
22 * @see nsTHashtable::EntryType for specification
24 template <class T>
25 class nsPtrHashKey : public PLDHashEntryHdr {
26 public:
27 using KeyType = T*;
28 using KeyTypePointer = const T*;
30 explicit nsPtrHashKey(const T* aKey) : mKey(const_cast<T*>(aKey)) {}
31 nsPtrHashKey(nsPtrHashKey&& aToMove) = default;
32 ~nsPtrHashKey() = default;
34 KeyType GetKey() const { return mKey; }
35 bool KeyEquals(KeyTypePointer aKey) const { return aKey == mKey; }
37 static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
38 static PLDHashNumber HashKey(KeyTypePointer aKey) {
39 return mozilla::HashGeneric(aKey);
41 enum { ALLOW_MEMMOVE = true };
43 protected:
44 T* MOZ_NON_OWNING_REF mKey;
47 using nsVoidPtrHashKey = nsPtrHashKey<const void>;
49 #endif // nsPointerHashKeys_h