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(NULL),Next(NULL) {}
46 };
48 
50 
51 class VTKCOMMONCORE_EXPORT vtkCollection : public vtkObject
52 {
53 public:
54  vtkTypeMacro(vtkCollection,vtkObject);
55  void PrintSelf(ostream& os, vtkIndent indent) VTK_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) VTK_OVERRIDE;
152  void UnRegister(vtkObjectBase* o) VTK_OVERRIDE;
154 
155 protected:
156  vtkCollection();
157  ~vtkCollection() VTK_OVERRIDE;
158 
159  virtual void RemoveElement(vtkCollectionElement *element,
161  virtual void DeleteElement(vtkCollectionElement *);
162  int NumberOfItems;
163  vtkCollectionElement *Top;
164  vtkCollectionElement *Bottom;
165  vtkCollectionElement *Current;
166 
167  friend class vtkCollectionIterator;
168 
169  // See vtkGarbageCollector.h:
170  void ReportReferences(vtkGarbageCollector* collector) VTK_OVERRIDE;
171 private:
172  vtkCollection(const vtkCollection&) VTK_DELETE_FUNCTION;
173  void operator=(const vtkCollection&) VTK_DELETE_FUNCTION;
174 };
175 
176 
177 inline vtkObject *vtkCollection::GetNextItemAsObject()
178 {
179  vtkCollectionElement *elem=this->Current;
180 
181  if ( elem != NULL )
182  {
183  this->Current = elem->Next;
184  return elem->Item;
185  }
186  else
187  {
188  return NULL;
189  }
190 }
191 
193 {
194  vtkCollectionElement *elem=static_cast<vtkCollectionElement *>(cookie);
195 
196  if ( elem != NULL )
197  {
198  cookie = static_cast<void *>(elem->Next);
199  return elem->Item;
200  }
201  else
202  {
203  return NULL;
204  }
205 }
206 
207 #endif
208 
209 
210 
211 
212 
void * vtkCollectionSimpleIterator
Definition: vtkCollection.h:47
abstract base class for most VTK objects
Definition: vtkObject.h:59
virtual void Register(vtkObjectBase *o)
Increase the reference count (mark as used by another object).
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.
Detect and break reference loops.
virtual void UnRegister(vtkObjectBase *o)
Decrease the reference count (release by another object).
a simple class to control print indentation
Definition: vtkIndent.h:39
abstract base class for most VTK objects
Definition: vtkObjectBase.h:65
#define VTK_NEWINSTANCE
iterator through a vtkCollection.
int GetNumberOfItems()
Return the number of objects in the list.
create and manipulate unsorted 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
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.