26 #ifndef SBFIXEDINTERFACECACHE_H_
27 #define SBFIXEDINTERFACECACHE_H_
31 #include <nsAutoLock.h>
45 template <
class KeyClass,
class Interface>
49 typedef typename KeyClass::KeyType
KeyType;
59 NS_ASSERTION(aSize,
"sbFixedInterfaceCache must have a size > 0");
61 mKeys.AppendElements(mSize);
62 mCacheMap.Init(aSize);
69 for (PRUint32 index = 0; index < mSize; ++index)
71 Interface * obj = nsnull;
72 mCacheMap.Get(mKeys[index], &obj);
88 Interface * oldObject = nsnull;
89 nsString
const & oldKey = mKeys[mCurrent];
90 if (!oldKey.IsEmpty() && mCacheMap.Get(oldKey, &oldObject) && oldObject) {
91 NS_RELEASE(oldObject);
92 mCacheMap.Remove(oldKey);
95 mKeys[mCurrent] = aKey;
96 mCacheMap.Put(aKey, aValue);
106 Interface * obj = nsnull;
108 mCacheMap.Get(aKey, &obj);
114 nsTArray<nsString> mKeys;
116 nsDataHashtable<KeyClass, Interface*> mCacheMap;
118 PRUint32
const mSize;
Interface * Get(KeyType aKey) const
KeyClass::KeyType KeyType
void Put(KeyType aKey, Interface *aValue)
sbFixedInterfaceCache(PRUint32 aSize)