1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 |Avenger|
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 typedef void (*ReleaseFun
)(void *);
40 char key
[KEYSIZE
]; //not ieResRef!
50 Cache(int nBlockSize
= 10, int nHashTableSize
= 129);
54 inline int GetCount() const
58 inline bool IsEmpty() const
63 void *GetResource(const ieResRef key
) const;
65 bool SetAt(const ieResRef key
, void *rValue
);
66 // decreases refcount or drops data
67 //if name is supplied it is faster, it will use rValue to validate the request
68 int DecRef(void *rValue
, const ieResRef name
, bool free
);
69 int RefCount(const ieResRef key
) const;
70 void RemoveAll(ReleaseFun fun
);//removes all refcounts
71 void Cleanup(); //removes only zero refcounts
72 void InitHashTable(unsigned int hashSize
, bool bAllocNow
= true);
76 MyAssoc
** m_pHashTable
;
77 unsigned int m_nHashTableSize
;
83 Cache::MyAssoc
* NewAssoc();
84 void FreeAssoc(Cache::MyAssoc
*);
85 Cache::MyAssoc
* GetAssocAt(const ieResRef
) const;
86 Cache::MyAssoc
*GetNextAssoc(Cache::MyAssoc
* rNextPosition
) const;
87 unsigned int MyHashKey(const ieResRef
) const;