2000-07-31 12:30:10 +00:00
|
|
|
// -*- C++ -*-
|
2002-02-27 09:59:52 +00:00
|
|
|
/**
|
|
|
|
* \file GraphicsCache.h
|
|
|
|
* Copyright 2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
2000-07-31 12:30:10 +00:00
|
|
|
*
|
2002-02-27 09:59:52 +00:00
|
|
|
* \author Baruch Even <baruch.even@writeme.com>
|
2002-07-15 10:19:45 +00:00
|
|
|
* \author Angus Leeming <leeming@lyx.org>
|
2002-02-27 09:59:52 +00:00
|
|
|
*
|
2002-06-28 11:22:56 +00:00
|
|
|
* grfx::Cache is the manager of the image cache.
|
|
|
|
* It is responsible for creating the grfx::CacheItem's and maintaining them.
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2002-06-28 11:22:56 +00:00
|
|
|
* grfx::Cache is a singleton class. It is possible to have only one
|
2002-02-27 09:59:52 +00:00
|
|
|
* instance of it at any moment.
|
|
|
|
*/
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
#ifndef GRAPHICSCACHE_H
|
|
|
|
#define GRAPHICSCACHE_H
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
namespace grfx {
|
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
|
|
|
|
* GraphicPtr. The boost::shared_ptr<>::use_count() function is
|
|
|
|
* 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
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
} // namespace grfx
|
|
|
|
|
|
|
|
#endif // GRAPHICSCACHE_H
|