VTK  9.5.20250812
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
61
67 void InsertItem(int i, vtkObject*);
68
73 void ReplaceItem(int i, vtkObject*);
74
82 void RemoveItem(int i);
83
91
96
103 int IsItemPresent(vtkObject* a) VTK_FUTURE_CONST;
104
111 int IndexOfFirstOccurence(vtkObject* a) VTK_FUTURE_CONST;
112
116 int GetNumberOfItems() VTK_FUTURE_CONST { return this->NumberOfItems; }
117
122 void InitTraversal() { this->Current = this->Top; }
123
129 {
130 cookie = static_cast<vtkCollectionSimpleIterator>(this->Top);
131 }
132
137 vtkObject* GetNextItemAsObject();
138
143 vtkObject* GetItemAsObject(int i) VTK_FUTURE_CONST;
144
149 vtkObject* GetNextItemAsObject(vtkCollectionSimpleIterator& cookie) VTK_FUTURE_CONST;
150
155
157
160 bool UsesGarbageCollector() const override { return true; }
162
163protected:
165 ~vtkCollection() override;
166
167 virtual void RemoveElement(vtkCollectionElement* element, vtkCollectionElement* previous);
173
175
176 // See vtkGarbageCollector.h:
177 void ReportReferences(vtkGarbageCollector* collector) override;
178
179private:
180 vtkCollection(const vtkCollection&) = delete;
181 void operator=(const vtkCollection&) = delete;
182};
183
185{
186 vtkCollectionElement* elem = this->Current;
187
188 if (elem != nullptr)
189 {
190 this->Current = elem->Next;
191 return elem->Item;
192 }
193 else
194 {
195 return nullptr;
196 }
197}
198
199inline vtkObject* vtkCollection::GetNextItemAsObject(void*& cookie) VTK_FUTURE_CONST
200{
201 vtkCollectionElement* elem = static_cast<vtkCollectionElement*>(cookie);
202
203 if (elem != nullptr)
204 {
205 cookie = static_cast<void*>(elem->Next);
206 return elem->Item;
207 }
208 else
209 {
210 return nullptr;
211 }
212}
213
214VTK_ABI_NAMESPACE_END
215#endif
vtkCollectionElement * Next
iterator through a vtkCollection.
create and manipulate ordered lists of objects
bool UsesGarbageCollector() const override
Participate in garbage collection.
int IndexOfFirstOccurence(vtkObject *a) VTK_FUTURE_CONST
Search for an object and return location in list.
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.
int GetNumberOfItems() VTK_FUTURE_CONST
Return the number of objects in the list.
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_MARSHALAUTO
#define VTK_NEWINSTANCE