00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkIdList.h,v $ 00005 Language: C++ 00006 00007 00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 00009 All rights reserved. 00010 00011 Redistribution and use in source and binary forms, with or without 00012 modification, are permitted provided that the following conditions are met: 00013 00014 * Redistributions of source code must retain the above copyright notice, 00015 this list of conditions and the following disclaimer. 00016 00017 * Redistributions in binary form must reproduce the above copyright notice, 00018 this list of conditions and the following disclaimer in the documentation 00019 and/or other materials provided with the distribution. 00020 00021 * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names 00022 of any contributors may be used to endorse or promote products derived 00023 from this software without specific prior written permission. 00024 00025 * Modified source versions must be plainly marked as such, and must not be 00026 misrepresented as being the original software. 00027 00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00038 00039 =========================================================================*/ 00057 #ifndef __vtkIdList_h 00058 #define __vtkIdList_h 00059 00060 #include "vtkObject.h" 00061 00062 class VTK_COMMON_EXPORT vtkIdList : public vtkObject 00063 { 00064 public: 00065 static vtkIdList *New(); 00066 00067 void Initialize(); 00068 int Allocate(const int sz, const int strategy=0); 00069 vtkTypeMacro(vtkIdList,vtkObject); 00070 void PrintSelf(ostream& os, vtkIndent indent); 00071 00073 vtkIdType GetNumberOfIds() {return this->NumberOfIds;}; 00074 00076 vtkIdType GetId(const int i) {return this->Ids[i];}; 00077 00080 void SetNumberOfIds(const vtkIdType number); 00081 00085 void SetId(const vtkIdType i, const vtkIdType id) {this->Ids[i] = id;}; 00086 00089 void InsertId(const vtkIdType i, const vtkIdType id); 00090 00093 vtkIdType InsertNextId(const vtkIdType id); 00094 00097 vtkIdType InsertUniqueId(const vtkIdType id); 00098 00100 vtkIdType *GetPointer(const vtkIdType i) {return this->Ids + i;}; 00101 00105 vtkIdType *WritePointer(const vtkIdType i, const vtkIdType number); 00106 00108 void Reset() {this->NumberOfIds = 0;}; 00109 00111 void Squeeze() {this->Resize(this->NumberOfIds);}; 00112 00114 void DeepCopy(vtkIdList *ids); 00115 00118 void DeleteId(vtkIdType id); 00119 00122 vtkIdType IsId(vtkIdType id); 00123 00126 void IntersectWith(vtkIdList& otherIds); 00127 00128 protected: 00129 vtkIdList(); 00130 ~vtkIdList(); 00131 00132 vtkIdType NumberOfIds; 00133 vtkIdType Size; 00134 vtkIdType *Ids; 00135 00136 vtkIdType *Resize(const vtkIdType sz); 00137 private: 00138 vtkIdList(const vtkIdList&); // Not implemented. 00139 void operator=(const vtkIdList&); // Not implemented. 00140 }; 00141 00142 // In-lined for performance 00143 inline vtkIdType vtkIdList::InsertNextId(const vtkIdType id) 00144 { 00145 if ( this->NumberOfIds >= this->Size ) 00146 { 00147 this->Resize(this->NumberOfIds+1); 00148 } 00149 this->Ids[this->NumberOfIds++] = id; 00150 return this->NumberOfIds-1; 00151 } 00152 00153 inline vtkIdType vtkIdList::IsId(vtkIdType id) 00154 { 00155 vtkIdType *ptr, i; 00156 for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++) 00157 { 00158 if ( id == *ptr ) 00159 { 00160 return i; 00161 } 00162 } 00163 return (-1); 00164 } 00165 00166 #endif