]> git.lyx.org Git - lyx.git/commitdiff
Changed the singleton implementation in GraphicsCache, the former version
authorBaruch Even <baruch@lyx.org>
Wed, 28 Feb 2001 11:32:10 +0000 (11:32 +0000)
committerBaruch Even <baruch@lyx.org>
Wed, 28 Feb 2001 11:32:10 +0000 (11:32 +0000)
leaked, in the sense that it was not deallocated at program end.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1640 a592a061-630c-0410-9148-cb99ea01b6c8

src/graphics/ChangeLog
src/graphics/GraphicsCache.C
src/graphics/GraphicsCache.h
src/insets/ChangeLog
src/insets/insetgraphics.C

index 9cedf2bc33fbb3d0c7e0d6bd437f371368fcfbb2..16696974eaa521063f9645e88a06539cc79dc09e 100644 (file)
@@ -1,3 +1,10 @@
+2001-02-28  Baruch Even  <baruch@ev-en.org>
+
+       * GraphicsCache.h:
+       * GraphicsCache.C: Changed the singleton pattern implementation, the
+       former version "leaked" in the sense that it was not deallocated at
+       program end.
+
 2001-02-20  Baruch Even  <baruch@ev-en.org>
 
        * GraphicsCache.C: Changed to use shared_ptr<GraphicsCacheItem>
index a2bed25973dfa2751e63849a5eef36e09052df94..cda36db9fc6b13059ce32149e82567222408a171 100644 (file)
 
 #include "support/LAssert.h"
 
-GraphicsCache * GraphicsCache::singleton = 0;
-
-
-GraphicsCache * 
+GraphicsCache &
 GraphicsCache::getInstance()
 {
-       if (!singleton) {
-               singleton = new GraphicsCache;
-               Assert(singleton != 0);
-       }
-
+       static GraphicsCache singleton;
        return singleton;
 }
 
@@ -39,8 +32,6 @@ GraphicsCache::~GraphicsCache()
 {
        // The map elements should have already been eliminated.
        Assert(cache.empty());
-       
-       delete singleton;
 }
 
 
index 3f28d385cc0b45f80767877a66091d8e56d16776..240157992b7d0ea161a2c1364dd3f0a2cb7f01d0 100644 (file)
@@ -34,7 +34,9 @@ class GraphicsCacheItem;
 class GraphicsCache : public noncopyable {
 public:
        /// Get the instance of the class.
-       static GraphicsCache * getInstance();
+       static GraphicsCache & getInstance();
+       /// Public destructor due to compiler warnings.
+       ~GraphicsCache();
 
        typedef boost::shared_ptr<GraphicsCacheItem> shared_ptr_item;
 
@@ -48,11 +50,6 @@ private:
        /// Private c-tor so we can control how many objects are instantiated.
        GraphicsCache() {}
        
-       /// Private d-tor so that no-one will destroy us.
-       ~GraphicsCache();
-       
-       /// Holder of the single instance of the class.
-       static GraphicsCache * singleton;
        ///
        typedef std::map<string, shared_ptr_item> CacheType;
        ///
index 57f3a521c66d4540d5794e22054037f60cb41646..e31a6069ed7a5fe75bf1b7a8941a9656458ee650 100644 (file)
@@ -1,3 +1,8 @@
+2001-02-28  Baruch Even  <baruch@ev-en.org>
+
+       * insetgraphics.C (updateInset): Changed due to the change in
+       GraphicsCache.
+
 2001-02-26  Juergen Vigna  <jug@sad.it>
 
        * insettext.C (SetFont): Set Undo only if we have selection (as it is
index 5ea6f7c08596630269fd08875ee81e699905fac8..cb77d328710cf614dfae934a3c6babef9fc470aa 100644 (file)
@@ -575,13 +575,13 @@ void InsetGraphics::Validate(LaTeXFeatures & features) const
 // dialog.
 void InsetGraphics::updateInset() const
 {
-       GraphicsCache * gc = GraphicsCache::getInstance();
+       GraphicsCache & gc = GraphicsCache::getInstance();
        boost::shared_ptr<GraphicsCacheItem> temp(0);
 
        // We do it this way so that in the face of some error, we will still
        // be in a valid state.
        if (!params.filename.empty()) {
-               temp = gc->addFile(params.filename);
+               temp = gc.addFile(params.filename);
        }
 
        // Mark the image as unloaded so that it gets updated.