1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/*=========================================================================
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.kitware.com/VolViewCopyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkVVSnapshotPool.h"
#include "vtkObjectFactory.h"
#include "vtkVVSnapshot.h"
#include <vtksys/stl/vector>
//---------------------------------------------------------------------------
vtkStandardNewMacro(vtkVVSnapshotPool);
vtkCxxRevisionMacro(vtkVVSnapshotPool, "$Revision: 1.5 $");
#ifdef KWCommonPro_USE_XML_RW
#include "XML/vtkXMLVVSnapshotPoolReader.h"
#include "XML/vtkXMLVVSnapshotPoolWriter.h"
#endif
vtkKWGetXMLReaderWriterObjectsImplementationMacro(vtkVVSnapshotPool, vtkXMLVVSnapshotPoolReader, vtkXMLVVSnapshotPoolWriter);
//----------------------------------------------------------------------------
class vtkVVSnapshotPoolInternals
{
public:
// Snapshots
typedef vtksys_stl::vector<vtkVVSnapshot*> SnapshotPoolType;
typedef vtksys_stl::vector<vtkVVSnapshot*>::iterator SnapshotPoolIterator;
SnapshotPoolType SnapshotPool;
};
//----------------------------------------------------------------------------
vtkVVSnapshotPool::vtkVVSnapshotPool()
{
this->Internals = new vtkVVSnapshotPoolInternals;
}
//----------------------------------------------------------------------------
vtkVVSnapshotPool::~vtkVVSnapshotPool()
{
// Delete our pool
if (this->Internals)
{
this->RemoveAllSnapshots(); // Note that this call this->Initialize()
delete this->Internals;
}
}
//----------------------------------------------------------------------------
int vtkVVSnapshotPool::GetNumberOfSnapshots()
{
if (this->Internals)
{
return (int)this->Internals->SnapshotPool.size();
}
return 0;
}
//----------------------------------------------------------------------------
vtkVVSnapshot *vtkVVSnapshotPool::GetNthSnapshot(int i)
{
// Get the ith snapshot
if (i < 0 || i >= this->GetNumberOfSnapshots() || !this->Internals)
{
vtkErrorMacro("Index out of range");
return NULL;
}
return this->Internals->SnapshotPool[i];
}
//----------------------------------------------------------------------------
int vtkVVSnapshotPool::HasSnapshot(vtkVVSnapshot *snapshot)
{
if (snapshot)
{
vtkVVSnapshotPoolInternals::SnapshotPoolIterator it =
this->Internals->SnapshotPool.begin();
vtkVVSnapshotPoolInternals::SnapshotPoolIterator end =
this->Internals->SnapshotPool.end();
for (; it != end; ++it)
{
if ((*it) == snapshot)
{
return 1;
}
}
}
return 0;
}
//----------------------------------------------------------------------------
int vtkVVSnapshotPool::GetIndexOfSnapshot(vtkVVSnapshot *snapshot)
{
int r = 0;
if (snapshot)
{
vtkVVSnapshotPoolInternals::SnapshotPoolIterator it =
this->Internals->SnapshotPool.begin();
vtkVVSnapshotPoolInternals::SnapshotPoolIterator end =
this->Internals->SnapshotPool.end();
for (; it != end; ++it)
{
if ((*it) == snapshot)
{
return r;
}
++r;
}
}
return -1;
}
//----------------------------------------------------------------------------
void vtkVVSnapshotPool::RemoveAllSnapshots()
{
if (this->Internals)
{
// Inefficient but there is too many things to do in RemoveSnapshot,
// let's not duplicate and go out of sync
while (this->Internals->SnapshotPool.size())
{
this->RemoveSnapshot(
(*this->Internals->SnapshotPool.begin()));
}
}
}
//----------------------------------------------------------------------------
void vtkVVSnapshotPool::RemoveSnapshot(vtkVVSnapshot *snapshot)
{
if (!snapshot)
{
return;
}
// Remove snapshot
vtkObject *obj;
vtkVVSnapshotPoolInternals::SnapshotPoolIterator it =
this->Internals->SnapshotPool.begin();
vtkVVSnapshotPoolInternals::SnapshotPoolIterator end =
this->Internals->SnapshotPool.end();
for (; it != end; ++it)
{
if ((*it) == snapshot)
{
obj = (vtkObject*)(*it);
(*it)->UnRegister(this);
this->Internals->SnapshotPool.erase(it);
break;
}
}
}
//----------------------------------------------------------------------------
int vtkVVSnapshotPool::AddSnapshot(vtkVVSnapshot *snapshot)
{
if (!snapshot)
{
vtkErrorMacro("can not add NULL snapshot to pool!");
return 0;
}
// Already in the pool ?
if (this->HasSnapshot(snapshot))
{
vtkErrorMacro("The snapshot is already in the pool!");
return 0;
}
this->Internals->SnapshotPool.push_back(snapshot);
snapshot->Register(this);
return 1;
}
//----------------------------------------------------------------------------
void vtkVVSnapshotPool::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Snapshots (" << this->GetNumberOfSnapshots() << "):\n";
indent = indent.GetNextIndent();
for (int i = 0; i < this->GetNumberOfSnapshots(); i++)
{
vtkVVSnapshot *snapshot = this->GetNthSnapshot(i);
os << indent << "Snapshot #" << i << ": " << snapshot << endl;
snapshot->PrintSelf(os, indent);
}
}
|