VTK  9.3.20240424
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
124#ifndef vtkIdList_h
125#define vtkIdList_h
126
127#include "vtkCommonCoreModule.h" // For export macro
128#include "vtkObject.h"
129#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
130
131VTK_ABI_NAMESPACE_BEGIN
132class VTKCOMMONCORE_EXPORT VTK_MARSHALAUTO vtkIdList : public vtkObject
133{
134public:
136
139 static vtkIdList* New();
140 vtkTypeMacro(vtkIdList, vtkObject);
141 void PrintSelf(ostream& os, vtkIndent indent) override;
143
148
154 int Allocate(vtkIdType sz, int strategy = 0);
155
159 vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
160
164 vtkIdType GetId(vtkIdType i) VTK_EXPECTS(0 <= i && i < GetNumberOfIds()) { return this->Ids[i]; }
165
170 {
171 for (int i = 0; i < this->NumberOfIds; i++)
172 if (this->Ids[i] == id)
173 return i;
174 return -1;
175 }
176
182
188 void SetId(vtkIdType i, vtkIdType vtkid) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
189 {
190 this->Ids[i] = vtkid;
191 }
192
197 void InsertId(vtkIdType i, vtkIdType vtkid) VTK_EXPECTS(0 <= i);
198
202 vtkIdType InsertNextId(vtkIdType vtkid);
203
209
214 void Sort();
215
220 void Fill(vtkIdType value);
221
225 vtkIdType* GetPointer(vtkIdType i) { return this->Ids + i; }
226
233
239 void SetArray(vtkIdType* array, vtkIdType size, bool save = true);
240
244 void Reset() { this->NumberOfIds = 0; }
245
249 void Squeeze() { this->Resize(this->NumberOfIds); }
250
254 void DeepCopy(vtkIdList* ids);
255
259 void DeleteId(vtkIdType vtkid);
260
265 vtkIdType IsId(vtkIdType vtkid);
266
271 void IntersectWith(vtkIdList* otherIds);
272
278
279#ifndef __VTK_WRAP__
287#endif
288
290
293 vtkIdType* begin() { return this->Ids; }
294 vtkIdType* end() { return this->Ids + this->NumberOfIds; }
295 const vtkIdType* begin() const { return this->Ids; }
296 const vtkIdType* end() const { return this->Ids + this->NumberOfIds; }
298protected:
300 ~vtkIdList() override;
301
305 bool AllocateInternal(vtkIdType sz, vtkIdType numberOfIds);
310
315
316private:
317 vtkIdList(const vtkIdList&) = delete;
318 void operator=(const vtkIdList&) = delete;
319};
320
321// In-lined for performance
322inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
323{
324 if (i >= this->Size)
325 {
326 this->Resize(i + 1);
327 }
328 this->Ids[i] = vtkid;
329 if (i >= this->NumberOfIds)
330 {
331 this->NumberOfIds = i + 1;
332 }
333}
334
335// In-lined for performance
337{
338 if (this->NumberOfIds >= this->Size)
339 {
340 if (!this->Resize(2 * this->NumberOfIds + 1)) // grow by factor of 2
341 {
342 return this->NumberOfIds - 1;
343 }
344 }
345 this->Ids[this->NumberOfIds++] = vtkid;
346 return this->NumberOfIds - 1;
347}
348
350{
351 vtkIdType *ptr, i;
352 for (ptr = this->Ids, i = 0; i < this->NumberOfIds; i++, ptr++)
353 {
354 if (vtkid == *ptr)
355 {
356 return i;
357 }
358 }
359 return (-1);
360}
361
362VTK_ABI_NAMESPACE_END
363#endif
list of point or cell ids
Definition vtkIdList.h:133
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition vtkIdList.h:169
void DeleteId(vtkIdType vtkid)
Delete specified id from list.
vtkIdType * Ids
Definition vtkIdList.h:313
void SetNumberOfIds(vtkIdType number)
Specify the number of ids for this object to hold.
void IntersectWith(vtkIdList *otherIds)
Intersect this list with another vtkIdList.
vtkIdType NumberOfIds
Definition vtkIdList.h:311
~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 * WritePointer(vtkIdType i, vtkIdType number)
Get a pointer to a particular data index.
vtkIdType Size
Definition vtkIdList.h:312
vtkIdType * Resize(vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).
void Squeeze()
Free any unused memory.
Definition vtkIdList.h:249
vtkIdType * end()
To support range-based for loops.
Definition vtkIdList.h:294
void InitializeMemory()
Release memory.
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition vtkIdList.h:159
void Initialize()
Release memory and restore to unallocated state.
bool AllocateInternal(vtkIdType sz, vtkIdType numberOfIds)
Allocate ids and set the number of ids.
vtkIdType InsertNextId(vtkIdType vtkid)
Add the id specified to the end of the list.
Definition vtkIdList.h:336
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:349
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition vtkIdList.h:244
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:188
vtkIdType GetId(vtkIdType i)
Return the id at location i.
Definition vtkIdList.h:164
void Sort()
Sort the ids in the list in ascending id order.
vtkIdType * begin()
To support range-based for loops.
Definition vtkIdList.h:293
bool ManageMemory
Definition vtkIdList.h:314
vtkIdType * Release()
This releases the ownership of the internal vtkIdType array and returns the pointer to it.
void InsertId(vtkIdType i, vtkIdType vtkid)
Set the id at location i.
Definition vtkIdList.h:322
const vtkIdType * end() const
To support range-based for loops.
Definition vtkIdList.h:296
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.
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
Definition vtkIdList.h:225
static vtkIdList * New()
Standard methods for instantiation, type information, and printing.
const vtkIdType * begin() const
To support range-based for loops.
Definition vtkIdList.h:295
a simple class to control print indentation
Definition vtkIndent.h:108
abstract base class for most VTK objects
Definition vtkObject.h:162
int vtkIdType
Definition vtkType.h:315
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_EXPECTS(x)
#define VTK_MARSHALAUTO