]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCacheItem.C
Cleaned up cruft in InsetGraphics.
[lyx.git] / src / graphics / GraphicsCacheItem.C
1 // -*- C++ -*-
2 /* This file is part of
3  * =================================================
4  * 
5  *          LyX, The Document Processor
6  *          Copyright 1995 Matthias Ettrich.
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  *          This file Copyright 2000 Baruch Even
10  * ================================================= */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "graphics/GraphicsCache.h"
19 #include "graphics/GraphicsCacheItem.h"
20 #include "graphics/GraphicsCacheItem_pimpl.h"
21 #include "frontends/support/LyXImage.h"
22
23
24 GraphicsCacheItem::GraphicsCacheItem()
25         : pimpl(new GraphicsCacheItem_pimpl)
26 {
27         pimpl->refCount = 1;
28 }
29
30
31 GraphicsCacheItem::~GraphicsCacheItem()
32 {
33         destroy();
34 }
35
36
37 bool
38 GraphicsCacheItem::setFilename(string const & filename)
39 {
40         filename_ = filename;
41         return pimpl->setFilename(filename);
42 }
43
44
45 GraphicsCacheItem::GraphicsCacheItem(GraphicsCacheItem const & gci)
46         : pimpl(0)
47 {
48         // copy will set the actual value of the pimpl.
49         copy(gci);
50 }
51
52 GraphicsCacheItem &
53 GraphicsCacheItem::operator=(GraphicsCacheItem const & gci)
54 {
55         // Are we trying to copy the object onto itself.
56         if (this == &gci)
57                 return *this;
58
59         // Destroy old copy 
60         destroy();
61
62         // And then copy new object.
63         copy(gci);
64
65         return *this;
66 }
67
68 GraphicsCacheItem *
69 GraphicsCacheItem::Clone() const
70 {
71         return new GraphicsCacheItem(*this);
72 }
73
74 void
75 GraphicsCacheItem::copy(GraphicsCacheItem const & gci)
76 {
77         pimpl = gci.pimpl;
78         ++(pimpl->refCount);
79 }
80
81
82 void
83 GraphicsCacheItem::destroy()
84 {
85         if (pimpl) {
86                 --(pimpl->refCount);
87                 if (pimpl->refCount == 0) {
88                         {   // We are deleting the pimpl but we want to mark it deleted
89                                 // even before it is deleted.
90                                 GraphicsCacheItem_pimpl * temp = pimpl;
91                                 pimpl = 0;
92                                 delete temp; temp = 0;
93                         }
94                         GraphicsCache * gc = GraphicsCache::getInstance();
95                         gc->removeFile(filename_);
96                 }
97         }
98 }
99
100
101 GraphicsCacheItem::ImageStatus 
102 GraphicsCacheItem::getImageStatus() const { return pimpl->imageStatus_; }
103
104 LyXImage * 
105 GraphicsCacheItem::getImage() const { return pimpl->getImage(); }