2006-11-13 10:27:57 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file ConverterCache.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Baruch Even
|
|
|
|
* \author Angus Leeming
|
|
|
|
* \author Georg Baum
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*
|
2007-11-07 21:25:22 +00:00
|
|
|
* ConverterCache is the manager of the file cache.
|
|
|
|
* It is responsible for creating the ConverterCacheItem's
|
2006-11-13 10:27:57 +00:00
|
|
|
* and maintaining them.
|
|
|
|
*
|
2007-11-07 21:25:22 +00:00
|
|
|
* ConverterCache is a singleton class. It is possible to have
|
2006-11-13 10:27:57 +00:00
|
|
|
* only one instance of it at any moment.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONVERTERCACHE_H
|
|
|
|
#define CONVERTERCACHE_H
|
|
|
|
|
2007-11-07 21:25:22 +00:00
|
|
|
#include "support/strfwd.h"
|
2006-11-13 10:27:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
namespace support { class FileName; }
|
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
/**
|
|
|
|
* Cache for converted files. The cache works as follows:
|
|
|
|
*
|
|
|
|
* The key for a cache item consists of the absolute name of the original
|
|
|
|
* file and the format name of the target format. The original file in the
|
|
|
|
* user directory is named \c orig_from in the code, the format name is named
|
|
|
|
* \c to_format. Example:
|
|
|
|
* \c orig_from = "/home/me/myfigure.fig"
|
|
|
|
* \c to_format = "eps"
|
|
|
|
* A cache item is considered up to date (inCache() returns \c true) if
|
|
|
|
* - The cache contains an item with key (\c orig_to, \c to_format)
|
|
|
|
* - The stored timestamp of the item is identical with the actual timestamp
|
|
|
|
* of \c orig_from, or, if that is not the case, the stored checksum is
|
|
|
|
* identical with the actual checksum of \c orig_from.
|
|
|
|
* Otherwise the item is not considered up to date, and add() will refresh it.
|
|
|
|
*
|
|
|
|
* There is no cache maintenance yet (max size, max age etc.)
|
|
|
|
*/
|
2007-11-07 21:25:22 +00:00
|
|
|
class ConverterCache {
|
2006-11-13 10:27:57 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
/// This is a singleton class. Get the instance.
|
|
|
|
static ConverterCache & get();
|
|
|
|
|
|
|
|
/// Init the cache. This must be done after package initialization.
|
|
|
|
static void init();
|
|
|
|
|
2009-05-10 00:03:14 +00:00
|
|
|
/// Writes the index list. This must be called on exit.
|
2009-06-29 23:43:23 +00:00
|
|
|
void writeIndex() const;
|
2009-05-10 00:03:14 +00:00
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
/**
|
|
|
|
* Add \c converted_file (\c orig_from converted to \c to_format) to
|
|
|
|
* the cache if it is not already in or not up to date.
|
|
|
|
*/
|
2006-11-26 21:30:39 +00:00
|
|
|
void add(support::FileName const & orig_from, std::string const & to_format,
|
2007-05-28 22:27:45 +00:00
|
|
|
support::FileName const & converted_file) const;
|
2006-11-13 10:27:57 +00:00
|
|
|
|
|
|
|
/// Remove a file from the cache.
|
2006-11-26 21:30:39 +00:00
|
|
|
void remove(support::FileName const & orig_from,
|
2007-05-28 22:27:45 +00:00
|
|
|
std::string const & to_format) const;
|
2006-11-13 10:27:57 +00:00
|
|
|
|
2007-05-17 08:31:00 +00:00
|
|
|
/// Remove all cached \p from_format -> \p to_format conversions
|
|
|
|
void remove_all(std::string const & from_format,
|
2007-05-28 22:27:45 +00:00
|
|
|
std::string const & to_format) const;
|
2007-05-17 08:31:00 +00:00
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
/**
|
|
|
|
* Returns \c true if \c orig_from converted to \c to_format is in
|
|
|
|
* the cache and up to date.
|
|
|
|
*/
|
2006-11-26 21:30:39 +00:00
|
|
|
bool inCache(support::FileName const & orig_from,
|
2007-05-28 22:27:45 +00:00
|
|
|
std::string const & to_format) const;
|
2006-11-13 10:27:57 +00:00
|
|
|
|
|
|
|
/// Get the name of the cached file
|
2006-11-26 21:30:39 +00:00
|
|
|
support::FileName const & cacheName(support::FileName const & orig_from,
|
2007-05-28 22:27:45 +00:00
|
|
|
std::string const & to_format) const;
|
2006-11-13 10:27:57 +00:00
|
|
|
|
|
|
|
/// Copy the file from the cache to \p dest
|
2006-11-26 21:30:39 +00:00
|
|
|
bool copy(support::FileName const & orig_from, std::string const & to_format,
|
2007-05-28 22:27:45 +00:00
|
|
|
support::FileName const & dest) const;
|
2006-11-13 10:27:57 +00:00
|
|
|
|
|
|
|
private:
|
2007-11-07 21:25:22 +00:00
|
|
|
/// noncopyable
|
|
|
|
ConverterCache(ConverterCache const &);
|
|
|
|
void operator=(ConverterCache const &);
|
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
/** Make the c-tor, d-tor private so we can control how many objects
|
|
|
|
* are instantiated.
|
|
|
|
*/
|
|
|
|
ConverterCache();
|
|
|
|
///
|
|
|
|
~ConverterCache();
|
|
|
|
|
|
|
|
/// Use the Pimpl idiom to hide the internals.
|
|
|
|
class Impl;
|
|
|
|
/// The pointer never changes although *pimpl_'s contents may.
|
2007-11-07 21:25:22 +00:00
|
|
|
Impl * const pimpl_;
|
2006-11-13 10:27:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif
|