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"
19 #include "GraphicsCacheItem.h"
21 #include "support/LAssert.h"
23 GraphicsCache * GraphicsCache::singleton = 0;
27 GraphicsCache::getInstance()
30 singleton = new GraphicsCache;
31 Assert(singleton != 0);
38 GraphicsCache::~GraphicsCache()
40 // The map elements should have already been eliminated.
41 Assert(cache.empty());
47 GraphicsCache::shared_ptr_item
48 GraphicsCache::addFile(string const & filename)
50 CacheType::iterator it = cache.find(filename);
52 if (it != cache.end()) {
56 shared_ptr_item cacheItem(new GraphicsCacheItem(filename));
57 if (cacheItem.get() == 0)
60 cache[filename] = cacheItem;
62 // GraphicsCacheItem_ptr is a shared_ptr and thus reference counted,
63 // it is safe to return it directly.
69 GraphicsCache::removeFile(string const & filename)
71 // We do not destroy the GraphicsCacheItem since we are here because
72 // the last copy of it is being erased.
74 CacheType::iterator it = cache.find(filename);
75 if (it != cache.end())