VTK  9.6.20260108
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
21
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
64
73 void InsertItem(int i, vtkObject*);
74
82 void ReplaceItem(int i, vtkObject*);
83
89 void RemoveItem(int i);
90
100
107
113 int IsItemPresent(vtkObject* a) VTK_FUTURE_CONST;
114
118 VTK_DEPRECATED_IN_9_6_0("Use correctly spelled IndexOfFirstOccurrence instead.")
119 int IndexOfFirstOccurence(vtkObject* a) VTK_FUTURE_CONST;
120
127
131 int GetNumberOfItems() VTK_FUTURE_CONST { return this->NumberOfItems; }
132
137 vtkObject* GetItemAsObject(int i) VTK_FUTURE_CONST;
138
143 void InitTraversal() { this->Current = this->Top; }
144
150 {
151 cookie = static_cast<vtkCollectionSimpleIterator>(this->Top);
152 }
153
158 vtkObject* GetNextItemAsObject();
159
164 vtkObject* GetNextItemAsObject(vtkCollectionSimpleIterator& cookie) VTK_FUTURE_CONST;
165
170
172
175 bool UsesGarbageCollector() const override { return true; }
177
178protected:
180 ~vtkCollection() override;
181
182 virtual void RemoveElement(vtkCollectionElement* element, vtkCollectionElement* previous);
188
190
191 // See vtkGarbageCollector.h:
192 void ReportReferences(vtkGarbageCollector* collector) override;
193
194private:
195 vtkCollection(const vtkCollection&) = delete;
196 void operator=(const vtkCollection&) = delete;
197};
198
200{
201 vtkCollectionElement* elem = this->Current;
202
203 if (elem != nullptr)
204 {
205 this->Current = elem->Next;
206 return elem->Item;
207 }
208 else
209 {
210 return nullptr;
211 }
212}
213
215 vtkCollectionSimpleIterator& cookie) VTK_FUTURE_CONST
216{
217 vtkCollectionElement* elem = static_cast<vtkCollectionElement*>(cookie);
218
219 if (elem != nullptr)
220 {
221 cookie = static_cast<vtkCollectionSimpleIterator>(elem->Next);
222 return elem->Item;
223 }
224 else
225 {
226 return nullptr;
227 }
228}
229
230VTK_ABI_NAMESPACE_END
231#endif
vtkCollectionElement * Next
iterator through a vtkCollection.
bool UsesGarbageCollector() const override
Participate in garbage collection.
int IndexOfFirstOccurence(vtkObject *a) VTK_FUTURE_CONST
Just calls IndexOfFirstOccurrence.
void ReportReferences(vtkGarbageCollector *collector) override
void RemoveItem(int i)
Remove the i'th item in the collection.
~vtkCollection() override
void ReplaceItem(int i, vtkObject *)
Replace the i'th item in the collection with the given item.
friend class vtkCollectionIterator
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int IndexOfFirstOccurrence(vtkObject *a) const
Search for the given item and return the 0-based index of its first occurrence in the collection.
vtkCollectionIterator * NewIterator()
Get an iterator to traverse the items in this collection.
vtkCollectionElement * Bottom
void RemoveItem(vtkObject *)
Remove the first occurrence of the given item from the collection.
int IsItemPresent(vtkObject *a) VTK_FUTURE_CONST
Search for the given item and return the 1-based index of its first occurrence in the collection.
vtkCollectionElement * Top
void AddItem(vtkObject *)
Add given item to the bottom (end) of the collection.
void InsertItem(int i, vtkObject *)
Insert given item into the collection after the i'th item.
void InitTraversal()
Initialize the traversal of the collection.
virtual void RemoveElement(vtkCollectionElement *element, vtkCollectionElement *previous)
void RemoveAllItems()
Remove all items from the collection.
static vtkCollection * New()
Construct an empty collection.
void InitTraversal(vtkCollectionSimpleIterator &cookie)
A reentrant safe way to iterate through a collection.
int GetNumberOfItems() VTK_FUTURE_CONST
Return the number of items in the 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
a simple class to control print indentation
Definition vtkIndent.h:108
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:162
void * vtkCollectionSimpleIterator
#define VTK_DEPRECATED_IN_9_6_0(reason)
#define VTK_MARSHALAUTO
#define VTK_NEWINSTANCE