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 =========================================================================*/
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:
40  vtkCollectionElement():Item(NULL),Next(NULL) {}
43 };
45 
47 
48 class VTKCOMMONCORE_EXPORT vtkCollection : public vtkObject
49 {
50 public:
51  vtkTypeMacro(vtkCollection,vtkObject);
52  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
53 
57  static vtkCollection *New();
58 
62  void AddItem(vtkObject *);
63 
68  void InsertItem(int i, vtkObject *);
69 
73  void ReplaceItem(int i, vtkObject *);
74 
82  void RemoveItem(int i);
83 
89  void RemoveItem(vtkObject *);
90 
94  void RemoveAllItems();
95 
101  int IsItemPresent(vtkObject *a);
102 
106  int GetNumberOfItems() { return this->NumberOfItems; }
107 
112  void InitTraversal() { this->Current = this->Top;};
113 
119  cookie = static_cast<vtkCollectionSimpleIterator>(this->Top);};
120 
125  vtkObject *GetNextItemAsObject();
126 
131  vtkObject *GetItemAsObject(int i);
132 
137  vtkObject *GetNextItemAsObject(vtkCollectionSimpleIterator &cookie);
138 
142  VTK_NEWINSTANCE vtkCollectionIterator* NewIterator();
143 
145 
148  void Register(vtkObjectBase* o) VTK_OVERRIDE;
149  void UnRegister(vtkObjectBase* o) VTK_OVERRIDE;
151 
152 protected:
153  vtkCollection();
154  ~vtkCollection() VTK_OVERRIDE;
155 
156  virtual void RemoveElement(vtkCollectionElement *element,
158  virtual void DeleteElement(vtkCollectionElement *);
159  int NumberOfItems;
160  vtkCollectionElement *Top;
161  vtkCollectionElement *Bottom;
162  vtkCollectionElement *Current;
163 
164  friend class vtkCollectionIterator;
165 
166  // See vtkGarbageCollector.h:
167  void ReportReferences(vtkGarbageCollector* collector) VTK_OVERRIDE;
168 private:
169  vtkCollection(const vtkCollection&) VTK_DELETE_FUNCTION;
170  void operator=(const vtkCollection&) VTK_DELETE_FUNCTION;
171 };
172 
173 
174 inline vtkObject *vtkCollection::GetNextItemAsObject()
175 {
176  vtkCollectionElement *elem=this->Current;
177 
178  if ( elem != NULL )
179  {
180  this->Current = elem->Next;
181  return elem->Item;
182  }
183  else
184  {
185  return NULL;
186  }
187 }
188 
190 {
191  vtkCollectionElement *elem=static_cast<vtkCollectionElement *>(cookie);
192 
193  if ( elem != NULL )
194  {
195  cookie = static_cast<void *>(elem->Next);
196  return elem->Item;
197  }
198  else
199  {
200  return NULL;
201  }
202 }
203 
204 #endif
void * vtkCollectionSimpleIterator
Definition: vtkCollection.h:44
abstract base class for most VTK objects
Definition: vtkObject.h:53
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:33
abstract base class for most VTK objects
Definition: vtkObjectBase.h:62
#define VTK_NEWINSTANCE
iterator through a vtkCollection.
int GetNumberOfItems()
Return the number of objects in the list.
create and manipulate ordered lists of objects
Definition: vtkCollection.h:48
void InitTraversal(vtkCollectionSimpleIterator &cookie)
A reentrant safe way to iterate through a collection.
vtkCollectionElement * Next
Definition: vtkCollection.h:42
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.