VTK  9.2.20220705
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 class vtkCollectionElement //;prevents pick-up by man page generator
41 {
42 public:
44  : Item(nullptr)
45  , Next(nullptr)
46  {
47  }
50 };
52 
54 
55 class VTKCOMMONCORE_EXPORT vtkCollection : public vtkObject
56 {
57 public:
58  vtkTypeMacro(vtkCollection, vtkObject);
59  void PrintSelf(ostream& os, vtkIndent indent) override;
60 
64  static vtkCollection* New();
65 
70 
75  void InsertItem(int i, vtkObject*);
76 
80  void ReplaceItem(int i, vtkObject*);
81 
89  void RemoveItem(int i);
90 
97 
102 
109 
113  int GetNumberOfItems() { return this->NumberOfItems; }
114 
119  void InitTraversal() { this->Current = this->Top; }
120 
126  {
127  cookie = static_cast<vtkCollectionSimpleIterator>(this->Top);
128  }
129 
134  vtkObject* GetNextItemAsObject();
135 
141 
146  vtkObject* GetNextItemAsObject(vtkCollectionSimpleIterator& cookie);
147 
152 
154 
157  bool UsesGarbageCollector() const override { return true; }
159 
160 protected:
162  ~vtkCollection() override;
163 
170 
171  friend class vtkCollectionIterator;
172 
173  // See vtkGarbageCollector.h:
174  void ReportReferences(vtkGarbageCollector* collector) override;
175 
176 private:
177  vtkCollection(const vtkCollection&) = delete;
178  void operator=(const vtkCollection&) = delete;
179 };
180 
182 {
183  vtkCollectionElement* elem = this->Current;
184 
185  if (elem != nullptr)
186  {
187  this->Current = elem->Next;
188  return elem->Item;
189  }
190  else
191  {
192  return nullptr;
193  }
194 }
195 
197 {
198  vtkCollectionElement* elem = static_cast<vtkCollectionElement*>(cookie);
199 
200  if (elem != nullptr)
201  {
202  cookie = static_cast<void*>(elem->Next);
203  return elem->Item;
204  }
205  else
206  {
207  return nullptr;
208  }
209 }
210 
211 #endif
vtkCollectionElement * Next
Definition: vtkCollection.h:49
iterator through a vtkCollection.
create and manipulate ordered lists of objects
Definition: vtkCollection.h:56
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:119
abstract base class for most VTK objects
Definition: vtkObject.h:82
@ previous
Definition: vtkX3D.h:455
void * vtkCollectionSimpleIterator
Definition: vtkCollection.h:51
#define VTK_NEWINSTANCE