lyx_mirror/src/graphics/GraphicsCache.C
Angus Leeming 31b56dac80 In for a penny, in for a pound. Consistent use of // -*- C++ -*-
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2123 a592a061-630c-0410-9148-cb99ea01b6c8
2001-06-14 08:20:41 +00:00

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);
}