]> git.lyx.org Git - lyx.git/blob - src/ConverterCache.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / ConverterCache.h
1 // -*- C++ -*-
2 /**
3  * \file ConverterCache.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  * \author Georg Baum
10  *
11  * Full author contact details are available in file CREDITS.
12  *
13  * ConverterCache is the manager of the file cache.
14  * It is responsible for creating the ConverterCacheItem's
15  * and maintaining them.
16  *
17  * ConverterCache is a singleton class. It is possible to have
18  * only one instance of it at any moment.
19  */
20
21 #ifndef CONVERTERCACHE_H
22 #define CONVERTERCACHE_H
23
24 #include "support/strfwd.h"
25
26
27 namespace lyx {
28
29 namespace support { class FileName; }
30
31 /**
32  * Cache for converted files. The cache works as follows:
33  *
34  * The key for a cache item consists of the absolute name of the original
35  * file and the format name of the target format.  The original file in the
36  * user directory is named \c orig_from in the code, the format name is named
37  * \c to_format. Example:
38  * \c orig_from = "/home/me/myfigure.fig"
39  * \c to_format = "eps"
40  * A cache item is considered up to date (inCache() returns \c true) if
41  * - The cache contains an item with key (\c orig_to, \c to_format)
42  * - The stored timestamp of the item is identical with the actual timestamp
43  *   of \c orig_from, or, if that is not the case, the stored checksum is
44  *   identical with the actual checksum of \c orig_from.
45  * Otherwise the item is not considered up to date, and add() will refresh it.
46  *
47  * There is no cache maintenance yet (max size, max age etc.)
48  */
49 class ConverterCache {
50 public:
51
52         /// This is a singleton class. Get the instance.
53         static ConverterCache & get();
54
55         /// Init the cache. This must be done after package initialization.
56         static void init();
57
58         /// Writes the index list. This must be called on exit.
59         void writeIndex() const;
60
61         /**
62          * Add \c converted_file (\c orig_from converted to \c to_format) to
63          * the cache if it is not already in or not up to date.
64          */
65         void add(support::FileName const & orig_from, std::string const & to_format,
66                  support::FileName const & converted_file) const;
67
68         /// Remove a file from the cache.
69         void remove(support::FileName const & orig_from,
70                     std::string const & to_format) const;
71
72         /// Remove all cached \p from_format -> \p to_format conversions
73         void remove_all(std::string const & from_format,
74                         std::string const & to_format) const;
75
76         /**
77          * Returns \c true if \c orig_from converted to \c to_format is in
78          * the cache and up to date.
79          */
80         bool inCache(support::FileName const & orig_from,
81                      std::string const & to_format) const;
82
83         /// Get the name of the cached file
84         support::FileName const & cacheName(support::FileName const & orig_from,
85                                             std::string const & to_format) const;
86
87         /// Copy the file from the cache to \p dest
88         bool copy(support::FileName const & orig_from, std::string const & to_format,
89                   support::FileName const & dest) const;
90
91 private:
92         /// noncopyable
93         ConverterCache(ConverterCache const &);
94         void operator=(ConverterCache const &);
95
96         /** Make the c-tor, d-tor private so we can control how many objects
97          *  are instantiated.
98          */
99         ConverterCache();
100         ///
101         ~ConverterCache();
102
103         /// Use the Pimpl idiom to hide the internals.
104         class Impl;
105         /// The pointer never changes although *pimpl_'s contents may.
106         Impl * const pimpl_;
107 };
108
109 } // namespace lyx
110
111 #endif