00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkCollection.h,v $ 00005 Language: C++ 00006 00007 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 00008 All rights reserved. 00009 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00010 00011 This software is distributed WITHOUT ANY WARRANTY; without even 00012 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00013 PURPOSE. See the above copyright notice for more information. 00014 00015 =========================================================================*/ 00034 #ifndef __vtkCollection_h 00035 #define __vtkCollection_h 00036 00037 #include "vtkObject.h" 00038 00039 //BTX - begin tcl exclude 00040 class vtkCollectionElement //;prevents pick-up by man page generator 00041 { 00042 public: 00043 vtkCollectionElement():Item(NULL),Next(NULL) {}; 00044 vtkObject *Item; 00045 vtkCollectionElement *Next; 00046 }; 00047 //ETX end tcl exclude 00048 00049 class vtkCollectionIterator; 00050 00051 class VTK_COMMON_EXPORT vtkCollection : public vtkObject 00052 { 00053 public: 00054 vtkTypeRevisionMacro(vtkCollection,vtkObject); 00055 void PrintSelf(ostream& os, vtkIndent indent); 00056 00058 static vtkCollection *New(); 00059 00061 void AddItem(vtkObject *); 00062 00064 void ReplaceItem(int i, vtkObject *); 00065 00071 void RemoveItem(int i); 00072 00076 void RemoveItem(vtkObject *); 00077 00079 void RemoveAllItems(); 00080 00083 int IsItemPresent(vtkObject *); 00084 00086 int GetNumberOfItems(); 00087 00090 void InitTraversal() { this->Current = this->Top;}; 00091 00092 //BTX 00094 00096 void InitTraversal(void *&cookie) {cookie = static_cast<void *>(this->Top);}; 00097 //ETX 00099 00102 vtkObject *GetNextItemAsObject(); 00103 00106 vtkObject *GetItemAsObject(int i); 00107 00108 //BTX 00111 vtkObject *GetNextItemAsObject(void *&cookie); 00112 00114 vtkCollectionIterator* NewIterator(); 00115 00116 protected: 00117 vtkCollection(); 00118 ~vtkCollection(); 00119 00120 virtual void DeleteElement(vtkCollectionElement *); 00121 int NumberOfItems; 00122 vtkCollectionElement *Top; 00123 vtkCollectionElement *Bottom; 00124 vtkCollectionElement *Current; 00125 00126 //BTX 00127 friend class vtkCollectionIterator; 00128 //ETX 00129 00130 private: 00131 vtkCollection(const vtkCollection&); // Not implemented 00132 void operator=(const vtkCollection&); // Not implemented 00133 }; 00134 00135 00136 inline vtkObject *vtkCollection::GetNextItemAsObject() 00137 { 00138 vtkCollectionElement *elem=this->Current; 00139 00140 if ( elem != NULL ) 00141 { 00142 this->Current = elem->Next; 00143 return elem->Item; 00144 } 00145 else 00146 { 00147 return NULL; 00148 } 00149 } 00150 00151 inline vtkObject *vtkCollection::GetNextItemAsObject(void *&cookie) 00152 { 00153 vtkCollectionElement *elem=static_cast<vtkCollectionElement *>(cookie); 00154 00155 if ( elem != NULL ) 00156 { 00157 cookie = static_cast<void *>(elem->Next); 00158 return elem->Item; 00159 } 00160 else 00161 { 00162 return NULL; 00163 } 00164 } 00165 00166 #endif 00167 00168 00169 00170 00171