VTK  9.2.6
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=========================================================================*/
30
31#ifndef vtkCollection_h
32#define vtkCollection_h
33
34#include "vtkCommonCoreModule.h" // For export macro
35#include "vtkObject.h"
36
37class vtkCollectionElement //;prevents pick-up by man page generator
38{
39public:
41 : Item(nullptr)
42 , Next(nullptr)
43 {
44 }
47};
49
51
52class VTKCOMMONCORE_EXPORT vtkCollection : public vtkObject
53{
54public:
55 vtkTypeMacro(vtkCollection, vtkObject);
56 void PrintSelf(ostream& os, vtkIndent indent) override;
57
61 static vtkCollection* New();
62
67
72 void InsertItem(int i, vtkObject*);
73
77 void ReplaceItem(int i, vtkObject*);
78
86 void RemoveItem(int i);
87
94
99
106
110 int GetNumberOfItems() { return this->NumberOfItems; }
111
116 void InitTraversal() { this->Current = this->Top; }
117
123 {
124 cookie = static_cast<vtkCollectionSimpleIterator>(this->Top);
125 }
126
131 vtkObject* GetNextItemAsObject();
132
138
144
149
151
154 bool UsesGarbageCollector() const override { return true; }
156
157protected:
159 ~vtkCollection() override;
160
161 virtual void RemoveElement(vtkCollectionElement* element, vtkCollectionElement* previous);
167
169
170 // See vtkGarbageCollector.h:
171 void ReportReferences(vtkGarbageCollector* collector) override;
172
173private:
174 vtkCollection(const vtkCollection&) = delete;
175 void operator=(const vtkCollection&) = delete;
176};
177
179{
180 vtkCollectionElement* elem = this->Current;
181
182 if (elem != nullptr)
183 {
184 this->Current = elem->Next;
185 return elem->Item;
186 }
187 else
188 {
189 return nullptr;
190 }
191}
192
194{
195 vtkCollectionElement* elem = static_cast<vtkCollectionElement*>(cookie);
196
197 if (elem != nullptr)
198 {
199 cookie = static_cast<void*>(elem->Next);
200 return elem->Item;
201 }
202 else
203 {
204 return nullptr;
205 }
206}
207
208#endif
vtkCollectionElement * Next
iterator through a vtkCollection.
bool UsesGarbageCollector() const override
Participate in garbage collection.
void ReportReferences(vtkGarbageCollector *collector) override
vtkObject * GetItemAsObject(int i)
Get the i'th item in the collection.
void RemoveItem(int i)
Remove the i'th item in the list.
~vtkCollection() override
void ReplaceItem(int i, vtkObject *)
Replace the i'th item in the collection with another item.
friend class vtkCollectionIterator
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkCollectionIterator * NewIterator()
Get an iterator to traverse the objects in this collection.
vtkCollectionElement * Bottom
void RemoveItem(vtkObject *)
Remove an object from the list.
vtkCollectionElement * Top
void AddItem(vtkObject *)
Add an object to the bottom of the list.
void InsertItem(int i, vtkObject *)
Insert item into the list after the i'th item.
void InitTraversal()
Initialize the traversal of the collection.
virtual void RemoveElement(vtkCollectionElement *element, vtkCollectionElement *previous)
void RemoveAllItems()
Remove all objects from the list.
static vtkCollection * New()
Construct with empty list.
void InitTraversal(vtkCollectionSimpleIterator &cookie)
A reentrant safe way to iterate through a collection.
virtual void DeleteElement(vtkCollectionElement *)
vtkObject * GetNextItemAsObject()
Get the next item in the collection.
int GetNumberOfItems()
Return the number of objects in the list.
vtkCollectionElement * Current
int IsItemPresent(vtkObject *a)
Search for an object and return location in list.
a simple class to control print indentation
Definition vtkIndent.h:34
friend class vtkGarbageCollector
Some classes need to clear the reference counts manually due to the way they work.
abstract base class for most VTK objects
Definition vtkObject.h:57
void * vtkCollectionSimpleIterator
#define VTK_NEWINSTANCE