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.
28 /////////////////////////////////////////////////////////////////////////////
29 // Cache<ieResRef, void*>
34 typedef void (*ReleaseFun
)(void *);
44 char key
[KEYSIZE
]; //not ieResRef!
54 Cache(int nBlockSize
= 10, int nHashTableSize
= 129);
58 inline int GetCount() const
62 inline bool IsEmpty() const
67 void *GetResource(const ieResRef key
);
69 bool SetAt(const ieResRef key
, void *rValue
);
70 // decreases refcount or drops data
71 //if name is supplied it is faster, it will use rValue to validate the request
72 int DecRef(void *rValue
, const ieResRef name
, bool free
);
73 int RefCount(const ieResRef key
) const;
74 void RemoveAll(ReleaseFun fun
);//removes all refcounts
75 void Cleanup(); //removes only zero refcounts
76 void InitHashTable(unsigned int hashSize
, bool bAllocNow
= true);
80 MyAssoc
** m_pHashTable
;
81 unsigned int m_nHashTableSize
;
87 Cache::MyAssoc
* NewAssoc();
88 void FreeAssoc(Cache::MyAssoc
*);
89 Cache::MyAssoc
* GetAssocAt(const ieResRef
) const;
90 Cache::MyAssoc
*GetNextAssoc(Cache::MyAssoc
* rNextPosition
) const;
91 unsigned int MyHashKey(const ieResRef
) const;