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