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 =========================================================================*/ 00043 #ifndef __vtkIdList_h 00044 #define __vtkIdList_h 00045 00046 #include "vtkObject.h" 00047 00048 class VTK_COMMON_EXPORT vtkIdList : public vtkObject 00049 { 00050 public: 00051 static vtkIdList *New(); 00052 00053 void Initialize(); 00054 int Allocate(const int sz, const int strategy=0); 00055 vtkTypeRevisionMacro(vtkIdList,vtkObject); 00056 void PrintSelf(ostream& os, vtkIndent indent); 00057 00059 vtkIdType GetNumberOfIds() {return this->NumberOfIds;}; 00060 00062 vtkIdType GetId(const int i) {return this->Ids[i];}; 00063 00066 void SetNumberOfIds(const vtkIdType number); 00067 00071 void SetId(const vtkIdType i, const vtkIdType id) {this->Ids[i] = id;}; 00072 00075 void InsertId(const vtkIdType i, const vtkIdType id); 00076 00079 vtkIdType InsertNextId(const vtkIdType id); 00080 00083 vtkIdType InsertUniqueId(const vtkIdType id); 00084 00086 vtkIdType *GetPointer(const vtkIdType i) {return this->Ids + i;}; 00087 00091 vtkIdType *WritePointer(const vtkIdType i, const vtkIdType number); 00092 00094 void Reset() {this->NumberOfIds = 0;}; 00095 00097 void Squeeze() {this->Resize(this->NumberOfIds);}; 00098 00100 void DeepCopy(vtkIdList *ids); 00101 00104 void DeleteId(vtkIdType id); 00105 00108 vtkIdType IsId(vtkIdType id); 00109 00112 void IntersectWith(vtkIdList& otherIds); 00113 00114 protected: 00115 vtkIdList(); 00116 ~vtkIdList(); 00117 00118 vtkIdType NumberOfIds; 00119 vtkIdType Size; 00120 vtkIdType *Ids; 00121 00122 vtkIdType *Resize(const vtkIdType sz); 00123 private: 00124 vtkIdList(const vtkIdList&); // Not implemented. 00125 void operator=(const vtkIdList&); // Not implemented. 00126 }; 00127 00128 // In-lined for performance 00129 inline vtkIdType vtkIdList::InsertNextId(const vtkIdType id) 00130 { 00131 if ( this->NumberOfIds >= this->Size ) 00132 { 00133 this->Resize(this->NumberOfIds+1); 00134 } 00135 this->Ids[this->NumberOfIds++] = id; 00136 return this->NumberOfIds-1; 00137 } 00138 00139 inline vtkIdType vtkIdList::IsId(vtkIdType id) 00140 { 00141 vtkIdType *ptr, i; 00142 for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++) 00143 { 00144 if ( id == *ptr ) 00145 { 00146 return i; 00147 } 00148 } 00149 return (-1); 00150 } 00151 00152 #endif