PrincipalHashKey.h (1529B)
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 #ifndef mozilla_PrincipalHashKey_h 8 #define mozilla_PrincipalHashKey_h 9 10 #include "BasePrincipal.h" 11 #include "PLDHashTable.h" 12 #include "nsCOMPtr.h" 13 #include "nsHashKeys.h" 14 15 namespace mozilla { 16 17 class PrincipalHashKey : public PLDHashEntryHdr { 18 public: 19 using KeyType = nsIPrincipal*; 20 using KeyTypePointer = const nsIPrincipal*; 21 22 explicit PrincipalHashKey(const nsIPrincipal* aKey) 23 : mPrincipal(const_cast<nsIPrincipal*>(aKey)) { 24 MOZ_ASSERT(aKey); 25 MOZ_COUNT_CTOR(PrincipalHashKey); 26 } 27 PrincipalHashKey(PrincipalHashKey&& aKey) noexcept 28 : mPrincipal(std::move(aKey.mPrincipal)) { 29 MOZ_COUNT_CTOR(PrincipalHashKey); 30 } 31 32 MOZ_COUNTED_DTOR(PrincipalHashKey) 33 34 nsIPrincipal* GetKey() const { return mPrincipal; } 35 36 bool KeyEquals(const nsIPrincipal* aKey) const { 37 return BasePrincipal::Cast(mPrincipal) 38 ->FastEquals(const_cast<nsIPrincipal*>(aKey)); 39 } 40 41 static const nsIPrincipal* KeyToPointer(const nsIPrincipal* aKey) { 42 return aKey; 43 } 44 static PLDHashNumber HashKey(const nsIPrincipal* aKey) { 45 return aKey->GetHashValue(); 46 } 47 48 enum { ALLOW_MEMMOVE = true }; 49 50 protected: 51 nsCOMPtr<nsIPrincipal> mPrincipal; 52 }; 53 54 } // namespace mozilla 55 56 #endif