VTK
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:
43  vtkCollectionElement():Item(nullptr),Next(nullptr) {}
46 };
48 
50 
51 class VTKCOMMONCORE_EXPORT vtkCollection : public vtkObject
52 {
53 public:
54  vtkTypeMacro(vtkCollection,vtkObject);
55  void PrintSelf(ostream& os, vtkIndent indent) override;
56 
60  static vtkCollection *New();
61 
65  void AddItem(vtkObject *);
66 
71  void InsertItem(int i, vtkObject *);
72 
76  void ReplaceItem(int i, vtkObject *);
77 
85  void RemoveItem(int i);
86 
92  void RemoveItem(vtkObject *);
93 
97  void RemoveAllItems();
98 
104  int IsItemPresent(vtkObject *a);
105 
109  int GetNumberOfItems() { return this->NumberOfItems; }
110 
115  void InitTraversal() { this->Current = this->Top;};
116 
122  cookie = static_cast<vtkCollectionSimpleIterator>(this->Top);};
123 
128  vtkObject *GetNextItemAsObject();
129 
134  vtkObject *GetItemAsObject(int i);
135 
140  vtkObject *GetNextItemAsObject(vtkCollectionSimpleIterator &cookie);
141 
145  VTK_NEWINSTANCE vtkCollectionIterator* NewIterator();
146 
148 
151  void Register(vtkObjectBase* o) override;
152  void UnRegister(vtkObjectBase* o) override;
154 
155 protected:
156  vtkCollection();
157  ~vtkCollection() override;
158 
159  virtual void RemoveElement(vtkCollectionElement *element,
161  virtual void DeleteElement(vtkCollectionElement *);
166 
167  friend class vtkCollectionIterator;
168 
169  // See vtkGarbageCollector.h:
170  void ReportReferences(vtkGarbageCollector* collector) override;
171 private:
172  vtkCollection(const vtkCollection&) = delete;
173  void operator=(const vtkCollection&) = delete;
174 };
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 #endif
void * vtkCollectionSimpleIterator
Definition: vtkCollection.h:47
abstract base class for most VTK objects
Definition: vtkObject.h:59
void InitTraversal()
Initialize the traversal of the collection.
vtkCollectionElement * Current
Detect and break reference loops.
a simple class to control print indentation
Definition: vtkIndent.h:39
virtual void ReportReferences(vtkGarbageCollector *)
abstract base class for most VTK objects
Definition: vtkObjectBase.h:65
#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:51
void InitTraversal(vtkCollectionSimpleIterator &cookie)
A reentrant safe way to iterate through a collection.
vtkCollectionElement * Next
Definition: vtkCollection.h:45
vtkObject * GetNextItemAsObject()
Get the next item in the collection.
vtkCollectionElement * Top