VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Common/Core/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 "vtkCommonCoreModule.h" // For export macro
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 typedef void * vtkCollectionSimpleIterator;
00048 //ETX end tcl exclude
00049 
00050 class vtkCollectionIterator;
00051 
00052 class VTKCOMMONCORE_EXPORT vtkCollection : public vtkObject
00053 {
00054 public:
00055   vtkTypeMacro(vtkCollection,vtkObject);
00056   void PrintSelf(ostream& os, vtkIndent indent);
00057 
00059   static vtkCollection *New();
00060 
00062   void AddItem(vtkObject *);
00063 
00067   void InsertItem(int i, vtkObject *);
00068 
00070   void ReplaceItem(int i, vtkObject *);
00071 
00077   void RemoveItem(int i);
00078 
00082   void RemoveItem(vtkObject *);
00083 
00085   void RemoveAllItems();
00086 
00090   int IsItemPresent(vtkObject *a);
00091 
00093   int  GetNumberOfItems() { return this->NumberOfItems; }
00094 
00097   void InitTraversal() { this->Current = this->Top;};
00098 
00099   //BTX
00101 
00103   void InitTraversal(vtkCollectionSimpleIterator &cookie) {
00104     cookie = static_cast<vtkCollectionSimpleIterator>(this->Top);};
00105   //ETX
00107 
00110   vtkObject *GetNextItemAsObject();
00111 
00114   vtkObject *GetItemAsObject(int i);
00115 
00116   //BTX
00118 
00120   vtkObject *GetNextItemAsObject(vtkCollectionSimpleIterator &cookie);
00121   //ETX
00123 
00125   vtkCollectionIterator* NewIterator();
00126 
00128 
00129   virtual void Register(vtkObjectBase* o);
00130   virtual void UnRegister(vtkObjectBase* o);
00131 protected:
00132   vtkCollection();
00133   ~vtkCollection();
00135 
00136   virtual void RemoveElement(vtkCollectionElement *element,
00137                              vtkCollectionElement *previous);
00138   virtual void DeleteElement(vtkCollectionElement *);
00139   int NumberOfItems;
00140   vtkCollectionElement *Top;
00141   vtkCollectionElement *Bottom;
00142   vtkCollectionElement *Current;
00143 
00144   //BTX
00145   friend class vtkCollectionIterator;
00146   //ETX
00147 
00148   // See vtkGarbageCollector.h:
00149   virtual void ReportReferences(vtkGarbageCollector* collector);
00150 private:
00151   vtkCollection(const vtkCollection&); // Not implemented
00152   void operator=(const vtkCollection&); // Not implemented
00153 };
00154 
00155 
00156 inline vtkObject *vtkCollection::GetNextItemAsObject()
00157 {
00158   vtkCollectionElement *elem=this->Current;
00159 
00160   if ( elem != NULL )
00161     {
00162     this->Current = elem->Next;
00163     return elem->Item;
00164     }
00165   else
00166     {
00167     return NULL;
00168     }
00169 }
00170 
00171 inline vtkObject *vtkCollection::GetNextItemAsObject(void *&cookie)
00172 {
00173   vtkCollectionElement *elem=static_cast<vtkCollectionElement *>(cookie);
00174 
00175   if ( elem != NULL )
00176     {
00177     cookie = static_cast<void *>(elem->Next);
00178     return elem->Item;
00179     }
00180   else
00181     {
00182     return NULL;
00183     }
00184 }
00185 
00186 #endif
00187 
00188 
00189 
00190 
00191