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

Common/vtkIdList.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkIdList.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 =========================================================================*/
00033 #ifndef __vtkIdList_h
00034 #define __vtkIdList_h
00035 
00036 #include "vtkObject.h"
00037 
00038 class VTK_COMMON_EXPORT vtkIdList : public vtkObject
00039 {
00040 public:
00041   static vtkIdList *New();
00042 
00043   void Initialize();
00044   int Allocate(const int sz, const int strategy=0);
00045   vtkTypeRevisionMacro(vtkIdList,vtkObject);
00046   void PrintSelf(ostream& os, vtkIndent indent);
00047 
00049   vtkIdType GetNumberOfIds() {return this->NumberOfIds;};
00050   
00052   vtkIdType GetId(const int i) {return this->Ids[i];};
00053   
00056   void SetNumberOfIds(const vtkIdType number);
00057 
00061   void SetId(const vtkIdType i, const vtkIdType id) {this->Ids[i] = id;};
00062 
00065   void InsertId(const vtkIdType i, const vtkIdType id);
00066 
00069   vtkIdType InsertNextId(const vtkIdType id);
00070 
00073   vtkIdType InsertUniqueId(const vtkIdType id);
00074 
00076   vtkIdType *GetPointer(const vtkIdType i) {return this->Ids + i;};
00077 
00081   vtkIdType *WritePointer(const vtkIdType i, const vtkIdType number);
00082 
00084   void Reset() {this->NumberOfIds = 0;};
00085 
00087   void Squeeze() {this->Resize(this->NumberOfIds);};
00088 
00090   void DeepCopy(vtkIdList *ids);
00091 
00094   void DeleteId(vtkIdType id);
00095 
00098   vtkIdType IsId(vtkIdType id);
00099 
00102   void IntersectWith(vtkIdList& otherIds);
00103 
00104 protected:
00105   vtkIdList();
00106   ~vtkIdList();
00107 
00108   vtkIdType NumberOfIds;
00109   vtkIdType Size; 
00110   vtkIdType *Ids;
00111 
00112   vtkIdType *Resize(const vtkIdType sz);
00113 private:
00114   vtkIdList(const vtkIdList&);  // Not implemented.
00115   void operator=(const vtkIdList&);  // Not implemented.
00116 };
00117 
00118 // In-lined for performance
00119 inline vtkIdType vtkIdList::InsertNextId(const vtkIdType id)
00120 {
00121   if ( this->NumberOfIds >= this->Size )
00122     {
00123     this->Resize(this->NumberOfIds+1);
00124     }
00125   this->Ids[this->NumberOfIds++] = id;
00126   return this->NumberOfIds-1;
00127 }
00128 
00129 inline vtkIdType vtkIdList::IsId(vtkIdType id)
00130 {
00131   vtkIdType *ptr, i;
00132   for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++)
00133     {
00134     if ( id == *ptr )
00135       {
00136       return i;
00137       }
00138     }
00139   return (-1);
00140 }
00141 
00142 #endif