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 16 /** 17 * hashkey wrapper using T* KeyType 18 * 19 * @see nsTHashtable::EntryType for specification 20 */ 21 template<class T> 22 class nsPtrHashKey : public PLDHashEntryHdr 23 { 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(const nsPtrHashKey<T> & aToCopy)29 nsPtrHashKey(const nsPtrHashKey<T>& aToCopy) : mKey(aToCopy.mKey) {} ~nsPtrHashKey()30 ~nsPtrHashKey() {} 31 GetKey()32 KeyType GetKey() const { return mKey; } KeyEquals(KeyTypePointer aKey)33 bool KeyEquals(KeyTypePointer aKey) const { return aKey == mKey; } 34 KeyToPointer(KeyType aKey)35 static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; } HashKey(KeyTypePointer aKey)36 static PLDHashNumber HashKey(KeyTypePointer aKey) 37 { 38 return NS_PTR_TO_UINT32(aKey) >> 2; 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