00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkCollection.h,v $ 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00043 #ifndef __vtkCollection_h 00044 #define __vtkCollection_h 00045 00046 #include "vtkObject.h" 00047 00048 //BTX - begin tcl exclude 00049 class vtkCollectionElement //;prevents pick-up by man page generator 00050 { 00051 public: 00052 vtkCollectionElement():Item(NULL),Next(NULL) {}; 00053 vtkObject *Item; 00054 vtkCollectionElement *Next; 00055 }; 00056 typedef void * vtkCollectionSimpleIterator; 00057 //ETX end tcl exclude 00058 00059 class vtkCollectionIterator; 00060 00061 class VTK_COMMON_EXPORT vtkCollection : public vtkObject 00062 { 00063 public: 00064 vtkTypeRevisionMacro(vtkCollection,vtkObject); 00065 void PrintSelf(ostream& os, vtkIndent indent); 00066 00068 static vtkCollection *New(); 00069 00071 void AddItem(vtkObject *); 00072 00074 void ReplaceItem(int i, vtkObject *); 00075 00081 void RemoveItem(int i); 00082 00086 void RemoveItem(vtkObject *); 00087 00089 void RemoveAllItems(); 00090 00093 int IsItemPresent(vtkObject *); 00094 00096 int GetNumberOfItems(); 00097 00100 void InitTraversal() { this->Current = this->Top;}; 00101 00102 //BTX 00104 00106 void InitTraversal(vtkCollectionSimpleIterator &cookie) { 00107 cookie = static_cast<vtkCollectionSimpleIterator>(this->Top);}; 00108 //ETX 00110 00113 vtkObject *GetNextItemAsObject(); 00114 00117 vtkObject *GetItemAsObject(int i); 00118 00119 //BTX 00121 00123 vtkObject *GetNextItemAsObject(vtkCollectionSimpleIterator &cookie); 00124 //ETX 00126 00128 vtkCollectionIterator* NewIterator(); 00129 00130 protected: 00131 vtkCollection(); 00132 ~vtkCollection(); 00133 00134 virtual void DeleteElement(vtkCollectionElement *); 00135 int NumberOfItems; 00136 vtkCollectionElement *Top; 00137 vtkCollectionElement *Bottom; 00138 vtkCollectionElement *Current; 00139 00140 //BTX 00141 friend class vtkCollectionIterator; 00142 //ETX 00143 00144 private: 00145 vtkCollection(const vtkCollection&); // Not implemented 00146 void operator=(const vtkCollection&); // Not implemented 00147 }; 00148 00149 00150 inline vtkObject *vtkCollection::GetNextItemAsObject() 00151 { 00152 vtkCollectionElement *elem=this->Current; 00153 00154 if ( elem != NULL ) 00155 { 00156 this->Current = elem->Next; 00157 return elem->Item; 00158 } 00159 else 00160 { 00161 return NULL; 00162 } 00163 } 00164 00165 inline vtkObject *vtkCollection::GetNextItemAsObject(void *&cookie) 00166 { 00167 vtkCollectionElement *elem=static_cast<vtkCollectionElement *>(cookie); 00168 00169 if ( elem != NULL ) 00170 { 00171 cookie = static_cast<void *>(elem->Next); 00172 return elem->Item; 00173 } 00174 else 00175 { 00176 return NULL; 00177 } 00178 } 00179 00180 #endif 00181 00182 00183 00184 00185