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
15 #pragma implementation
18 #include "GraphicsCache.h"
19 #include "GraphicsCacheItem.h"
20 #include "GraphicsImage.h"
24 #include "support/filetools.h"
26 #include "frontends/lyx_gui.h"
32 /** The cache contains one item per file, so use a map to find the
33 * cache item quickly by filename.
35 typedef std::map<string, Cache::ItemPtr> CacheType;
45 // Now return the cache
46 static Cache singleton;
60 std::vector<string> Cache::loadableFormats() const
62 return Image::loadableFormats();
66 void Cache::add(string const & file) const
68 if (!AbsolutePath(file)) {
69 lyxerr << "Cache::add(" << file << "):\n"
70 << "The file must be have an absolute path."
75 // Is the file in the cache already?
77 lyxerr[Debug::GRAPHICS] << "Cache::add(" << file << "):\n"
78 << "The file is already in the cache."
83 pimpl_->cache[file] = ItemPtr(new CacheItem(file));
87 void Cache::remove(string const & file) const
89 CacheType::iterator it = pimpl_->cache.find(file);
90 if (it == pimpl_->cache.end())
93 ItemPtr & item = it->second;
95 if (item.use_count() == 1) {
96 // The graphics file is in the cache, but nothing else
98 pimpl_->cache.erase(it);
103 bool Cache::inCache(string const & file) const
105 return pimpl_->cache.find(file) != pimpl_->cache.end();
109 Cache::ItemPtr const Cache::item(string const & file) const
111 CacheType::const_iterator it = pimpl_->cache.find(file);
112 if (it == pimpl_->cache.end())