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