VTK  9.5.20251017
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 "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_6_0
27#include "vtkObject.h"
28#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
29
30VTK_ABI_NAMESPACE_BEGIN
31class vtkCollectionElement //;prevents pick-up by man page generator
32{
33public:
35 : Item(nullptr)
36 , Next(nullptr)
37 {
38 }
41};
43
45
46class VTKCOMMONCORE_EXPORT VTK_MARSHALAUTO vtkCollection : public vtkObject
47{
48public:
49 vtkTypeMacro(vtkCollection, vtkObject);
50 void PrintSelf(ostream& os, vtkIndent indent) override;
51
55 static vtkCollection* New();
56
62
68 void InsertItem(int i, vtkObject*);
69
74 void ReplaceItem(int i, vtkObject*);
75
83 void RemoveItem(int i);
84
92
97
104 int IsItemPresent(vtkObject* a) VTK_FUTURE_CONST;
105
112 VTK_DEPRECATED_IN_9_6_0("Use correctly spelled IndexOfFirstOccurrence instead.")
113 int IndexOfFirstOccurence(vtkObject* a) VTK_FUTURE_CONST;
114
121 int IndexOfFirstOccurrence(vtkObject* a) const;
122
126 int GetNumberOfItems() VTK_FUTURE_CONST { return this->NumberOfItems; }
127
132 void InitTraversal() { this->Current = this->Top; }
133
139 {
140 cookie = static_cast<vtkCollectionSimpleIterator>(this->Top);
141 }
142
147 vtkObject* GetNextItemAsObject();
148
153 vtkObject* GetItemAsObject(int i) VTK_FUTURE_CONST;
154
159 vtkObject* GetNextItemAsObject(vtkCollectionSimpleIterator& cookie) VTK_FUTURE_CONST;
160
165
167
170 bool UsesGarbageCollector() const override { return true; }
172
173protected:
175 ~vtkCollection() override;
176
177 virtual void RemoveElement(vtkCollectionElement* element, vtkCollectionElement* previous);
183
185
186 // See vtkGarbageCollector.h:
187 void ReportReferences(vtkGarbageCollector* collector) override;
188
189private:
190 vtkCollection(const vtkCollection&) = delete;
191 void operator=(const vtkCollection&) = delete;
192};
193
195{
196 vtkCollectionElement* elem = this->Current;
197
198 if (elem != nullptr)
199 {
200 this->Current = elem->Next;
201 return elem->Item;
202 }
203 else
204 {
205 return nullptr;
206 }
207}
208
209inline vtkObject* vtkCollection::GetNextItemAsObject(void*& cookie) VTK_FUTURE_CONST
210{
211 vtkCollectionElement* elem = static_cast<vtkCollectionElement*>(cookie);
212
213 if (elem != nullptr)
214 {
215 cookie = static_cast<void*>(elem->Next);
216 return elem->Item;
217 }
218 else
219 {
220 return nullptr;
221 }
222}
223
224VTK_ABI_NAMESPACE_END
225#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
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.
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.
int IsItemPresent(vtkObject *a) VTK_FUTURE_CONST
Search for an object and return location in 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.
vtkObject * GetItemAsObject(int i) VTK_FUTURE_CONST
Get the i'th item in the collection.
virtual void DeleteElement(vtkCollectionElement *)
vtkObject * GetNextItemAsObject()
Get the next item in the collection.
vtkCollectionElement * Current
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_DEPRECATED_IN_9_6_0(reason)
#define VTK_MARSHALAUTO
#define VTK_NEWINSTANCE