2000-07-31 12:30:10 +00:00
|
|
|
/* This file is part of
|
|
|
|
* =================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
* Copyright 1995 Matthias Ettrich.
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
2000-07-31 12:30:10 +00:00
|
|
|
*
|
|
|
|
* This file Copyright 2000 Baruch Even
|
|
|
|
* ================================================= */
|
|
|
|
|
2000-07-31 16:39:50 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "GraphicsCache.h"
|
2001-02-22 16:53:59 +00:00
|
|
|
#include "GraphicsCacheItem.h"
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2000-08-08 09:18:39 +00:00
|
|
|
#include "support/LAssert.h"
|
2000-07-31 16:39:50 +00:00
|
|
|
|
2001-02-28 11:32:10 +00:00
|
|
|
GraphicsCache &
|
2000-07-31 12:30:10 +00:00
|
|
|
GraphicsCache::getInstance()
|
|
|
|
{
|
2001-02-28 11:32:10 +00:00
|
|
|
static GraphicsCache singleton;
|
2000-09-14 17:53:12 +00:00
|
|
|
return singleton;
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 16:39:50 +00:00
|
|
|
GraphicsCache::~GraphicsCache()
|
|
|
|
{
|
2001-03-07 12:43:48 +00:00
|
|
|
// All elements are destroyed by the shared_ptr's in the map.
|
2000-07-31 16:39:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-22 16:53:59 +00:00
|
|
|
GraphicsCache::shared_ptr_item
|
2000-07-31 16:39:50 +00:00
|
|
|
GraphicsCache::addFile(string const & filename)
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
CacheType::iterator it = cache.find(filename);
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
|
|
if (it != cache.end()) {
|
2001-03-18 17:48:56 +00:00
|
|
|
return it->second;
|
2000-09-14 17:53:12 +00:00
|
|
|
}
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2001-02-22 16:53:59 +00:00
|
|
|
shared_ptr_item cacheItem(new GraphicsCacheItem(filename));
|
|
|
|
if (cacheItem.get() == 0)
|
|
|
|
return cacheItem;
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2000-08-08 09:18:39 +00:00
|
|
|
cache[filename] = cacheItem;
|
2001-02-22 16:53:59 +00:00
|
|
|
|
|
|
|
// GraphicsCacheItem_ptr is a shared_ptr and thus reference counted,
|
|
|
|
// it is safe to return it directly.
|
|
|
|
return cacheItem;
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2000-07-31 16:39:50 +00:00
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
void
|
2000-07-31 16:39:50 +00:00
|
|
|
GraphicsCache::removeFile(string const & filename)
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2000-08-10 13:15:05 +00:00
|
|
|
// We do not destroy the GraphicsCacheItem since we are here because
|
|
|
|
// the last copy of it is being erased.
|
|
|
|
|
2001-02-20 09:08:56 +00:00
|
|
|
CacheType::iterator it = cache.find(filename);
|
|
|
|
if (it != cache.end())
|
|
|
|
cache.erase(it);
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|