1//========================================================================
2//
3// PopplerCache.h
4//
5// This file is licensed under the GPLv2 or later
6//
7// Copyright (C) 2009 Koji Otani <sho@bbr.jp>
8// Copyright (C) 2009, 2010 Albert Astals Cid <aacid@kde.org>
9// Copyright (C) 2010 Carlos Garcia Campos <carlosgc@gnome.org>
10//
11//========================================================================
12
13#ifndef POPPLER_CACHE_H
14#define POPPLER_CACHE_H
15
16#include "Object.h"
17
18class PopplerCacheItem
19{
20 public:
21 virtual ~PopplerCacheItem();
22};
23
24class PopplerCacheKey
25{
26 public:
27 virtual ~PopplerCacheKey();
28 virtual bool operator==(const PopplerCacheKey &key) const = 0;
29};
30
31class PopplerCache
32{
33 public:
34 PopplerCache(int cacheSizeA);
35 ~PopplerCache();
36
37 /* The item returned is owned by the cache */
38 PopplerCacheItem *lookup(const PopplerCacheKey &key);
39
40 /* The key and item pointers ownership is taken by the cache */
41 void put(PopplerCacheKey *key, PopplerCacheItem *item);
42
43 /* The max size of the cache */
44 int size();
45
46 /* The number of items in the cache */
47 int numberOfItems();
48
49 /* The n-th item in the cache */
50 PopplerCacheItem *item(int index);
51
52 /* The n-th key in the cache */
53 PopplerCacheKey *key(int index);
54
55 private:
56 PopplerCache(const PopplerCache &cache); // not allowed
57
58 PopplerCacheKey **keys;
59 PopplerCacheItem **items;
60 int lastValidCacheIndex;
61 int cacheSize;
62};
63
64class PopplerObjectCache
65{
66 public:
67 PopplerObjectCache (int cacheSizeA, XRef *xrefA);
68 ~PopplerObjectCache();
69
70 Object *put(const Ref &ref);
71 Object *lookup(const Ref &ref, Object *obj);
72
73 private:
74 XRef *xref;
75 PopplerCache *cache;
76};
77
78#endif
79