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 * lyx::graphics::Cache is the manager of the image cache.
13 * It is responsible for creating the lyx::graphics::CacheItem's
14 * and maintaining them.
16 * lyx::graphics::Cache is a singleton class. It is possible to have only one
17 * instance of it at any moment.
20 #ifndef GRAPHICSCACHE_H
21 #define GRAPHICSCACHE_H
23 #include <boost/utility.hpp>
24 #include <boost/scoped_ptr.hpp>
25 #include <boost/shared_ptr.hpp>
36 class Cache : boost::noncopyable {
39 /// This is a singleton class. Get the instance.
42 /** Which graphics formats can be loaded directly by the image loader.
43 * Other formats can be loaded if a converter to a loadable format
46 std::vector<std::string> loadableFormats() const;
48 /// Add a graphics file to the cache.
49 void add(std::string const & file) const;
51 /// Remove a file from the cache.
52 void remove(std::string const & file) const;
54 /// Returns \c true if the file is in the cache.
55 bool inCache(std::string const & file) const;
57 /** Get the cache item associated with file.
58 * Returns an empty container if there is no such item.
60 * IMPORTANT: whatever uses an image must make a local copy of this
61 * ItemPtr. The boost::shared_ptr<>::use_count() function is
62 * used to ascertain whether or not to remove the item from the cache
63 * when remove(file) is called.
65 * You have been warned!
67 typedef boost::shared_ptr<CacheItem> ItemPtr;
69 ItemPtr const item(std::string const & file) const;
72 /** Make the c-tor, d-tor private so we can control how many objects
79 /// Use the Pimpl idiom to hide the internals.
81 /// The pointer never changes although *pimpl_'s contents may.
82 boost::scoped_ptr<Impl> const pimpl_;
85 } // namespace graphics
88 #endif // GRAPHICSCACHE_H