VTK  9.2.20230401
vtkCollection.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkCollection.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
34 #ifndef vtkCollection_h
35 #define vtkCollection_h
36 
37 #include "vtkCommonCoreModule.h" // For export macro
38 #include "vtkObject.h"
39 
40 VTK_ABI_NAMESPACE_BEGIN
41 class vtkCollectionElement //;prevents pick-up by man page generator
42 {
43 public:
45  : Item(nullptr)
46  , Next(nullptr)
47  {
48  }
51 };
53 
55 
56 class VTKCOMMONCORE_EXPORT vtkCollection : public vtkObject
57 {
58 public:
59  vtkTypeMacro(vtkCollection, vtkObject);
60  void PrintSelf(ostream& os, vtkIndent indent) override;
61 
65  static vtkCollection* New();
66 
71 
76  void InsertItem(int i, vtkObject*);
77 
81  void ReplaceItem(int i, vtkObject*);
82 
90  void RemoveItem(int i);
91 
98 
103 
110 
114  int GetNumberOfItems() { return this->NumberOfItems; }
115 
120  void InitTraversal() { this->Current = this->Top; }
121 
127  {
128  cookie = static_cast<vtkCollectionSimpleIterator>(this->Top);
129  }
130 
135  vtkObject* GetNextItemAsObject();
136 
142 
147  vtkObject* GetNextItemAsObject(vtkCollectionSimpleIterator& cookie);
148 
153 
155 
158  bool UsesGarbageCollector() const override { return true; }
160 
161 protected:
163  ~vtkCollection() override;
164 
171 
172  friend class vtkCollectionIterator;
173 
174  // See vtkGarbageCollector.h:
175  void ReportReferences(vtkGarbageCollector* collector) override;
176 
177 private:
178  vtkCollection(const vtkCollection&) = delete;
179  void operator=(const vtkCollection&) = delete;
180 };
181 
183 {
184  vtkCollectionElement* elem = this->Current;
185 
186  if (elem != nullptr)
187  {
188  this->Current = elem->Next;
189  return elem->Item;
190  }
191  else
192  {
193  return nullptr;
194  }
195 }
196 
198 {
199  vtkCollectionElement* elem = static_cast<vtkCollectionElement*>(cookie);
200 
201  if (elem != nullptr)
202  {
203  cookie = static_cast<void*>(elem->Next);
204  return elem->Item;
205  }
206  else
207  {
208  return nullptr;
209  }
210 }
211 
212 VTK_ABI_NAMESPACE_END
213 #endif
vtkCollectionElement * Next
Definition: vtkCollection.h:50
iterator through a vtkCollection.
create and manipulate ordered lists of objects
Definition: vtkCollection.h:57
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.
~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:120
abstract base class for most VTK objects
Definition: vtkObject.h:83
@ previous
Definition: vtkX3D.h:461
void * vtkCollectionSimpleIterator
Definition: vtkCollection.h:52
#define VTK_NEWINSTANCE