2 /* This file is part of
3 * =================================================
5 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich.
7 * Copyright 1995-2000 The LyX Team.
9 * This file Copyright 2000 Baruch Even
10 * ================================================= */
15 #pragma implementation
18 #include "GraphicsCache.h"
20 #include "support/LAssert.h"
22 GraphicsCache * GraphicsCache::singleton = 0;
26 GraphicsCache::getInstance()
29 singleton = new GraphicsCache;
30 Assert(singleton != 0);
37 GraphicsCache::~GraphicsCache()
39 // The map elements should have already been eliminated.
40 Assert(cache.empty());
47 GraphicsCache::addFile(string const & filename)
49 CacheType::iterator it = cache.find(filename);
51 if (it != cache.end()) {
52 return new GraphicsCacheItem( *((*it).second) );
55 GraphicsCacheItem * cacheItem = new GraphicsCacheItem();
59 cacheItem->setFilename(filename);
61 cache[filename] = cacheItem;
63 // We do not want to return the main cache object, otherwise when the
64 // will destroy their copy they will destroy the main copy.
65 return new GraphicsCacheItem( *cacheItem );
70 GraphicsCache::removeFile(string const & filename)
72 // We do not destroy the GraphicsCacheItem since we are here because
73 // the last copy of it is being erased.
75 CacheType::iterator it = cache.find(filename);
76 if (it != cache.end())