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