3 * \file GraphicsCache.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS
12 * grfx::Cache is the manager of the image cache.
13 * It is responsible for creating the grfx::CacheItem's and maintaining them.
15 * grfx::Cache is a singleton class. It is possible to have only one
16 * instance of it at any moment.
19 #ifndef GRAPHICSCACHE_H
20 #define GRAPHICSCACHE_H
28 #include <boost/utility.hpp>
29 #include <boost/scoped_ptr.hpp>
30 #include <boost/shared_ptr.hpp>
37 class Cache : boost::noncopyable {
40 /// This is a singleton class. Get the instance.
43 /** Which graphics formats can be loaded directly by the image loader.
44 * Other formats can be loaded if a converter to a loadable format
47 std::vector<string> loadableFormats() const;
49 /// Add a graphics file to the cache.
50 void add(string const & file) const;
52 /// Remove a file from the cache.
53 void remove(string const & file) const;
55 /// Returns \c true if the file is in the cache.
56 bool inCache(string const & file) const;
58 /** Get the cache item associated with file.
59 * Returns an empty container if there is no such item.
61 * IMPORTANT: whatever uses an image must make a local copy of this
62 * ItemPtr. The boost::shared_ptr<>::use_count() function is
63 * used to ascertain whether or not to remove the item from the cache
64 * when remove(file) is called.
66 * You have been warned!
68 typedef boost::shared_ptr<CacheItem> ItemPtr;
70 ItemPtr const item(string const & file) const;
73 /** Make the c-tor, d-tor private so we can control how many objects
80 /// Use the Pimpl idiom to hide the internals.
82 /// The pointer never changes although *pimpl_'s contents may.
83 boost::scoped_ptr<Impl> const pimpl_;
88 #endif // GRAPHICSCACHE_H