]> git.lyx.org Git - lyx.git/blob - src/ConverterCache.h
* languages: use nb_NO instead of no_NO for norwegian (bug 2850).
[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  * lyx::ConverterCache is the manager of the file cache.
14  * It is responsible for creating the lyx::ConverterCacheItem's
15  * and maintaining them.
16  *
17  * lyx::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 <boost/utility.hpp>
25 #include <boost/scoped_ptr.hpp>
26
27 #include <string>
28
29
30 namespace lyx {
31
32 /**
33  * Cache for converted files. The cache works as follows:
34  *
35  * The key for a cache item consists of the absolute name of the original
36  * file and the format name of the target format.  The original file in the
37  * user directory is named \c orig_from in the code, the format name is named
38  * \c to_format. Example:
39  * \c orig_from = "/home/me/myfigure.fig"
40  * \c to_format = "eps"
41  * A cache item is considered up to date (inCache() returns \c true) if
42  * - The cache contains an item with key (\c orig_to, \c to_format)
43  * - The stored timestamp of the item is identical with the actual timestamp
44  *   of \c orig_from, or, if that is not the case, the stored checksum is
45  *   identical with the actual checksum of \c orig_from.
46  * Otherwise the item is not considered up to date, and add() will refresh it.
47  *
48  * There is no cache maintenance yet (max size, max age etc.)
49  */
50 class ConverterCache : boost::noncopyable {
51 public:
52
53         /// This is a singleton class. Get the instance.
54         static ConverterCache & get();
55
56         /// Init the cache. This must be done after package initialization.
57         static void init();
58
59         /**
60          * Add \c converted_file (\c orig_from converted to \c to_format) to
61          * the cache if it is not already in or not up to date.
62          */
63         void add(std::string const & orig_from, std::string const & to_format,
64                  std::string const & converted_file) const;
65
66         /// Remove a file from the cache.
67         void remove(std::string const & orig_from,
68                     std::string const & to_format) const;
69
70         /**
71          * Returns \c true if \c orig_from converted to \c to_format is in
72          * the cache and up to date.
73          */
74         bool inCache(std::string const & orig_from,
75                      std::string const & to_format) const;
76
77         /// Get the name of the cached file
78         std::string const cacheName(std::string const & orig_from,
79                                     std::string const & to_format) const;
80
81         /// Copy the file from the cache to \p dest
82         bool copy(std::string const & orig_from, std::string const & to_format,
83                   std::string const & dest) const;
84
85 private:
86         /** Make the c-tor, d-tor private so we can control how many objects
87          *  are instantiated.
88          */
89         ConverterCache();
90         ///
91         ~ConverterCache();
92
93         /// Use the Pimpl idiom to hide the internals.
94         class Impl;
95         /// The pointer never changes although *pimpl_'s contents may.
96         boost::scoped_ptr<Impl> const pimpl_;
97 };
98
99 } // namespace lyx
100
101 #endif