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 // This is not really needed, it will only happen on program close and in
42 // any case the OS will release those resources (not doing it may have
43 // a good effect on closing time).
50 GraphicsCache::addFile(string const & filename)
52 CacheType::const_iterator it = cache.find(filename);
54 if (it != cache.end()) {
55 return new GraphicsCacheItem( *((*it).second) );
58 GraphicsCacheItem * cacheItem = new GraphicsCacheItem();
62 cacheItem->setFilename(filename);
64 cache[filename] = cacheItem;
66 // We do not want to return the main cache object, otherwise when the
67 // will destroy their copy they will destroy the main copy.
68 return new GraphicsCacheItem( *cacheItem );
73 GraphicsCache::removeFile(string const & filename)
75 // We do not destroy the GraphicsCacheItem since we are here because
76 // the last copy of it is being erased.
78 if (cache.find(filename) != cache.end())
79 cache.erase(filename);