2 * \file GraphicsCache.C
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"
20 #include "support/filetools.h"
22 #include "frontends/lyx_gui.h"
26 using namespace lyx::support;
31 /** The cache contains one item per file, so use a map to find the
32 * cache item quickly by filename.
34 typedef std::map<string, Cache::ItemPtr> CacheType;
44 // Now return the cache
45 static Cache singleton;
59 std::vector<string> Cache::loadableFormats() const
61 return Image::loadableFormats();
65 void Cache::add(string const & file) const
67 if (!AbsolutePath(file)) {
68 lyxerr << "Cache::add(" << file << "):\n"
69 << "The file must be have an absolute path."
74 // Is the file in the cache already?
76 lyxerr[Debug::GRAPHICS] << "Cache::add(" << file << "):\n"
77 << "The file is already in the cache."
82 pimpl_->cache[file] = ItemPtr(new CacheItem(file));
86 void Cache::remove(string const & file) const
88 CacheType::iterator it = pimpl_->cache.find(file);
89 if (it == pimpl_->cache.end())
92 ItemPtr & item = it->second;
94 if (item.use_count() == 1) {
95 // The graphics file is in the cache, but nothing else
97 pimpl_->cache.erase(it);
102 bool Cache::inCache(string const & file) const
104 return pimpl_->cache.find(file) != pimpl_->cache.end();
108 Cache::ItemPtr const Cache::item(string const & file) const
110 CacheType::const_iterator it = pimpl_->cache.find(file);
111 if (it == pimpl_->cache.end())
117 } // namespace graphics