VTK  9.3.20240612
vtkCollection.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
22#ifndef vtkCollection_h
23#define vtkCollection_h
24
25#include "vtkCommonCoreModule.h" // For export macro
26#include "vtkObject.h"
27#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
28
29VTK_ABI_NAMESPACE_BEGIN
30class vtkCollectionElement //;prevents pick-up by man page generator
31{
32public:
34 : Item(nullptr)
35 , Next(nullptr)
36 {
37 }
40};
42
44
45class VTKCOMMONCORE_EXPORT VTK_MARSHALAUTO vtkCollection : public vtkObject
46{
47public:
48 vtkTypeMacro(vtkCollection, vtkObject);
49 void PrintSelf(ostream& os, vtkIndent indent) override;
50
54 static vtkCollection* New();
55
60
65 void InsertItem(int i, vtkObject*);
66
70 void ReplaceItem(int i, vtkObject*);
71
79 void RemoveItem(int i);
80
87
92
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
143 vtkObject* GetNextItemAsObject(vtkCollectionSimpleIterator& cookie);
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
208VTK_ABI_NAMESPACE_END
209#endif
vtkCollectionElement * Next
iterator through a vtkCollection.
create and manipulate ordered lists of objects
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.
int IndexOfFirstOccurence(vtkObject *a)
Search for an object and return location in list.
~vtkCollection() override
void ReplaceItem(int i, vtkObject *)
Replace the i'th item in the collection with another item.
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.
Detect and break reference loops.
a simple class to control print indentation
Definition vtkIndent.h:108
abstract base class for most VTK objects
Definition vtkObject.h:162
void * vtkCollectionSimpleIterator
#define VTK_MARSHALAUTO
#define VTK_NEWINSTANCE