1/*
2
3"Special" Cache.
4
5Copyright (c) 2003 OpenBeOS.
6
7Author:
8	Michael Pfeiffer
9
10Permission is hereby granted, free of charge, to any person obtaining a copy of
11this software and associated documentation files (the "Software"), to deal in
12the Software without restriction, including without limitation the rights to
13use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14of the Software, and to permit persons to whom the Software is furnished to do
15so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26THE SOFTWARE.
27
28*/
29
30#ifndef _CACHE_H
31#define _CACHE_H
32
33#include "PrintUtils.h"
34
35class CacheItem;
36
37// CacheItemDescription
38class CIDescription {
39public:
40	CIDescription() {};
41	virtual ~CIDescription() {};
42
43	virtual CacheItem* NewItem(int id) { return NULL; }
44};
45
46class CacheItem {
47public:
48	CacheItem() {}
49	virtual ~CacheItem() {}
50
51	virtual bool Equals(CIDescription* desc) const = 0;
52	virtual CacheItem* Reference() { return this; }
53};
54
55class Cache {
56public:
57	Cache();
58	virtual ~Cache() {};
59
60	void NextPass();
61
62	// returns the CacheItem at "NextID", returns NULL on error
63	CacheItem* Find(CIDescription* desc);
64	void MakeEmpty() { fCache.MakeEmpty(); }
65	int32 CountItems() const { return fCache.CountItems(); }
66	CacheItem* ItemAt(int32 i) const { return fCache.ItemAt(i); }
67
68private:
69	int8  fPass;
70	int32 fNextID;
71	TList<CacheItem> fCache;
72};
73
74#endif
75