VTK  9.6.20260315
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
123
124#ifndef vtkIdList_h
125#define vtkIdList_h
126
127#include "vtkAbstractArray.h" // For vtkAbstractArray::DeleteMethod
128#include "vtkBuffer.h" // For vtkBuffer
129#include "vtkCommonCoreModule.h" // For export macro
130#include "vtkObject.h"
131#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
132
133VTK_ABI_NAMESPACE_BEGIN
134class VTKCOMMONCORE_EXPORT VTK_MARSHALAUTO vtkIdList : public vtkObject
135{
136public:
144
146
149 static vtkIdList* New();
150 vtkTypeMacro(vtkIdList, vtkObject);
151 void PrintSelf(ostream& os, vtkIndent indent) override;
153
158
167 vtkTypeBool Allocate(vtkIdType size, int strategy = 0);
168
178
182 vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
183
188 {
189 return this->Buffer->GetBuffer()[i];
190 }
191
196 {
197 for (int i = 0; i < this->NumberOfIds; i++)
198 {
199 if (this->Buffer->GetBuffer()[i] == id)
200 {
201 return i;
202 }
203 }
204 return -1;
205 }
206
213
220 {
221 this->Buffer->GetBuffer()[i] = id;
222 }
223
228 void InsertId(vtkIdType i, vtkIdType id) VTK_EXPECTS(0 <= i);
229
233 vtkIdType InsertNextId(vtkIdType id);
234
240
245 void Sort();
246
251 void Fill(vtkIdType value);
252
256 vtkIdType* GetPointer(vtkIdType i) { return this->Buffer->GetBuffer() + i; }
257
264
280 vtkIdType* array, vtkIdType size, bool save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
281
286 VTK_DEPRECATED_IN_9_7_0("Use SetList instead")
287 void SetArray(vtkIdType* array, vtkIdType size, bool manageMemory = true);
288
292 void Reset() { this->NumberOfIds = 0; }
293
297 void Squeeze();
298
304
308 void DeepCopy(vtkIdList* ids);
309
314
319 vtkIdType IsId(vtkIdType id) VTK_FUTURE_CONST;
320
325 void IntersectWith(vtkIdList* otherIds);
326
331 VTK_DEPRECATED_IN_9_7_0("Use Reserve, Squeeze or Initialize")
333
334#ifndef __VTK_WRAP__
342#endif
343
348 vtkIdType GetCapacity() const { return this->Buffer->GetNumberOfElements(); }
349
351
354 vtkIdType* begin() { return this->Buffer->GetBuffer(); }
355 vtkIdType* end() { return this->Buffer->GetBuffer() + this->NumberOfIds; }
356 const vtkIdType* begin() const { return this->Buffer->GetBuffer(); }
357 const vtkIdType* end() const { return this->Buffer->GetBuffer() + this->NumberOfIds; }
359protected:
361 ~vtkIdList() override;
362
366 VTK_DEPRECATED_IN_9_7_0("Use Allocate and SetNumberOfIds instead")
367 bool AllocateInternal(vtkIdType sz, vtkIdType numberOfIds);
371 VTK_DEPRECATED_IN_9_7_0("Use Allocate(0) instead")
373
376 vtkIdType Size VTK_DEPRECATED_IN_9_7_0("Use GetCapacity() instead");
377
378private:
379 vtkIdList(const vtkIdList&) = delete;
380 void operator=(const vtkIdList&) = delete;
381};
382
383// In-lined for performance
384inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType id)
385{
386 if (i >= this->GetCapacity())
387 {
388 this->Reserve(i + 1);
389 }
390 this->Buffer->GetBuffer()[i] = id;
391 if (i >= this->NumberOfIds)
392 {
393 this->NumberOfIds = i + 1;
394 }
395}
396
397// In-lined for performance
399{
400 if (this->NumberOfIds >= this->GetCapacity())
401 {
402 if (!this->Reserve(this->NumberOfIds + 1))
403 {
404 return this->NumberOfIds - 1;
405 }
406 }
407 this->Buffer->GetBuffer()[this->NumberOfIds++] = id;
408 return this->NumberOfIds - 1;
409}
410
411inline vtkIdType vtkIdList::IsId(vtkIdType id) VTK_FUTURE_CONST
412{
413 for (vtkIdType i = 0; i < this->NumberOfIds; ++i)
414 {
415 if (this->Buffer->GetBuffer()[i] == id)
416 {
417 return i;
418 }
419 }
420 return -1;
421}
422
423VTK_ABI_NAMESPACE_END
424#endif
internal storage class used by vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate, and others.
Definition vtkBuffer.h:32
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition vtkIdList.h:195
vtkIdType InsertUniqueId(vtkIdType id)
If id is not already in list, insert it and return location in list.
vtkIdType InsertNextId(vtkIdType id)
Add the id specified to the end of the list.
Definition vtkIdList.h:398
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:374
~vtkIdList() override
void Fill(vtkIdType value)
Fill the ids with the input value.
vtkIdType * WritePointer(vtkIdType i, vtkIdType number)
Get a pointer to a particular data index.
vtkIdType Size
Definition vtkIdList.h:376
vtkIdType * Resize(vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).
void SetArray(vtkIdType *array, vtkIdType size, bool manageMemory=true)
This method does the same as SetList but the save and manageMemory are opposite.
void Squeeze()
Free any unused memory.
vtkIdType * end()
To support range-based for loops.
Definition vtkIdList.h:355
void InitializeMemory()
Release memory.
void SetList(vtkIdType *array, vtkIdType size, bool save, int deleteMethod=VTK_DATA_ARRAY_DELETE)
This method let's the user specify data to be held by the id list.
void DeleteId(vtkIdType id)
Delete specified id from list.
vtkIdType IsId(vtkIdType id) VTK_FUTURE_CONST
Return -1 if id specified is not contained in the list; otherwise return the position in the list.
Definition vtkIdList.h:411
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition vtkIdList.h:182
void Initialize()
Release memory and restore to unallocated state.
bool AllocateInternal(vtkIdType sz, vtkIdType numberOfIds)
Allocate ids and set the number of ids.
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition vtkIdList.h:292
vtkBuffer< vtkIdType > * Buffer
Definition vtkIdList.h:375
void InsertId(vtkIdType i, vtkIdType id)
Set the id at location i.
Definition vtkIdList.h:384
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instantiation, type information, and printing.
vtkTypeBool Allocate(vtkIdType size, int strategy=0)
Allocate memory for this id list.
vtkIdType GetId(vtkIdType i)
Return the id at location i.
Definition vtkIdList.h:187
void Sort()
Sort the ids in the list in ascending id order.
vtkIdType * begin()
To support range-based for loops.
Definition vtkIdList.h:354
vtkIdType * Release()
This releases the ownership of the internal vtkIdType array and returns the pointer to it.
void ShallowCopy(vtkIdList *list)
Copy an id list by copying the internal buffer pointer.
vtkIdType GetCapacity() const
Get the capacity of the id list.
Definition vtkIdList.h:348
const vtkIdType * end() const
To support range-based for loops.
Definition vtkIdList.h:357
void DeepCopy(vtkIdList *ids)
Copy an id list by explicitly copying the internal array.
void SetId(vtkIdType i, vtkIdType id)
Set the id at location i.
Definition vtkIdList.h:219
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
Definition vtkIdList.h:256
static vtkIdList * New()
Standard methods for instantiation, type information, and printing.
vtkTypeBool Reserve(vtkIdType size)
Reserve the id list to the requested number of ids and preserve data.
const vtkIdType * begin() const
To support range-based for loops.
Definition vtkIdList.h:356
@ VTK_DATA_ARRAY_DELETE
Definition vtkIdList.h:140
@ VTK_DATA_ARRAY_FREE
Definition vtkIdList.h:139
@ VTK_DATA_ARRAY_ALIGNED_FREE
Definition vtkIdList.h:141
@ VTK_DATA_ARRAY_USER_DEFINED
Definition vtkIdList.h:142
a simple class to control print indentation
Definition vtkIndent.h:108
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_DEPRECATED_IN_9_7_0(reason)
int vtkIdType
Definition vtkType.h:363
void save(Archiver &ar, const std::string &str, const unsigned int version)
#define VTK_EXPECTS(x)
#define VTK_MARSHALAUTO