3 * \file GraphicsCache.h
4 * Copyright 2002 the LyX Team
5 * Read the file COPYING
7 * \author Baruch Even <baruch.even@writeme.com>
8 * \author Angus Leeming <a.leeming@ic.ac.uk>
10 * grfx::GCache is the manager of the image cache.
11 * It is responsible for creating the grfx::GCacheItem's and maintaining them.
13 * grfx::GCache is a singleton class. It is possible to have only one
14 * instance of it at any moment.
17 #ifndef GRAPHICSCACHE_H
18 #define GRAPHICSCACHE_H
24 #include "GraphicsTypes.h"
28 #include <boost/utility.hpp>
36 class GCache : boost::noncopyable {
39 /// This is a singleton class. Get the instance.
40 static GCache & get();
45 /// Add a file to the cache (or modify an existing image).
46 void update(InsetGraphics const &, string const & filepath);
48 /** Remove the data associated with this inset.
49 * Called from the InsetGraphics d-tor.
51 void remove(InsetGraphics const &);
53 /** No processing of the image will take place until this call is
56 void startLoading(InsetGraphics const &);
58 /** If (changed_background == true), then the background color of the
59 * graphics inset has changed. Update all images.
60 * Else, the preferred display type has changed.
61 * Update the view of all insets whose display type is DEFAULT.
63 void changeDisplay(bool changed_background = false);
65 /// Get the image referenced by a particular inset.
66 ImagePtr const image(InsetGraphics const &) const;
68 /// How far have we got in loading the image?
69 ImageStatus status(InsetGraphics const &) const;
71 // Used to ascertain the Bounding Box of non (e)ps files.
72 unsigned int raw_width(string const & filename) const;
74 unsigned int raw_height(string const & filename) const;
76 std::vector<string> loadableFormats() const;
79 /** Make the c-tor private so we can control how many objects
84 /// The cache contains data of this type.
85 typedef boost::shared_ptr<GCacheItem> CacheItemType;
87 /** The cache contains one item per file, so use a map to find the
88 * cache item quickly by filename.
89 * Note that each cache item can have multiple views, potentially one
90 * per inset that references the original file.
92 typedef std::map<string, CacheItemType> CacheType;
94 /// Search the cache by inset.
95 CacheType::const_iterator find(InsetGraphics const &) const;
97 CacheType::iterator find(InsetGraphics const &);
99 /** Store a pointer to the cache so that we can forward declare
108 #endif // GRAPHICSCACHE_H