netwerk/base/public/nsURIHashKey.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/base/public/nsURIHashKey.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +#ifndef nsURIHashKey_h__
     1.9 +#define nsURIHashKey_h__
    1.10 +
    1.11 +#include "pldhash.h"
    1.12 +#include "nsCOMPtr.h"
    1.13 +#include "nsIURI.h"
    1.14 +#include "nsHashKeys.h"
    1.15 +
    1.16 +/**
    1.17 + * Hashtable key class to use with nsTHashtable/nsBaseHashtable
    1.18 + */
    1.19 +class nsURIHashKey : public PLDHashEntryHdr
    1.20 +{
    1.21 +public:
    1.22 +    typedef nsIURI* KeyType;
    1.23 +    typedef const nsIURI* KeyTypePointer;
    1.24 +
    1.25 +    nsURIHashKey(const nsIURI* aKey) :
    1.26 +        mKey(const_cast<nsIURI*>(aKey)) { MOZ_COUNT_CTOR(nsURIHashKey); }
    1.27 +    nsURIHashKey(const nsURIHashKey& toCopy) :
    1.28 +        mKey(toCopy.mKey) { MOZ_COUNT_CTOR(nsURIHashKey); }
    1.29 +    ~nsURIHashKey() { MOZ_COUNT_DTOR(nsURIHashKey); }
    1.30 +
    1.31 +    nsIURI* GetKey() const { return mKey; }
    1.32 +
    1.33 +    bool KeyEquals(const nsIURI* aKey) const {
    1.34 +        bool eq;
    1.35 +        if (NS_SUCCEEDED(mKey->Equals(const_cast<nsIURI*>(aKey), &eq))) {
    1.36 +            return eq;
    1.37 +        }
    1.38 +        return false;
    1.39 +    }
    1.40 +
    1.41 +    static const nsIURI* KeyToPointer(nsIURI* aKey) { return aKey; }
    1.42 +    static PLDHashNumber HashKey(const nsIURI* aKey) {
    1.43 +        nsAutoCString spec;
    1.44 +        const_cast<nsIURI*>(aKey)->GetSpec(spec);
    1.45 +        return mozilla::HashString(spec);
    1.46 +    }
    1.47 +    
    1.48 +    enum { ALLOW_MEMMOVE = true };
    1.49 +
    1.50 +protected:
    1.51 +    nsCOMPtr<nsIURI> mKey;
    1.52 +};
    1.53 +
    1.54 +#endif // nsURIHashKey_h__

mercurial