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