netwerk/base/public/nsURIHashKey.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:83015bda8b50
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsURIHashKey_h__
6 #define nsURIHashKey_h__
7
8 #include "pldhash.h"
9 #include "nsCOMPtr.h"
10 #include "nsIURI.h"
11 #include "nsHashKeys.h"
12
13 /**
14 * Hashtable key class to use with nsTHashtable/nsBaseHashtable
15 */
16 class nsURIHashKey : public PLDHashEntryHdr
17 {
18 public:
19 typedef nsIURI* KeyType;
20 typedef const nsIURI* KeyTypePointer;
21
22 nsURIHashKey(const nsIURI* aKey) :
23 mKey(const_cast<nsIURI*>(aKey)) { MOZ_COUNT_CTOR(nsURIHashKey); }
24 nsURIHashKey(const nsURIHashKey& toCopy) :
25 mKey(toCopy.mKey) { MOZ_COUNT_CTOR(nsURIHashKey); }
26 ~nsURIHashKey() { MOZ_COUNT_DTOR(nsURIHashKey); }
27
28 nsIURI* GetKey() const { return mKey; }
29
30 bool KeyEquals(const nsIURI* aKey) const {
31 bool eq;
32 if (NS_SUCCEEDED(mKey->Equals(const_cast<nsIURI*>(aKey), &eq))) {
33 return eq;
34 }
35 return false;
36 }
37
38 static const nsIURI* KeyToPointer(nsIURI* aKey) { return aKey; }
39 static PLDHashNumber HashKey(const nsIURI* aKey) {
40 nsAutoCString spec;
41 const_cast<nsIURI*>(aKey)->GetSpec(spec);
42 return mozilla::HashString(spec);
43 }
44
45 enum { ALLOW_MEMMOVE = true };
46
47 protected:
48 nsCOMPtr<nsIURI> mKey;
49 };
50
51 #endif // nsURIHashKey_h__

mercurial