]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCache.h
Merge branch 'master' into biblatex2
[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 <memory>
24 #include <string>
25 #include <vector>
26
27
28 namespace lyx {
29
30 namespace support { class FileName; }
31
32 namespace graphics {
33
34 class CacheItem;
35
36 class Cache {
37 public:
38
39         /// This is a singleton class. Get the instance.
40         static Cache & get();
41
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
44          *  can be defined.
45          */
46         std::vector<std::string> const & loadableFormats() const;
47
48         /// Add a graphics file to the cache.
49         void add(support::FileName const & file, support::FileName const & doc_file) const;
50
51         /// Remove a file from the cache.
52         void remove(support::FileName const & file) const;
53
54         /// Returns \c true if the file is in the cache.
55         bool inCache(support::FileName const & file) const;
56
57         /** Get the cache item associated with file.
58          *  Returns an empty container if there is no such item.
59          *
60          *  IMPORTANT: whatever uses an image must make a local copy of this
61          *  ItemPtr. The 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.
64          *
65          *  You have been warned!
66          */
67         typedef std::shared_ptr<CacheItem> ItemPtr;
68         ///
69         ItemPtr const item(support::FileName const & file) const;
70
71 private:
72         /// noncopyable
73         Cache(Cache const &);
74         void operator=(Cache const &);
75
76         /** Make the c-tor, d-tor private so we can control how many objects
77          *  are instantiated.
78          */
79         Cache();
80         ///
81         ~Cache();
82
83         /// Use the Pimpl idiom to hide the internals.
84         class Impl;
85         /// The pointer never changes although *pimpl_'s contents may.
86         Impl * const pimpl_;
87 };
88
89 } // namespace graphics
90 } // namespace lyx
91
92 #endif // GRAPHICSCACHE_H