2000-07-31 12:30:10 +00:00
|
|
|
// -*- C++ -*-
|
2002-02-27 09:59:52 +00:00
|
|
|
/**
|
2003-08-23 00:17:00 +00:00
|
|
|
* \file GraphicsCache.h
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2000-07-31 12:30:10 +00:00
|
|
|
*
|
2002-09-05 11:31:30 +00:00
|
|
|
* \author Baruch Even
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-02-27 09:59:52 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* lyx::graphics::Cache is the manager of the image cache.
|
|
|
|
* It is responsible for creating the lyx::graphics::CacheItem's
|
|
|
|
* and maintaining them.
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* lyx::graphics::Cache is a singleton class. It is possible to have only one
|
|
|
|
* instance of it at any moment.
|
2002-02-27 09:59:52 +00:00
|
|
|
*/
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
#ifndef GRAPHICSCACHE_H
|
|
|
|
#define GRAPHICSCACHE_H
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
#include <vector>
|
2003-10-07 06:45:25 +00:00
|
|
|
#include <string>
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2001-02-22 16:53:59 +00:00
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
namespace lyx {
|
2006-11-26 21:30:39 +00:00
|
|
|
|
|
|
|
namespace support { class FileName; }
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
namespace graphics {
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
class CacheItem;
|
|
|
|
|
2007-11-21 23:31:12 +00:00
|
|
|
class Cache {
|
2000-07-31 12:30:10 +00:00
|
|
|
public:
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// This is a singleton class. Get the instance.
|
2002-06-28 11:22:56 +00:00
|
|
|
static Cache & get();
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-25 15:59:10 +00:00
|
|
|
/** Which graphics formats can be loaded directly by the image loader.
|
|
|
|
* Other formats can be loaded if a converter to a loadable format
|
|
|
|
* can be defined.
|
|
|
|
*/
|
2008-06-06 11:34:49 +00:00
|
|
|
std::vector<std::string> const & loadableFormats() const;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-25 15:59:10 +00:00
|
|
|
/// Add a graphics file to the cache.
|
2006-11-26 21:30:39 +00:00
|
|
|
void add(support::FileName const & file) const;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
/// Remove a file from the cache.
|
2006-11-26 21:30:39 +00:00
|
|
|
void remove(support::FileName const & file) const;
|
2002-06-25 15:59:10 +00:00
|
|
|
|
|
|
|
/// Returns \c true if the file is in the cache.
|
2006-11-26 21:30:39 +00:00
|
|
|
bool inCache(support::FileName const & file) const;
|
2002-06-25 15:59:10 +00:00
|
|
|
|
|
|
|
/** Get the cache item associated with file.
|
|
|
|
* Returns an empty container if there is no such item.
|
|
|
|
*
|
|
|
|
* IMPORTANT: whatever uses an image must make a local copy of this
|
2002-07-17 17:10:45 +00:00
|
|
|
* ItemPtr. The boost::shared_ptr<>::use_count() function is
|
2002-06-25 15:59:10 +00:00
|
|
|
* used to ascertain whether or not to remove the item from the cache
|
|
|
|
* when remove(file) is called.
|
|
|
|
*
|
|
|
|
* You have been warned!
|
2002-02-27 09:59:52 +00:00
|
|
|
*/
|
2002-06-28 11:22:56 +00:00
|
|
|
typedef boost::shared_ptr<CacheItem> ItemPtr;
|
|
|
|
///
|
2006-11-26 21:30:39 +00:00
|
|
|
ItemPtr const item(support::FileName const & file) const;
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
private:
|
2007-11-21 23:31:12 +00:00
|
|
|
/// noncopyable
|
|
|
|
Cache(Cache const &);
|
|
|
|
void operator=(Cache const &);
|
|
|
|
|
2002-06-25 15:59:10 +00:00
|
|
|
/** Make the c-tor, d-tor private so we can control how many objects
|
2002-02-27 09:59:52 +00:00
|
|
|
* are instantiated.
|
|
|
|
*/
|
2002-06-28 11:22:56 +00:00
|
|
|
Cache();
|
2002-06-25 15:59:10 +00:00
|
|
|
///
|
2002-06-28 11:22:56 +00:00
|
|
|
~Cache();
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
/// Use the Pimpl idiom to hide the internals.
|
|
|
|
class Impl;
|
|
|
|
/// The pointer never changes although *pimpl_'s contents may.
|
2007-11-21 23:47:47 +00:00
|
|
|
Impl * const pimpl_;
|
2000-07-31 12:30:10 +00:00
|
|
|
};
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
} // namespace graphics
|
|
|
|
} // namespace lyx
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
#endif // GRAPHICSCACHE_H
|