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-05-24 10:39:34 +00:00
|
|
|
#include "LString.h"
|
2002-04-19 09:17:05 +00:00
|
|
|
#include <vector>
|
2000-10-02 00:55:02 +00:00
|
|
|
#include <boost/utility.hpp>
|
2002-06-28 11:22:56 +00:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
2001-02-22 16:53:59 +00:00
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace graphics {
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
class CacheItem;
|
|
|
|
|
|
|
|
class Cache : boost::noncopyable {
|
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.
|
|
|
|
*/
|
|
|
|
std::vector<string> 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.
|
2002-07-17 16:56:42 +00:00
|
|
|
void add(string 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.
|
2002-07-17 16:56:42 +00:00
|
|
|
void remove(string const & file) const;
|
2002-06-25 15:59:10 +00:00
|
|
|
|
|
|
|
/// Returns \c true if the file is in the cache.
|
|
|
|
bool inCache(string const & file) const;
|
|
|
|
|
|
|
|
/** 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;
|
|
|
|
///
|
|
|
|
ItemPtr const item(string const & file) const;
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
private:
|
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.
|
|
|
|
boost::scoped_ptr<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
|