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 static bool start = true;
46 lyx_gui::init_graphics();
49 // Now return the cache
50 static Cache singleton;
64 std::vector<string> Cache::loadableFormats() const
66 return Image::loadableFormats();
70 void Cache::add(string const & file)
72 if (!AbsolutePath(file)) {
73 lyxerr << "Cache::add(" << file << "):\n"
74 << "The file must be have an absolute path."
79 // Is the file in the cache already?
81 lyxerr[Debug::GRAPHICS] << "Cache::add(" << file << "):\n"
82 << "The file is already in the cache."
87 pimpl_->cache[file] = ItemPtr(new CacheItem(file));
91 void Cache::remove(string const & file)
93 CacheType::iterator it = pimpl_->cache.find(file);
94 if (it == pimpl_->cache.end())
97 ItemPtr & item = it->second;
99 if (item.use_count() == 1) {
100 // The graphics file is in the cache, but nothing else
102 pimpl_->cache.erase(it);
107 bool Cache::inCache(string const & file) const
109 return pimpl_->cache.find(file) != pimpl_->cache.end();
113 Cache::ItemPtr const Cache::item(string const & file) const
115 CacheType::const_iterator it = pimpl_->cache.find(file);
116 if (it == pimpl_->cache.end())