]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCache.C
remove more forms.h cruft
[lyx.git] / src / graphics / GraphicsCache.C
1 /* This file is part of
2  * =================================================
3  * 
4  *          LyX, The Document Processor
5  *          Copyright 1995 Matthias Ettrich.
6  *          Copyright 1995-2001 The LyX Team.
7  *
8  *          This file Copyright 2000 Baruch Even
9  * ================================================= */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "GraphicsCache.h"
18 #include "GraphicsCacheItem.h"
19
20 #include "support/LAssert.h"
21
22 GraphicsCache &
23 GraphicsCache::getInstance()
24 {
25         static GraphicsCache singleton;
26         return singleton;
27 }
28
29
30 GraphicsCache::~GraphicsCache()
31 {
32         // All elements are destroyed by the shared_ptr's in the map.
33 }
34
35
36 GraphicsCache::shared_ptr_item
37 GraphicsCache::addFile(string const & filename)
38 {
39         CacheType::iterator it = cache.find(filename);
40         
41         if (it != cache.end()) {
42                 return it->second;
43         }
44         
45         shared_ptr_item cacheItem(new GraphicsCacheItem(filename));
46         if (cacheItem.get() == 0)
47                 return cacheItem;
48         
49         cache[filename] = cacheItem;
50
51         // GraphicsCacheItem_ptr is a shared_ptr and thus reference counted,
52         // it is safe to return it directly.
53         return cacheItem;
54 }
55
56
57 void
58 GraphicsCache::removeFile(string const & filename)
59 {
60         // We do not destroy the GraphicsCacheItem since we are here because
61         // the last copy of it is being erased.
62
63         CacheType::iterator it = cache.find(filename);
64         if (it != cache.end())
65                 cache.erase(it);
66 }