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()
40 //std::foreach(map.begin(), map.end(), ...);
41 //#warning This is a bogus reason to not clean up after your self. (Lgb)
42 // TODO: Clean up here (BE)
44 // This is not really needed, it will only happen on program close and in
45 // any case the OS will release those resources (not doing it may have
46 // a good effect on closing time).
53 GraphicsCache::addFile(string const & filename)
55 CacheType::iterator it = cache.find(filename);
57 if (it != cache.end()) {
58 return new GraphicsCacheItem( *((*it).second) );
61 GraphicsCacheItem * cacheItem = new GraphicsCacheItem();
65 cacheItem->setFilename(filename);
67 cache[filename] = cacheItem;
69 // We do not want to return the main cache object, otherwise when the
70 // will destroy their copy they will destroy the main copy.
71 return new GraphicsCacheItem( *cacheItem );
76 GraphicsCache::removeFile(string const & filename)
78 // We do not destroy the GraphicsCacheItem since we are here because
79 // the last copy of it is being erased.
81 if (cache.find(filename) != cache.end())
82 cache.erase(filename);