michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef nsURIHashKey_h__ michael@0: #define nsURIHashKey_h__ michael@0: michael@0: #include "pldhash.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIURI.h" michael@0: #include "nsHashKeys.h" michael@0: michael@0: /** michael@0: * Hashtable key class to use with nsTHashtable/nsBaseHashtable michael@0: */ michael@0: class nsURIHashKey : public PLDHashEntryHdr michael@0: { michael@0: public: michael@0: typedef nsIURI* KeyType; michael@0: typedef const nsIURI* KeyTypePointer; michael@0: michael@0: nsURIHashKey(const nsIURI* aKey) : michael@0: mKey(const_cast(aKey)) { MOZ_COUNT_CTOR(nsURIHashKey); } michael@0: nsURIHashKey(const nsURIHashKey& toCopy) : michael@0: mKey(toCopy.mKey) { MOZ_COUNT_CTOR(nsURIHashKey); } michael@0: ~nsURIHashKey() { MOZ_COUNT_DTOR(nsURIHashKey); } michael@0: michael@0: nsIURI* GetKey() const { return mKey; } michael@0: michael@0: bool KeyEquals(const nsIURI* aKey) const { michael@0: bool eq; michael@0: if (NS_SUCCEEDED(mKey->Equals(const_cast(aKey), &eq))) { michael@0: return eq; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: static const nsIURI* KeyToPointer(nsIURI* aKey) { return aKey; } michael@0: static PLDHashNumber HashKey(const nsIURI* aKey) { michael@0: nsAutoCString spec; michael@0: const_cast(aKey)->GetSpec(spec); michael@0: return mozilla::HashString(spec); michael@0: } michael@0: michael@0: enum { ALLOW_MEMMOVE = true }; michael@0: michael@0: protected: michael@0: nsCOMPtr mKey; michael@0: }; michael@0: michael@0: #endif // nsURIHashKey_h__