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