Bug 1734063 [wpt PR 31107] - [GridNG] Fix rounding of distributed free space to flexi...
[gecko.git] / xpcom / ds / nsPointerHashKeys.h
blob5cf2e8c4d32e564108458d9e764a5344d512d77c
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 typedef T* KeyType;
28 typedef const T* KeyTypePointer;
30 explicit nsPtrHashKey(const T* aKey) : mKey(const_cast<T*>(aKey)) {}
31 nsPtrHashKey(nsPtrHashKey<T>&& aToMove)
32 : PLDHashEntryHdr(std::move(aToMove)), mKey(std::move(aToMove.mKey)) {}
33 ~nsPtrHashKey() = default;
35 KeyType GetKey() const { return mKey; }
36 bool KeyEquals(KeyTypePointer aKey) const { return aKey == mKey; }
38 static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
39 static PLDHashNumber HashKey(KeyTypePointer aKey) {
40 return mozilla::HashGeneric(aKey);
42 enum { ALLOW_MEMMOVE = true };
44 protected:
45 T* MOZ_NON_OWNING_REF mKey;
48 typedef nsPtrHashKey<const void> nsVoidPtrHashKey;
50 #endif // nsPointerHashKeys_h