]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCache.C
small fix with footnote, use stringstream some more
[lyx.git] / src / graphics / GraphicsCache.C
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 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "GraphicsCache.h"
19 #include "GraphicsCacheItem.h"
20
21 #include "support/LAssert.h"
22
23 GraphicsCache &
24 GraphicsCache::getInstance()
25 {
26         static GraphicsCache singleton;
27         return singleton;
28 }
29
30
31 GraphicsCache::~GraphicsCache()
32 {
33         // All elements are destroyed by the shared_ptr's in the map.
34 }
35
36
37 GraphicsCache::shared_ptr_item
38 GraphicsCache::addFile(string const & filename)
39 {
40         CacheType::iterator it = cache.find(filename);
41         
42         if (it != cache.end()) {
43                 return it->second;
44         }
45         
46         shared_ptr_item cacheItem(new GraphicsCacheItem(filename));
47         if (cacheItem.get() == 0)
48                 return cacheItem;
49         
50         cache[filename] = cacheItem;
51
52         // GraphicsCacheItem_ptr is a shared_ptr and thus reference counted,
53         // it is safe to return it directly.
54         return cacheItem;
55 }
56
57
58 void
59 GraphicsCache::removeFile(string const & filename)
60 {
61         // We do not destroy the GraphicsCacheItem since we are here because
62         // the last copy of it is being erased.
63
64         CacheType::iterator it = cache.find(filename);
65         if (it != cache.end())
66                 cache.erase(it);
67 }