xpcom/glue/nsClassHashtable.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsClassHashtable_h__
michael@0 7 #define nsClassHashtable_h__
michael@0 8
michael@0 9 #include "nsBaseHashtable.h"
michael@0 10 #include "nsHashKeys.h"
michael@0 11 #include "nsAutoPtr.h"
michael@0 12
michael@0 13 /**
michael@0 14 * templated hashtable class maps keys to C++ object pointers.
michael@0 15 * See nsBaseHashtable for complete declaration.
michael@0 16 * @param KeyClass a wrapper-class for the hashtable key, see nsHashKeys.h
michael@0 17 * for a complete specification.
michael@0 18 * @param Class the class-type being wrapped
michael@0 19 * @see nsInterfaceHashtable, nsClassHashtable
michael@0 20 */
michael@0 21 template<class KeyClass,class T>
michael@0 22 class nsClassHashtable :
michael@0 23 public nsBaseHashtable< KeyClass, nsAutoPtr<T>, T* >
michael@0 24 {
michael@0 25 public:
michael@0 26 typedef typename KeyClass::KeyType KeyType;
michael@0 27 typedef T* UserDataType;
michael@0 28 typedef nsBaseHashtable< KeyClass, nsAutoPtr<T>, T* > base_type;
michael@0 29
michael@0 30 nsClassHashtable()
michael@0 31 {
michael@0 32 }
michael@0 33 explicit nsClassHashtable(uint32_t aInitSize)
michael@0 34 : nsBaseHashtable<KeyClass,nsAutoPtr<T>,T*>(aInitSize)
michael@0 35 {
michael@0 36 }
michael@0 37
michael@0 38 /**
michael@0 39 * @copydoc nsBaseHashtable::Get
michael@0 40 * @param pData if the key doesn't exist, pData will be set to nullptr.
michael@0 41 */
michael@0 42 bool Get(KeyType aKey, UserDataType* pData) const;
michael@0 43
michael@0 44 /**
michael@0 45 * @copydoc nsBaseHashtable::Get
michael@0 46 * @returns nullptr if the key is not present.
michael@0 47 */
michael@0 48 UserDataType Get(KeyType aKey) const;
michael@0 49
michael@0 50 /**
michael@0 51 * Remove the entry for the given key from the hashtable and return it in
michael@0 52 * aOut. If the key is not in the hashtable, aOut's pointer is set to
michael@0 53 * nullptr.
michael@0 54 *
michael@0 55 * Normally, an entry is deleted when it's removed from an nsClassHashtable,
michael@0 56 * but this function transfers ownership of the entry back to the caller
michael@0 57 * through aOut -- the entry will be deleted when aOut goes out of scope.
michael@0 58 *
michael@0 59 * @param aKey the key to get and remove from the hashtable
michael@0 60 */
michael@0 61 void RemoveAndForget(KeyType aKey, nsAutoPtr<T> &aOut);
michael@0 62 };
michael@0 63
michael@0 64 //
michael@0 65 // nsClassHashtable definitions
michael@0 66 //
michael@0 67
michael@0 68 template<class KeyClass,class T>
michael@0 69 bool
michael@0 70 nsClassHashtable<KeyClass,T>::Get(KeyType aKey, T** retVal) const
michael@0 71 {
michael@0 72 typename base_type::EntryType* ent = this->GetEntry(aKey);
michael@0 73
michael@0 74 if (ent)
michael@0 75 {
michael@0 76 if (retVal)
michael@0 77 *retVal = ent->mData;
michael@0 78
michael@0 79 return true;
michael@0 80 }
michael@0 81
michael@0 82 if (retVal)
michael@0 83 *retVal = nullptr;
michael@0 84
michael@0 85 return false;
michael@0 86 }
michael@0 87
michael@0 88 template<class KeyClass,class T>
michael@0 89 T*
michael@0 90 nsClassHashtable<KeyClass,T>::Get(KeyType aKey) const
michael@0 91 {
michael@0 92 typename base_type::EntryType* ent = this->GetEntry(aKey);
michael@0 93
michael@0 94 if (!ent)
michael@0 95 return nullptr;
michael@0 96
michael@0 97 return ent->mData;
michael@0 98 }
michael@0 99
michael@0 100 template<class KeyClass,class T>
michael@0 101 void
michael@0 102 nsClassHashtable<KeyClass,T>::RemoveAndForget(KeyType aKey, nsAutoPtr<T> &aOut)
michael@0 103 {
michael@0 104 aOut = nullptr;
michael@0 105 nsAutoPtr<T> ptr;
michael@0 106
michael@0 107 typename base_type::EntryType *ent = this->GetEntry(aKey);
michael@0 108 if (!ent)
michael@0 109 return;
michael@0 110
michael@0 111 // Transfer ownership from ent->mData into aOut.
michael@0 112 aOut = ent->mData;
michael@0 113
michael@0 114 this->Remove(aKey);
michael@0 115 }
michael@0 116
michael@0 117 #endif // nsClassHashtable_h__

mercurial