]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCache.h
Fix bug #9684: Update previews after background color change
[lyx.git] / src / graphics / GraphicsCache.h
1 // -*- C++ -*-
2 /**
3  * \file GraphicsCache.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Baruch Even
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS.
11  *
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.
15  *
16  * lyx::graphics::Cache is a singleton class. It is possible to have only one
17  * instance of it at any moment.
18  */
19
20 #ifndef GRAPHICSCACHE_H
21 #define GRAPHICSCACHE_H
22
23 #include "support/shared_ptr.h"
24
25 #include <vector>
26 #include <string>
27
28
29 namespace lyx {
30
31 namespace support { class FileName; }
32
33 namespace graphics {
34
35 class CacheItem;
36
37 class Cache {
38 public:
39
40         /// This is a singleton class. Get the instance.
41         static Cache & get();
42
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
45          *  can be defined.
46          */
47         std::vector<std::string> const & loadableFormats() const;
48
49         /// Add a graphics file to the cache.
50         void add(support::FileName const & file) const;
51
52         /// Remove a file from the cache.
53         void remove(support::FileName const & file) const;
54
55         /// Returns \c true if the file is in the cache.
56         bool inCache(support::FileName const & file) const;
57
58         /** Get the cache item associated with file.
59          *  Returns an empty container if there is no such item.
60          *
61          *  IMPORTANT: whatever uses an image must make a local copy of this
62          *  ItemPtr. The 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.
65          *
66          *  You have been warned!
67          */
68         typedef shared_ptr<CacheItem> ItemPtr;
69         ///
70         ItemPtr const item(support::FileName const & file) const;
71
72 private:
73         /// noncopyable
74         Cache(Cache const &);
75         void operator=(Cache const &);
76
77         /** Make the c-tor, d-tor private so we can control how many objects
78          *  are instantiated.
79          */
80         Cache();
81         ///
82         ~Cache();
83
84         /// Use the Pimpl idiom to hide the internals.
85         class Impl;
86         /// The pointer never changes although *pimpl_'s contents may.
87         Impl * const pimpl_;
88 };
89
90 } // namespace graphics
91 } // namespace lyx
92
93 #endif // GRAPHICSCACHE_H