]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCache.h
Forgot to save changed file ;)
[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 "LString.h"
27 #include <boost/utility.hpp>
28
29 class InsetGraphics;
30
31 namespace grfx {
32
33 class GCacheItem;
34
35 class GCache : boost::noncopyable {
36 public:
37
38         /// This is a singleton class. Get the instance.
39         static GCache & get();
40
41         ///
42         ~GCache();
43
44         /// Add a file to the cache (or modify an existing image).
45         void update(InsetGraphics const &, string const & filepath);
46
47         /** Remove the data associated with this inset.
48          *  Called from the InsetGraphics d-tor.
49          */
50         void remove(InsetGraphics const &);
51
52         /** No processing of the image will take place until this call is
53          *  received.
54          */
55         void startLoading(InsetGraphics const &);
56
57         /** If (changed_background == true), then the background color of the
58          *  graphics inset has changed. Update all images.
59          *  Else, the preferred display type has changed.
60          *  Update the view of all insets whose display type is DEFAULT.
61          */
62         void changeDisplay(bool changed_background = false);
63
64         /// Get the image referenced by a particular inset.
65         ImagePtr const image(InsetGraphics const &) const;
66
67         /// How far have we got in loading the image?
68         ImageStatus status(InsetGraphics const &) const;
69
70         // Used to ascertain the Bounding Box of non (e)ps files.
71         unsigned int raw_width(string const & filename) const;
72         ///
73         unsigned int raw_height(string const & filename) const;
74         
75 private:
76         /** Make the c-tor private so we can control how many objects
77          *  are instantiated.
78          */
79         GCache();
80
81         /// The cache contains data of this type.
82         typedef boost::shared_ptr<GCacheItem> CacheItemType;
83
84         /** The cache contains one item per file, so use a map to find the
85          *  cache item quickly by filename.
86          *  Note that each cache item can have multiple views, potentially one
87          *  per inset that references the original file.
88          */
89         typedef std::map<string, CacheItemType> CacheType;
90
91         /// Search the cache by inset.
92         CacheType::const_iterator find(InsetGraphics const &) const;
93         ///
94         CacheType::iterator find(InsetGraphics const &);
95
96         /** Store a pointer to the cache so that we can forward declare
97          *  GCacheItem.
98          */
99         CacheType * cache;
100 };
101
102 } // namespace grfx
103
104
105 #endif // GRAPHICSCACHE_H