VTK
dox/Common/vtkCollection.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkCollection.h
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 =========================================================================*/
00033 #ifndef __vtkCollection_h
00034 #define __vtkCollection_h
00035 
00036 #include "vtkObject.h"
00037 
00038 //BTX - begin tcl exclude
00039 class vtkCollectionElement //;prevents pick-up by man page generator
00040 {
00041  public:
00042   vtkCollectionElement():Item(NULL),Next(NULL) {};
00043   vtkObject *Item;
00044   vtkCollectionElement *Next;
00045 };
00046 typedef void * vtkCollectionSimpleIterator;
00047 //ETX end tcl exclude
00048 
00049 class vtkCollectionIterator;
00050 
00051 class VTK_COMMON_EXPORT vtkCollection : public vtkObject
00052 {
00053 public:
00054   vtkTypeMacro(vtkCollection,vtkObject);
00055   void PrintSelf(ostream& os, vtkIndent indent);
00056 
00058   static vtkCollection *New();
00059 
00061   void AddItem(vtkObject *);
00062 
00066   void InsertItem(int i, vtkObject *);
00067 
00069   void ReplaceItem(int i, vtkObject *);
00070 
00076   void RemoveItem(int i);
00077 
00081   void RemoveItem(vtkObject *);
00082 
00084   void RemoveAllItems();
00085 
00089   int IsItemPresent(vtkObject *a);
00090 
00092   int  GetNumberOfItems() { return this->NumberOfItems; }
00093 
00096   void InitTraversal() { this->Current = this->Top;};
00097 
00098   //BTX
00100 
00102   void InitTraversal(vtkCollectionSimpleIterator &cookie) {
00103     cookie = static_cast<vtkCollectionSimpleIterator>(this->Top);};
00104   //ETX
00106 
00109   vtkObject *GetNextItemAsObject();  
00110 
00113   vtkObject *GetItemAsObject(int i);
00114 
00115   //BTX
00117 
00119   vtkObject *GetNextItemAsObject(vtkCollectionSimpleIterator &cookie);
00120   //ETX
00122   
00124   vtkCollectionIterator* NewIterator();
00125 
00127 
00128   virtual void Register(vtkObjectBase* o);
00129   virtual void UnRegister(vtkObjectBase* o);
00130 protected:
00131   vtkCollection();
00132   ~vtkCollection();
00134 
00135   virtual void DeleteElement(vtkCollectionElement *); 
00136   int NumberOfItems;
00137   vtkCollectionElement *Top;
00138   vtkCollectionElement *Bottom;
00139   vtkCollectionElement *Current;
00140 
00141   //BTX
00142   friend class vtkCollectionIterator;
00143   //ETX
00144 
00145   // See vtkGarbageCollector.h:
00146   virtual void ReportReferences(vtkGarbageCollector* collector);
00147 private:
00148   vtkCollection(const vtkCollection&); // Not implemented
00149   void operator=(const vtkCollection&); // Not implemented
00150 };
00151 
00152 
00153 inline vtkObject *vtkCollection::GetNextItemAsObject()
00154 {
00155   vtkCollectionElement *elem=this->Current;
00156 
00157   if ( elem != NULL )
00158     {
00159     this->Current = elem->Next;
00160     return elem->Item;
00161     }
00162   else
00163     {
00164     return NULL;
00165     }
00166 }
00167 
00168 inline vtkObject *vtkCollection::GetNextItemAsObject(void *&cookie)
00169 {
00170   vtkCollectionElement *elem=static_cast<vtkCollectionElement *>(cookie);
00171 
00172   if ( elem != NULL )
00173     {
00174     cookie = static_cast<void *>(elem->Next);
00175     return elem->Item;
00176     }
00177   else
00178     {
00179     return NULL;
00180     }
00181 }
00182 
00183 #endif
00184 
00185 
00186 
00187 
00188