VTK  9.2.6
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 
69  void AddItem(vtkObject*);
70 
75  void InsertItem(int i, vtkObject*);
76 
80  void ReplaceItem(int i, vtkObject*);
81 
89  void RemoveItem(int i);
90 
96  void RemoveItem(vtkObject*);
97 
101  void RemoveAllItems();
102 
108  int IsItemPresent(vtkObject* a);
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 
140  vtkObject* GetItemAsObject(int i);
141 
146  vtkObject* GetNextItemAsObject(vtkCollectionSimpleIterator& cookie);
147 
151  VTK_NEWINSTANCE vtkCollectionIterator* NewIterator();
152 
154 
157  bool UsesGarbageCollector() const override { return true; }
159 
160 protected:
161  vtkCollection();
162  ~vtkCollection() override;
163 
164  virtual void RemoveElement(vtkCollectionElement* element, vtkCollectionElement* previous);
165  virtual void DeleteElement(vtkCollectionElement*);
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
void * vtkCollectionSimpleIterator
Definition: vtkCollection.h:51
abstract base class for most VTK objects
Definition: vtkObject.h:62
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void InitTraversal()
Initialize the traversal of the collection.
vtkCollectionElement * Current
bool UsesGarbageCollector() const override
Participate in garbage collection.
Detect and break reference loops.
a simple class to control print indentation
Definition: vtkIndent.h:39
virtual void ReportReferences(vtkGarbageCollector *)
#define VTK_NEWINSTANCE
vtkCollectionElement * Bottom
iterator through a vtkCollection.
int GetNumberOfItems()
Return the number of objects in the list.
create and manipulate ordered lists of objects
Definition: vtkCollection.h:55
void InitTraversal(vtkCollectionSimpleIterator &cookie)
A reentrant safe way to iterate through a collection.
vtkCollectionElement * Next
Definition: vtkCollection.h:49
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkObject * GetNextItemAsObject()
Get the next item in the collection.
vtkCollectionElement * Top