On Tuesday 25 June 2002 5:11 pm, Andre Poenitz wrote: > On Tue, Jun 25, 2002 at 04:53:30PM +0100, Angus Leeming wrote: > > Ok, André, I've done as you desired and stripped out all the > > InsetGraphics nonsense from the graphics cache. InsetGraphics now has > > code to generate the pixmap once the file is loaded. > > Thank you. > > I'll have a look. > > Andre'
When you do, I wonder if you can think of a way of doing things a little better ;-) As the code is written at the moment, anything that uses the graphics stuff must store a local copy of GCache::graphic(file). Doing so, increments the reference count in boost::shared_ptr<GCacheItem> (the type stored in the cache) and so ensures that the item is not removed from the cache "unexpectedly". I could think of no way of hiding GCacheItem entirely. Angus /// The cache contains data of this type. typedef boost::shared_ptr<GCacheItem> GraphicPtr; class GCache : boost::noncopyable { public: /** 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! */ GraphicPtr const graphic(string const & file) const; };