VTK  9.0.20210614
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 =========================================================================*/
31 #ifndef vtkCollection_h
32 #define vtkCollection_h
33 
34 #include "vtkCommonCoreModule.h" // For export macro
35 #include "vtkObject.h"
36 
37 class vtkCollectionElement //;prevents pick-up by man page generator
38 {
39 public:
41  : Item(nullptr)
42  , Next(nullptr)
43  {
44  }
47 };
49 
51 
52 class VTKCOMMONCORE_EXPORT vtkCollection : public vtkObject
53 {
54 public:
55  vtkTypeMacro(vtkCollection, vtkObject);
56  void PrintSelf(ostream& os, vtkIndent indent) override;
57 
61  static vtkCollection* New();
62 
67 
72  void InsertItem(int i, vtkObject*);
73 
77  void ReplaceItem(int i, vtkObject*);
78 
86  void RemoveItem(int i);
87 
94 
99 
106 
110  int GetNumberOfItems() { return this->NumberOfItems; }
111 
116  void InitTraversal() { this->Current = this->Top; }
117 
123  {
124  cookie = static_cast<vtkCollectionSimpleIterator>(this->Top);
125  }
126 
131  vtkObject* GetNextItemAsObject();
132 
138 
143  vtkObject* GetNextItemAsObject(vtkCollectionSimpleIterator& cookie);
144 
149 
151 
154  void Register(vtkObjectBase* o) override;
155  void UnRegister(vtkObjectBase* o) override;
157 
158 protected:
160  ~vtkCollection() override;
161 
168 
169  friend class vtkCollectionIterator;
170 
171  // See vtkGarbageCollector.h:
172  void ReportReferences(vtkGarbageCollector* collector) override;
173 
174 private:
175  vtkCollection(const vtkCollection&) = delete;
176  void operator=(const vtkCollection&) = delete;
177 };
178 
180 {
181  vtkCollectionElement* elem = this->Current;
182 
183  if (elem != nullptr)
184  {
185  this->Current = elem->Next;
186  return elem->Item;
187  }
188  else
189  {
190  return nullptr;
191  }
192 }
193 
195 {
196  vtkCollectionElement* elem = static_cast<vtkCollectionElement*>(cookie);
197 
198  if (elem != nullptr)
199  {
200  cookie = static_cast<void*>(elem->Next);
201  return elem->Item;
202  }
203  else
204  {
205  return nullptr;
206  }
207 }
208 
209 #endif
vtkCollection::NewIterator
vtkCollectionIterator * NewIterator()
Get an iterator to traverse the objects in this collection.
vtkCollection::NumberOfItems
int NumberOfItems
Definition: vtkCollection.h:164
vtkCollection::Current
vtkCollectionElement * Current
Definition: vtkCollection.h:167
vtkCollection::RemoveElement
virtual void RemoveElement(vtkCollectionElement *element, vtkCollectionElement *previous)
vtkCollection::New
static vtkCollection * New()
Construct with empty list.
vtkCollection::DeleteElement
virtual void DeleteElement(vtkCollectionElement *)
vtkCollectionSimpleIterator
void * vtkCollectionSimpleIterator
Definition: vtkCollection.h:48
vtkCollection::InitTraversal
void InitTraversal(vtkCollectionSimpleIterator &cookie)
A reentrant safe way to iterate through a collection.
Definition: vtkCollection.h:122
vtkCollection::RemoveItem
void RemoveItem(vtkObject *)
Remove an object from the list.
vtkCollection::Register
void Register(vtkObjectBase *o) override
Participate in garbage collection.
vtkCollection::vtkCollection
vtkCollection()
vtkCollection::IsItemPresent
int IsItemPresent(vtkObject *a)
Search for an object and return location in list.
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:63
vtkCollection::ReplaceItem
void ReplaceItem(int i, vtkObject *)
Replace the i'th item in the collection with another item.
vtkCollectionElement::Item
vtkObject * Item
Definition: vtkCollection.h:45
vtkCollectionElement::vtkCollectionElement
vtkCollectionElement()
Definition: vtkCollection.h:40
vtkCollection::GetNumberOfItems
int GetNumberOfItems()
Return the number of objects in the list.
Definition: vtkCollection.h:110
vtkCollection::GetNextItemAsObject
vtkObject * GetNextItemAsObject()
Get the next item in the collection.
Definition: vtkCollection.h:179
vtkCollectionElement::Next
vtkCollectionElement * Next
Definition: vtkCollection.h:46
vtkCollection
create and manipulate ordered lists of objects
Definition: vtkCollection.h:53
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:70
vtkCollectionIterator
iterator through a vtkCollection.
Definition: vtkCollectionIterator.h:38
vtkCollection::Bottom
vtkCollectionElement * Bottom
Definition: vtkCollection.h:166
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkCollection::UnRegister
void UnRegister(vtkObjectBase *o) override
Participate in garbage collection.
vtkCollection::InsertItem
void InsertItem(int i, vtkObject *)
Insert item into the list after the i'th item.
vtkCollection::GetItemAsObject
vtkObject * GetItemAsObject(int i)
Get the i'th item in the collection.
vtkCollection::ReportReferences
void ReportReferences(vtkGarbageCollector *collector) override
vtkGarbageCollector
Detect and break reference loops.
Definition: vtkGarbageCollector.h:95
vtkObject.h
vtkCollection::RemoveAllItems
void RemoveAllItems()
Remove all objects from the list.
vtkCollection::RemoveItem
void RemoveItem(int i)
Remove the i'th item in the list.
vtkX3D::previous
@ previous
Definition: vtkX3D.h:455
vtkCollection::AddItem
void AddItem(vtkObject *)
Add an object to the bottom of the list.
vtkCollection::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkCollection::InitTraversal
void InitTraversal()
Initialize the traversal of the collection.
Definition: vtkCollection.h:116
vtkCollectionElement
Definition: vtkCollection.h:38
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:44
vtkCollection::Top
vtkCollectionElement * Top
Definition: vtkCollection.h:165
vtkCollection::~vtkCollection
~vtkCollection() override