SetupWishCore: fixed table lookup being out of bounds for the wisest pcs
[gemrb.git] / gemrb / core / LRUCache.h
blob31add80924591c1e479767d5aeceaea4820039d4
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2007
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.
21 #ifndef LRUCACHE_H
22 #define LRUCACHE_H
24 #include "exports.h"
26 #include "Variables.h"
28 struct VarEntry;
30 class GEM_EXPORT LRUCache {
31 public:
32 LRUCache();
33 ~LRUCache();
35 // set value, overwriting any previous entry
36 void SetAt(const char* key, void* value);
37 bool Lookup(const char* key, void*& value) const;
38 bool Touch(const char* key);
39 bool Remove(const char* key);
41 int GetCount() const;
43 // return n-th LRU entry. key remains owned by LRUCache.
44 // (n = 0 is least recently used, n = 1 the next least recently used,
45 // etc...)
46 bool getLRU(unsigned int n, const char*& key, void*& value) const;
48 private:
49 // internal storage
50 Variables v;
51 VarEntry* head;
52 VarEntry* tail;
54 void removeFromList(VarEntry* e);
59 #endif