]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCache.h
Angus's insetref-patch and a small fix.
[lyx.git] / src / graphics / GraphicsCache.h
1 // -*- C++ -*-
2 /* This file is part of
3  * =================================================
4  * 
5  *          LyX, The Document Processor
6  *          Copyright 1995 Matthias Ettrich.
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  *          This file Copyright 2000 Baruch Even
10  * ================================================= */
11
12 #ifndef GRAPHICSCACHE_H
13 #define GRAPHICSCACHE_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include <map>
20
21 #include "LString.h"
22 #include "GraphicsCacheItem.h"
23 #include "support/utility.hpp"
24
25 /** GraphicsCache is the manager of the image cache, it is responsible to
26     create the GraphicsCacheItem's and maintain them.
27     
28     GraphicsCache is a singleton class, there should be only one instance of
29     it at any moment.
30 */
31 class GraphicsCache : public noncopyable {
32 public:
33     /// Get the instance of the class.
34     static GraphicsCache * getInstance();
35
36     /// Add a file to the cache.
37     GraphicsCacheItem * addFile(string const & filename);
38
39 private:
40     /// Remove a cache item if it's count has gone to zero.
41     void removeFile(string const & filename);
42     
43     /// Private c-tor so we can control how many objects are instantiated.
44     GraphicsCache() {}
45
46     /// Private d-tor so that no-one will destroy us.
47     ~GraphicsCache();
48
49     /// Holder of the single instance of the class.
50     static GraphicsCache * singleton;
51     ///
52     typedef std::map<string, GraphicsCacheItem *> CacheType;
53     ///
54     CacheType cache;
55
56         // We need this so that an Item can tell the cache that it should be
57         // deleted. (to call removeFile).
58         // It also helps removing a warning gcc emits.
59         friend class GraphicsCacheItem;
60 };
61 #endif