mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-24 18:43:37 +00:00
31b56dac80
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2123 a592a061-630c-0410-9148-cb99ea01b6c8
67 lines
1.4 KiB
C
67 lines
1.4 KiB
C
/* This file is part of
|
|
* =================================================
|
|
*
|
|
* LyX, The Document Processor
|
|
* Copyright 1995 Matthias Ettrich.
|
|
* Copyright 1995-2001 The LyX Team.
|
|
*
|
|
* This file Copyright 2000 Baruch Even
|
|
* ================================================= */
|
|
|
|
#include <config.h>
|
|
|
|
#ifdef __GNUG__
|
|
#pragma implementation
|
|
#endif
|
|
|
|
#include "GraphicsCache.h"
|
|
#include "GraphicsCacheItem.h"
|
|
|
|
#include "support/LAssert.h"
|
|
|
|
GraphicsCache &
|
|
GraphicsCache::getInstance()
|
|
{
|
|
static GraphicsCache singleton;
|
|
return singleton;
|
|
}
|
|
|
|
|
|
GraphicsCache::~GraphicsCache()
|
|
{
|
|
// All elements are destroyed by the shared_ptr's in the map.
|
|
}
|
|
|
|
|
|
GraphicsCache::shared_ptr_item
|
|
GraphicsCache::addFile(string const & filename)
|
|
{
|
|
CacheType::iterator it = cache.find(filename);
|
|
|
|
if (it != cache.end()) {
|
|
return it->second;
|
|
}
|
|
|
|
shared_ptr_item cacheItem(new GraphicsCacheItem(filename));
|
|
if (cacheItem.get() == 0)
|
|
return cacheItem;
|
|
|
|
cache[filename] = cacheItem;
|
|
|
|
// GraphicsCacheItem_ptr is a shared_ptr and thus reference counted,
|
|
// it is safe to return it directly.
|
|
return cacheItem;
|
|
}
|
|
|
|
|
|
void
|
|
GraphicsCache::removeFile(string const & filename)
|
|
{
|
|
// We do not destroy the GraphicsCacheItem since we are here because
|
|
// the last copy of it is being erased.
|
|
|
|
CacheType::iterator it = cache.find(filename);
|
|
if (it != cache.end())
|
|
cache.erase(it);
|
|
}
|