VTK
vtkCollection.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkCollection.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
34 #ifndef vtkCollection_h
35 #define vtkCollection_h
36 
37 #include "vtkCommonCoreModule.h" // For export macro
38 #include "vtkObject.h"
39 
40 class vtkCollectionElement //;prevents pick-up by man page generator
41 {
42  public:
43  vtkCollectionElement():Item(nullptr),Next(nullptr) {}
46 };
48 
50 
51 class VTKCOMMONCORE_EXPORT vtkCollection : public vtkObject
52 {
53 public:
54  vtkTypeMacro(vtkCollection,vtkObject);
55  void PrintSelf(ostream& os, vtkIndent indent) override;
56 
60  static vtkCollection *New();
61 
65  void AddItem(vtkObject *);
66 
71  void InsertItem(int i, vtkObject *);
72 
76  void ReplaceItem(int i, vtkObject *);
77 
85  void RemoveItem(int i);
86 
93 
98 
105 
109  int GetNumberOfItems() { return this->NumberOfItems; }
110 
115  void InitTraversal() { this->Current = this->Top;};
116 
122  cookie = static_cast<vtkCollectionSimpleIterator>(this->Top);};
123 
128  vtkObject *GetNextItemAsObject();
129 
135 
140  vtkObject *GetNextItemAsObject(vtkCollectionSimpleIterator &cookie);
141 
146 
148 
151  void Register(vtkObjectBase* o) override;
152  void UnRegister(vtkObjectBase* o) override;
154 
155 protected:
157  ~vtkCollection() override;
158 
159  virtual void RemoveElement(vtkCollectionElement *element,
166 
167  friend class vtkCollectionIterator;
168 
169  // See vtkGarbageCollector.h:
170  void ReportReferences(vtkGarbageCollector* collector) override;
171 private:
172  vtkCollection(const vtkCollection&) = delete;
173  void operator=(const vtkCollection&) = delete;
174 };
175 
176 
178 {
179  vtkCollectionElement *elem=this->Current;
180 
181  if ( elem != nullptr )
182  {
183  this->Current = elem->Next;
184  return elem->Item;
185  }
186  else
187  {
188  return nullptr;
189  }
190 }
191 
193 {
194  vtkCollectionElement *elem=static_cast<vtkCollectionElement *>(cookie);
195 
196  if ( elem != nullptr )
197  {
198  cookie = static_cast<void *>(elem->Next);
199  return elem->Item;
200  }
201  else
202  {
203  return nullptr;
204  }
205 }
206 
207 #endif
vtkCollection::NewIterator
vtkCollectionIterator * NewIterator()
Get an iterator to traverse the objects in this collection.
vtkCollection::NumberOfItems
int NumberOfItems
Definition: vtkCollection.h:162
vtkCollection::Current
vtkCollectionElement * Current
Definition: vtkCollection.h:165
vtkCollection::RemoveElement
virtual void RemoveElement(vtkCollectionElement *element, vtkCollectionElement *previous)
vtkCollection::New
static vtkCollection * New()
Construct with empty list.
vtkCollection::DeleteElement
virtual void DeleteElement(vtkCollectionElement *)
vtkCollectionSimpleIterator
void * vtkCollectionSimpleIterator
Definition: vtkCollection.h:47
vtkCollection::InitTraversal
void InitTraversal(vtkCollectionSimpleIterator &cookie)
A reentrant safe way to iterate through a collection.
Definition: vtkCollection.h:121
vtkCollection::RemoveItem
void RemoveItem(vtkObject *)
Remove an object from the list.
vtkCollection::Register
void Register(vtkObjectBase *o) override
Participate in garbage collection.
vtkCollection::vtkCollection
vtkCollection()
vtkCollection::IsItemPresent
int IsItemPresent(vtkObject *a)
Search for an object and return location in list.
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:60
vtkCollection::ReplaceItem
void ReplaceItem(int i, vtkObject *)
Replace the i'th item in the collection with another item.
vtkCollectionElement::Item
vtkObject * Item
Definition: vtkCollection.h:44
vtkCollectionElement::vtkCollectionElement
vtkCollectionElement()
Definition: vtkCollection.h:43
vtkCollection::GetNumberOfItems
int GetNumberOfItems()
Return the number of objects in the list.
Definition: vtkCollection.h:109
vtkCollection::GetNextItemAsObject
vtkObject * GetNextItemAsObject()
Get the next item in the collection.
Definition: vtkCollection.h:177
vtkCollectionElement::Next
vtkCollectionElement * Next
Definition: vtkCollection.h:45
vtkCollection
create and manipulate ordered lists of objects
Definition: vtkCollection.h:52
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:66
vtkCollectionIterator
iterator through a vtkCollection.
Definition: vtkCollectionIterator.h:38
vtkCollection::Bottom
vtkCollectionElement * Bottom
Definition: vtkCollection.h:164
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkCollection::UnRegister
void UnRegister(vtkObjectBase *o) override
Decrease the reference count (release by another object).
vtkCollection::InsertItem
void InsertItem(int i, vtkObject *)
Insert item into the list after the i'th item.
vtkCollection::GetItemAsObject
vtkObject * GetItemAsObject(int i)
Get the i'th item in the collection.
vtkCollection::ReportReferences
void ReportReferences(vtkGarbageCollector *collector) override
vtkGarbageCollector
Detect and break reference loops.
Definition: vtkGarbageCollector.h:100
vtkObject.h
vtkCollection::RemoveAllItems
void RemoveAllItems()
Remove all objects from the list.
vtkCollection::RemoveItem
void RemoveItem(int i)
Remove the i'th item in the list.
vtkX3D::previous
@ previous
Definition: vtkX3D.h:449
vtkCollection::AddItem
void AddItem(vtkObject *)
Add an object to the bottom of the list.
vtkCollection::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkCollection::InitTraversal
void InitTraversal()
Initialize the traversal of the collection.
Definition: vtkCollection.h:115
vtkCollectionElement
Definition: vtkCollection.h:41
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:39
vtkCollection::Top
vtkCollectionElement * Top
Definition: vtkCollection.h:163
vtkCollection::~vtkCollection
~vtkCollection() override