VTK  9.3.20240328
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 
28 VTK_ABI_NAMESPACE_BEGIN
29 class vtkCollectionElement //;prevents pick-up by man page generator
30 {
31 public:
33  : Item(nullptr)
34  , Next(nullptr)
35  {
36  }
39 };
41 
43 
44 class VTKCOMMONCORE_EXPORT vtkCollection : public vtkObject
45 {
46 public:
47  vtkTypeMacro(vtkCollection, vtkObject);
48  void PrintSelf(ostream& os, vtkIndent indent) override;
49 
53  static vtkCollection* New();
54 
59 
64  void InsertItem(int i, vtkObject*);
65 
69  void ReplaceItem(int i, vtkObject*);
70 
78  void RemoveItem(int i);
79 
86 
91 
98 
105 
109  int GetNumberOfItems() { return this->NumberOfItems; }
110 
115  void InitTraversal() { this->Current = this->Top; }
116 
122  {
123  cookie = static_cast<vtkCollectionSimpleIterator>(this->Top);
124  }
125 
130  vtkObject* GetNextItemAsObject();
131 
137 
142  vtkObject* GetNextItemAsObject(vtkCollectionSimpleIterator& cookie);
143 
148 
150 
153  bool UsesGarbageCollector() const override { return true; }
155 
156 protected:
158  ~vtkCollection() override;
159 
166 
167  friend class vtkCollectionIterator;
168 
169  // See vtkGarbageCollector.h:
170  void ReportReferences(vtkGarbageCollector* collector) override;
171 
172 private:
173  vtkCollection(const vtkCollection&) = delete;
174  void operator=(const vtkCollection&) = delete;
175 };
176 
178 {
179  vtkCollectionElement* elem = this->Current;
180 
181  if (elem != nullptr)
182  {
183  this->Current = elem->Next;
184  return elem->Item;
185  }
186  else
187  {
188  return nullptr;
189  }
190 }
191 
193 {
194  vtkCollectionElement* elem = static_cast<vtkCollectionElement*>(cookie);
195 
196  if (elem != nullptr)
197  {
198  cookie = static_cast<void*>(elem->Next);
199  return elem->Item;
200  }
201  else
202  {
203  return nullptr;
204  }
205 }
206 
207 VTK_ABI_NAMESPACE_END
208 #endif
vtkCollectionElement * Next
Definition: vtkCollection.h:38
iterator through a vtkCollection.
create and manipulate ordered lists of objects
Definition: vtkCollection.h:45
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.
vtkCollectionIterator * NewIterator()
Get an iterator to traverse the objects in this 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.
static vtkCollection * New()
Construct with empty list.
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.
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:161
@ previous
Definition: vtkX3D.h:449
void * vtkCollectionSimpleIterator
Definition: vtkCollection.h:40
#define VTK_NEWINSTANCE