2000-07-31 12:30:10 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
|
|
|
* =================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
* Copyright 1995 Matthias Ettrich.
|
|
|
|
* Copyright 1995-2000 The LyX Team.
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2000-08-08 09:18:39 +00:00
|
|
|
#include "support/LAssert.h"
|
2000-07-31 16:39:50 +00:00
|
|
|
|
|
|
|
GraphicsCache * GraphicsCache::singleton = 0;
|
|
|
|
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
GraphicsCache *
|
|
|
|
GraphicsCache::getInstance()
|
|
|
|
{
|
|
|
|
if (! singleton) {
|
|
|
|
singleton = new GraphicsCache;
|
2000-08-08 09:18:39 +00:00
|
|
|
Assert(singleton != 0);
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 16:39:50 +00:00
|
|
|
GraphicsCache::~GraphicsCache()
|
|
|
|
{
|
2000-08-08 09:18:39 +00:00
|
|
|
// Free the map.
|
|
|
|
//std::foreach(map.begin(), map.end(), ...);
|
|
|
|
// This is not really needed, it will only happen on program close and in
|
|
|
|
// any case the OS will release those resources (not doing it may have
|
|
|
|
// a good effect on closing time).
|
|
|
|
|
|
|
|
delete singleton;
|
2000-07-31 16:39:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
GraphicsCacheItem *
|
2000-07-31 16:39:50 +00:00
|
|
|
GraphicsCache::addFile(string const & filename)
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
|
|
|
CacheType::const_iterator it = cache.find(filename);
|
|
|
|
|
|
|
|
if (it != cache.end()) {
|
|
|
|
return (*it).second;
|
|
|
|
}
|
2000-08-08 09:18:39 +00:00
|
|
|
|
|
|
|
GraphicsCacheItem * cacheItem = new GraphicsCacheItem();
|
|
|
|
if (cacheItem == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool result = cacheItem->setFilename(filename);
|
|
|
|
if (!result)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cache[filename] = cacheItem;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
CacheType::const_iterator it = cache.find(filename);
|
|
|
|
|
|
|
|
if (it != cache.end()) {
|
|
|
|
// INCOMPLETE!
|
|
|
|
// cache.erase(it);
|
|
|
|
}
|
|
|
|
}
|