2 * \file GraphicsCache.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
14 #include "GraphicsCache.h"
15 #include "GraphicsCacheItem.h"
16 #include "GraphicsImage.h"
18 #include "support/debug.h"
20 #include "support/filetools.h"
29 using support::FileName;
33 /** The cache contains one item per file, so use a map to find the
34 * cache item quickly by filename.
36 typedef std::map<FileName, Cache::ItemPtr> CacheType;
47 // Now return the cache
48 static Cache singleton;
64 std::vector<string> Cache::loadableFormats() const
66 return Image::loadableFormats();
70 void Cache::add(FileName const & file) const
72 // Is the file in the cache already?
74 LYXERR(Debug::GRAPHICS, "Cache::add(" << file << "):\n"
75 << "The file is already in the cache.");
79 pimpl_->cache[file] = ItemPtr(new CacheItem(file));
83 void Cache::remove(FileName const & file) const
85 CacheType::iterator it = pimpl_->cache.find(file);
86 if (it == pimpl_->cache.end())
89 ItemPtr & item = it->second;
91 if (item.use_count() == 1) {
92 // The graphics file is in the cache, but nothing else
94 pimpl_->cache.erase(it);
99 bool Cache::inCache(FileName const & file) const
101 return pimpl_->cache.find(file) != pimpl_->cache.end();
105 Cache::ItemPtr const Cache::item(FileName const & file) const
107 CacheType::const_iterator it = pimpl_->cache.find(file);
108 if (it == pimpl_->cache.end())
114 } // namespace graphics