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"
28 GCache & GCache::get()
30 static bool start = true;
33 lyx_gui::init_graphics();
36 // Now return the cache
37 static GCache singleton;
44 cache = new CacheType;
48 // all elements are destroyed by the shared_ptr's in the map.
55 std::vector<string> GCache::loadableFormats() const
57 return GImage::loadableFormats();
61 void GCache::add(string const & file)
63 if (!AbsolutePath(file)) {
64 lyxerr << "GCacheItem::add(" << file << "):\n"
65 << "The file must be have an absolute path."
70 // Is the file in the cache already?
72 lyxerr[Debug::GRAPHICS] << "GCache::add(" << file << "):\n"
73 << "The file is already in the cache."
79 (*cache)[file] = GraphicPtr(new GCacheItem(file));
83 void GCache::remove(string const & file)
85 CacheType::iterator it = cache->find(file);
86 if (it == cache->end())
89 GraphicPtr item = it->second;
91 if (item.use_count() == 1) {
92 // The graphics file is in the cache, but nothing else
99 bool GCache::inCache(string const & file) const
101 return cache->find(file) != cache->end();
105 GraphicPtr const GCache::graphic(string const & file) const
107 CacheType::const_iterator it = cache->find(file);
108 if (it == cache->end())
115 ImagePtr const GCache::image(string const & file) const
117 CacheType::const_iterator it = cache->find(file);
118 if (it == cache->end())
121 return it->second->image();