2 * \file GraphicsCache.C
3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
6 * \author Baruch Even <baruch.even@writeme.com>
7 * \author Angus Leeming <a.leeming@ic.ac.uk>
13 #pragma implementation
16 #include "GraphicsCache.h"
17 #include "GraphicsCacheItem.h"
18 #include "GraphicsImage.h"
22 #include "support/filetools.h"
24 #include "frontends/lyx_gui.h"
30 /** The cache contains one item per file, so use a map to find the
31 * cache item quickly by filename.
33 typedef std::map<string, Cache::ItemPtr> CacheType;
43 // Now return the cache
44 static Cache singleton;
58 std::vector<string> Cache::loadableFormats() const
60 return Image::loadableFormats();
64 void Cache::add(string const & file)
66 if (!AbsolutePath(file)) {
67 lyxerr << "Cache::add(" << file << "):\n"
68 << "The file must be have an absolute path."
73 // Is the file in the cache already?
75 lyxerr[Debug::GRAPHICS] << "Cache::add(" << file << "):\n"
76 << "The file is already in the cache."
81 pimpl_->cache[file] = ItemPtr(new CacheItem(file));
85 void Cache::remove(string const & file)
87 CacheType::iterator it = pimpl_->cache.find(file);
88 if (it == pimpl_->cache.end())
91 ItemPtr & item = it->second;
93 if (item.use_count() == 1) {
94 // The graphics file is in the cache, but nothing else
96 pimpl_->cache.erase(it);
101 bool Cache::inCache(string const & file) const
103 return pimpl_->cache.find(file) != pimpl_->cache.end();
107 Cache::ItemPtr const Cache::item(string const & file) const
109 CacheType::const_iterator it = pimpl_->cache.find(file);
110 if (it == pimpl_->cache.end())