Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members Related Pages

# Common/vtkCollection.h

Go to the documentation of this file.

    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 =========================================================================*/
    00047 #ifndef __vtkCollection_h
    00048 #define __vtkCollection_h
    00049
    00050 #include "vtkObject.h"
    00051
    00052 //BTX - begin tcl exclude
    00053 class vtkCollectionElement //;prevents pick-up by man page generator
    00054 {
    00055  public:
    00056   vtkCollectionElement():Item(NULL),Next(NULL) {};
    00057   vtkObject *Item;
    00058   vtkCollectionElement *Next;
    00059 };
    00060 //ETX end tcl exclude
    00061
    00062 class vtkCollectionIterator;
    00063
    00064 class VTK_COMMON_EXPORT vtkCollection : public vtkObject
    00065 {
    00066 public:
    00067   vtkTypeRevisionMacro(vtkCollection,vtkObject);
    00068   void PrintSelf(ostream& os, vtkIndent indent);
    00069
    00071   static vtkCollection *New();
    00072
    00074   void AddItem(vtkObject *);
    00075
    00077   void ReplaceItem(int i, vtkObject *);
    00078
    00084   void RemoveItem(int i);
    00085
    00089   void RemoveItem(vtkObject *);
    00090
    00092   void RemoveAllItems();
    00093
    00096   int  IsItemPresent(vtkObject *);
    00097
    00099   int  GetNumberOfItems();
    00100
    00103   void InitTraversal() { this->Current = this->Top;};
    00104
    00105   //BTX
    00107   /*! Less bloated way to iterate through a collection. Just pass the same
    00108       cookie value around each time */
    00109   void InitTraversal(void *&cookie) {cookie = static_cast<void *>(this->Top);};
    00110   //ETX
    00112
    00115   vtkObject *GetNextItemAsObject();
    00116
    00119   vtkObject *GetItemAsObject(int i);
    00120
    00121   //BTX
    00124   vtkObject *GetNextItemAsObject(void *&cookie);
    00125
    00127   vtkCollectionIterator* NewIterator();
    00128
    00129 protected:
    00130   vtkCollection();
    00131   ~vtkCollection();
    00132
    00133   virtual void DeleteElement(vtkCollectionElement *);
    00134   int NumberOfItems;
    00135   vtkCollectionElement *Top;
    00136   vtkCollectionElement *Bottom;
    00137   vtkCollectionElement *Current;
    00138
    00139   //BTX
    00140   friend class vtkCollectionIterator;
    00141   //ETX
    00142
    00143 private:
    00144   vtkCollection(const vtkCollection&); // Not implemented
    00145   void operator=(const vtkCollection&); // Not implemented
    00146 };
    00147
    00148
    00149 inline vtkObject *vtkCollection::GetNextItemAsObject()
    00150 {
    00151   vtkCollectionElement *elem=this->Current;
    00152
    00153   if ( elem != NULL )
    00154     {
    00155     this->Current = elem->Next;
    00156     return elem->Item;
    00157     }
    00158   else
    00159     {
    00160     return NULL;
    00161     }
    00162 }
    00163
    00164 inline vtkObject *vtkCollection::GetNextItemAsObject(void *&cookie)
    00165 {
    00166   vtkCollectionElement *elem=static_cast<vtkCollectionElement *>(cookie);
    00167
    00168   if ( elem != NULL )
    00169     {
    00170     cookie = static_cast<void *>(elem->Next);
    00171     return elem->Item;
    00172     }
    00173   else
    00174     {
    00175     return NULL;
    00176     }
    00177 }
    00178
    00179 #endif
    00180
    00181
    00182
    00183
    00184