3 * \file ConverterCache.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Angus Leeming
11 * Full author contact details are available in file CREDITS.
13 * lyx::ConverterCache is the manager of the file cache.
14 * It is responsible for creating the lyx::ConverterCacheItem's
15 * and maintaining them.
17 * lyx::ConverterCache is a singleton class. It is possible to have
18 * only one instance of it at any moment.
21 #ifndef CONVERTERCACHE_H
22 #define CONVERTERCACHE_H
24 #include <boost/utility.hpp>
25 #include <boost/scoped_ptr.hpp>
32 namespace support { class FileName; }
35 * Cache for converted files. The cache works as follows:
37 * The key for a cache item consists of the absolute name of the original
38 * file and the format name of the target format. The original file in the
39 * user directory is named \c orig_from in the code, the format name is named
40 * \c to_format. Example:
41 * \c orig_from = "/home/me/myfigure.fig"
42 * \c to_format = "eps"
43 * A cache item is considered up to date (inCache() returns \c true) if
44 * - The cache contains an item with key (\c orig_to, \c to_format)
45 * - The stored timestamp of the item is identical with the actual timestamp
46 * of \c orig_from, or, if that is not the case, the stored checksum is
47 * identical with the actual checksum of \c orig_from.
48 * Otherwise the item is not considered up to date, and add() will refresh it.
50 * There is no cache maintenance yet (max size, max age etc.)
52 class ConverterCache : boost::noncopyable {
55 /// This is a singleton class. Get the instance.
56 static ConverterCache & get();
58 /// Init the cache. This must be done after package initialization.
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.
65 void add(support::FileName const & orig_from, std::string const & to_format,
66 support::FileName const & converted_file) const;
68 /// Remove a file from the cache.
69 void remove(support::FileName const & orig_from,
70 std::string const & to_format) const;
73 * Returns \c true if \c orig_from converted to \c to_format is in
74 * the cache and up to date.
76 bool inCache(support::FileName const & orig_from,
77 std::string const & to_format) const;
79 /// Get the name of the cached file
80 support::FileName const & cacheName(support::FileName const & orig_from,
81 std::string const & to_format) const;
83 /// Copy the file from the cache to \p dest
84 bool copy(support::FileName const & orig_from, std::string const & to_format,
85 support::FileName const & dest) const;
88 /** Make the c-tor, d-tor private so we can control how many objects
95 /// Use the Pimpl idiom to hide the internals.
97 /// The pointer never changes although *pimpl_'s contents may.
98 boost::scoped_ptr<Impl> const pimpl_;