VTK  9.3.0
vtkIdList.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
24 #ifndef vtkIdList_h
25 #define vtkIdList_h
26 
27 #include "vtkCommonCoreModule.h" // For export macro
28 #include "vtkObject.h"
29 
30 VTK_ABI_NAMESPACE_BEGIN
31 class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
32 {
33 public:
35 
38  static vtkIdList* New();
39  vtkTypeMacro(vtkIdList, vtkObject);
40  void PrintSelf(ostream& os, vtkIndent indent) override;
42 
46  void Initialize();
47 
53  int Allocate(vtkIdType sz, int strategy = 0);
54 
58  vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
59 
63  vtkIdType GetId(vtkIdType i) VTK_EXPECTS(0 <= i && i < GetNumberOfIds()) { return this->Ids[i]; }
64 
69  {
70  for (int i = 0; i < this->NumberOfIds; i++)
71  if (this->Ids[i] == id)
72  return i;
73  return -1;
74  }
75 
80  void SetNumberOfIds(vtkIdType number);
81 
87  void SetId(vtkIdType i, vtkIdType vtkid) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
88  {
89  this->Ids[i] = vtkid;
90  }
91 
96  void InsertId(vtkIdType i, vtkIdType vtkid) VTK_EXPECTS(0 <= i);
97 
101  vtkIdType InsertNextId(vtkIdType vtkid);
102 
108 
113  void Sort();
114 
120 
124  vtkIdType* GetPointer(vtkIdType i) { return this->Ids + i; }
125 
132 
138  void SetArray(vtkIdType* array, vtkIdType size, bool save = true);
139 
143  void Reset() { this->NumberOfIds = 0; }
144 
148  void Squeeze() { this->Resize(this->NumberOfIds); }
149 
153  void DeepCopy(vtkIdList* ids);
154 
158  void DeleteId(vtkIdType vtkid);
159 
164  vtkIdType IsId(vtkIdType vtkid);
165 
170  void IntersectWith(vtkIdList* otherIds);
171 
177 
178 #ifndef __VTK_WRAP__
186 #endif
187 
189 
192  vtkIdType* begin() { return this->Ids; }
193  vtkIdType* end() { return this->Ids + this->NumberOfIds; }
194  const vtkIdType* begin() const { return this->Ids; }
195  const vtkIdType* end() const { return this->Ids + this->NumberOfIds; }
197 protected:
199  ~vtkIdList() override;
200 
204  bool AllocateInternal(vtkIdType sz, vtkIdType numberOfIds);
209 
214 
215 private:
216  vtkIdList(const vtkIdList&) = delete;
217  void operator=(const vtkIdList&) = delete;
218 };
219 
220 // In-lined for performance
221 inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
222 {
223  if (i >= this->Size)
224  {
225  this->Resize(i + 1);
226  }
227  this->Ids[i] = vtkid;
228  if (i >= this->NumberOfIds)
229  {
230  this->NumberOfIds = i + 1;
231  }
232 }
233 
234 // In-lined for performance
236 {
237  if (this->NumberOfIds >= this->Size)
238  {
239  if (!this->Resize(2 * this->NumberOfIds + 1)) // grow by factor of 2
240  {
241  return this->NumberOfIds - 1;
242  }
243  }
244  this->Ids[this->NumberOfIds++] = vtkid;
245  return this->NumberOfIds - 1;
246 }
247 
249 {
250  vtkIdType *ptr, i;
251  for (ptr = this->Ids, i = 0; i < this->NumberOfIds; i++, ptr++)
252  {
253  if (vtkid == *ptr)
254  {
255  return i;
256  }
257  }
258  return (-1);
259 }
260 
261 VTK_ABI_NAMESPACE_END
262 #endif
list of point or cell ids
Definition: vtkIdList.h:32
vtkIdType * WritePointer(vtkIdType i, vtkIdType number)
Get a pointer to a particular data index.
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition: vtkIdList.h:68
void DeleteId(vtkIdType vtkid)
Delete specified id from list.
vtkIdType * Ids
Definition: vtkIdList.h:212
const vtkIdType * end() const
To support range-based for loops.
Definition: vtkIdList.h:195
void SetNumberOfIds(vtkIdType number)
Specify the number of ids for this object to hold.
const vtkIdType * begin() const
To support range-based for loops.
Definition: vtkIdList.h:194
void IntersectWith(vtkIdList *otherIds)
Intersect this list with another vtkIdList.
vtkIdType NumberOfIds
Definition: vtkIdList.h:210
~vtkIdList() override
void Fill(vtkIdType value)
Fill the ids with the input value.
void SetArray(vtkIdType *array, vtkIdType size, bool save=true)
Specify an array of vtkIdType to use as the id list.
int Allocate(vtkIdType sz, int strategy=0)
Allocate a capacity for sz ids in the list and set the number of stored ids in the list to 0.
vtkIdType Size
Definition: vtkIdList.h:211
void Squeeze()
Free any unused memory.
Definition: vtkIdList.h:148
vtkIdType * Resize(vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).
vtkIdType * end()
To support range-based for loops.
Definition: vtkIdList.h:193
void InitializeMemory()
Release memory.
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:58
void Initialize()
Release memory and restore to unallocated state.
bool AllocateInternal(vtkIdType sz, vtkIdType numberOfIds)
Allocate ids and set the number of ids.
vtkIdType * begin()
To support range-based for loops.
Definition: vtkIdList.h:192
vtkIdType InsertNextId(vtkIdType vtkid)
Add the id specified to the end of the list.
Definition: vtkIdList.h:235
vtkIdType IsId(vtkIdType vtkid)
Return -1 if id specified is not contained in the list; otherwise return the position in the list.
Definition: vtkIdList.h:248
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:143
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:124
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instantiation, type information, and printing.
void SetId(vtkIdType i, vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:87
vtkIdType GetId(vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:63
void Sort()
Sort the ids in the list in ascending id order.
static vtkIdList * New()
Standard methods for instantiation, type information, and printing.
bool ManageMemory
Definition: vtkIdList.h:213
void InsertId(vtkIdType i, vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:221
vtkIdType * Release()
This releases the ownership of the internal vtkIdType array and returns the pointer to it.
void DeepCopy(vtkIdList *ids)
Copy an id list by explicitly copying the internal array.
vtkIdType InsertUniqueId(vtkIdType vtkid)
If id is not already in list, insert it and return location in list.
a simple class to control print indentation
Definition: vtkIndent.h:38
abstract base class for most VTK objects
Definition: vtkObject.h:61
@ value
Definition: vtkX3D.h:220
@ size
Definition: vtkX3D.h:253
int vtkIdType
Definition: vtkType.h:315
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_EXPECTS(x)