]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCache.h
Cleaned up the GraphicsCache mechanism, made it use shared_ptr for cleanliness
[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 <boost/utility.hpp>
24 #include <boost/smart_ptr.hpp>
25
26 class GraphicsCacheItem;
27
28 /** GraphicsCache is the manager of the image cache.
29     It is responsible of create the GraphicsCacheItem's and maintain them.
30     
31     GraphicsCache is a singleton class, there should be only one instance of
32     it at any moment.
33 */
34 class GraphicsCache : public noncopyable {
35 public:
36         /// Get the instance of the class.
37         static GraphicsCache * getInstance();
38
39         typedef boost::shared_ptr<GraphicsCacheItem> shared_ptr_item;
40
41         /// Add a file to the cache.
42         shared_ptr_item addFile(string const & filename);
43
44 private:
45         /// Remove a cache item if it's count has gone to zero.
46         void removeFile(string const & filename);
47         
48         /// Private c-tor so we can control how many objects are instantiated.
49         GraphicsCache() {}
50         
51         /// Private d-tor so that no-one will destroy us.
52         ~GraphicsCache();
53         
54         /// Holder of the single instance of the class.
55         static GraphicsCache * singleton;
56         ///
57         typedef std::map<string, shared_ptr_item> CacheType;
58         ///
59         CacheType cache;
60         
61         /** We need this so that an Item can tell the cache that it should be
62             deleted. (to call removeFile).
63             It also helps removing a warning gcc emits. */
64         friend class GraphicsCacheItem;
65 };
66 #endif