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