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/. */ 6 7 /* Definitions for nsPtrHashKey<T> and nsVoidPtrHashKey. */ 8 9 #ifndef nsPointerHashKeys_h 10 #define nsPointerHashKeys_h 11 12 #include "nscore.h" 13 14 #include "mozilla/Attributes.h" 15 #include "mozilla/HashFunctions.h" 16 17 /** 18 * hashkey wrapper using T* KeyType 19 * 20 * @see nsTHashtable::EntryType for specification 21 */ 22 template <class T> 23 class nsPtrHashKey : public PLDHashEntryHdr { 24 public: 25 typedef T* KeyType; 26 typedef const T* KeyTypePointer; 27 nsPtrHashKey(const T * aKey)28 explicit nsPtrHashKey(const T* aKey) : mKey(const_cast<T*>(aKey)) {} nsPtrHashKey(nsPtrHashKey<T> && aToMove)29 nsPtrHashKey(nsPtrHashKey<T>&& aToMove) 30 : PLDHashEntryHdr(std::move(aToMove)), mKey(std::move(aToMove.mKey)) {} 31 ~nsPtrHashKey() = default; 32 GetKey()33 KeyType GetKey() const { return mKey; } KeyEquals(KeyTypePointer aKey)34 bool KeyEquals(KeyTypePointer aKey) const { return aKey == mKey; } 35 KeyToPointer(KeyType aKey)36 static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; } HashKey(KeyTypePointer aKey)37 static PLDHashNumber HashKey(KeyTypePointer aKey) { 38 return mozilla::HashGeneric(aKey); 39 } 40 enum { ALLOW_MEMMOVE = true }; 41 42 protected: 43 T* MOZ_NON_OWNING_REF mKey; 44 }; 45 46 typedef nsPtrHashKey<const void> nsVoidPtrHashKey; 47 48 #endif // nsPointerHashKeys_h 49