]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCache.h
(Marco Morandini): make the list of loadable graphics formats dynamic.
[lyx.git] / src / graphics / GraphicsCache.h
1 // -*- C++ -*-
2 /**
3  *  \file GraphicsCache.h
4  *  Copyright 2002 the LyX Team
5  *  Read the file COPYING
6  *
7  * \author Baruch Even <baruch.even@writeme.com>
8  * \author Angus Leeming <a.leeming@ic.ac.uk>
9  *
10  *  grfx::GCache is the manager of the image cache.
11  *  It is responsible for creating the grfx::GCacheItem's and maintaining them.
12  *
13  *  grfx::GCache is a singleton class. It is possible to have only one
14  *  instance of it at any moment.
15  */
16
17 #ifndef GRAPHICSCACHE_H
18 #define GRAPHICSCACHE_H
19
20 #ifdef __GNUG__
21 #pragma interface
22 #endif
23
24 #include "GraphicsTypes.h"
25 #include <map>
26 #include <vector>
27 #include "LString.h"
28 #include <boost/utility.hpp>
29
30 class InsetGraphics;
31
32 namespace grfx {
33
34 class GCacheItem;
35
36 class GCache : boost::noncopyable {
37 public:
38
39         /// This is a singleton class. Get the instance.
40         static GCache & get();
41
42         ///
43         ~GCache();
44
45         /// Add a file to the cache (or modify an existing image).
46         void update(InsetGraphics const &, string const & filepath);
47
48         /** Remove the data associated with this inset.
49          *  Called from the InsetGraphics d-tor.
50          */
51         void remove(InsetGraphics const &);
52
53         /** No processing of the image will take place until this call is
54          *  received.
55          */
56         void startLoading(InsetGraphics const &);
57
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.
62          */
63         void changeDisplay(bool changed_background = false);
64
65         /// Get the image referenced by a particular inset.
66         ImagePtr const image(InsetGraphics const &) const;
67
68         /// How far have we got in loading the image?
69         ImageStatus status(InsetGraphics const &) const;
70
71         // Used to ascertain the Bounding Box of non (e)ps files.
72         unsigned int raw_width(string const & filename) const;
73         ///
74         unsigned int raw_height(string const & filename) const;
75         ///
76         std::vector<string> loadableFormats() const;
77         
78 private:
79         /** Make the c-tor private so we can control how many objects
80          *  are instantiated.
81          */
82         GCache();
83
84         /// The cache contains data of this type.
85         typedef boost::shared_ptr<GCacheItem> CacheItemType;
86
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.
91          */
92         typedef std::map<string, CacheItemType> CacheType;
93
94         /// Search the cache by inset.
95         CacheType::const_iterator find(InsetGraphics const &) const;
96         ///
97         CacheType::iterator find(InsetGraphics const &);
98
99         /** Store a pointer to the cache so that we can forward declare
100          *  GCacheItem.
101          */
102         CacheType * cache;
103 };
104
105 } // namespace grfx
106
107
108 #endif // GRAPHICSCACHE_H