VTK  9.7.20260805
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
14
15#ifndef vtkIdList_h
16#define vtkIdList_h
17
18#include "vtkAbstractArray.h" // For vtkAbstractArray::DeleteMethod
19#include "vtkBuffer.h" // For vtkBuffer
20#include "vtkCommonCoreModule.h" // For export macro
21#include "vtkObject.h"
22#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
23
24VTK_ABI_NAMESPACE_BEGIN
25class VTKCOMMONCORE_EXPORT VTK_MARSHALAUTO vtkIdList : public vtkObject
26{
27public:
35
37
40 static vtkIdList* New();
41 vtkTypeMacro(vtkIdList, vtkObject);
42 void PrintSelf(ostream& os, vtkIndent indent) override;
44
48 void Initialize();
49
58 VTK_DEPRECATED_IN_9_7_0("Use Reserve() to allocate or Initialize() to deallocate.")
59 vtkTypeBool Allocate(vtkIdType size, int strategy = 0);
60
72
76 vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
77
82 {
83 return this->Buffer->GetBuffer()[i];
84 }
85
90 {
91 for (int i = 0; i < this->NumberOfIds; i++)
92 {
93 if (this->Buffer->GetBuffer()[i] == id)
94 {
95 return i;
96 }
97 }
98 return -1;
99 }
100
107
114 {
115 this->Buffer->GetBuffer()[i] = id;
116 }
117
122 void InsertId(vtkIdType i, vtkIdType id) VTK_EXPECTS(0 <= i);
123
127 vtkIdType InsertNextId(vtkIdType id);
128
134
139 void Sort();
140
145 void Fill(vtkIdType value);
146
150 vtkIdType* GetPointer(vtkIdType i) { return this->Buffer->GetBuffer() + i; }
151
158
174 vtkIdType* array, vtkIdType size, bool save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
175
180 VTK_DEPRECATED_IN_9_7_0("Use SetList instead")
181 void SetArray(vtkIdType* array, vtkIdType size, bool manageMemory = true);
182
186 void Reset() { this->NumberOfIds = 0; }
187
191 void Squeeze();
192
198
202 void DeepCopy(vtkIdList* ids);
203
208
213 vtkIdType IsId(vtkIdType id) VTK_FUTURE_CONST;
214
219 void IntersectWith(vtkIdList* otherIds);
220
225 VTK_DEPRECATED_IN_9_7_0("Use Reserve, Squeeze or Initialize")
227
228#ifndef __VTK_WRAP__
236#endif
237
242 vtkIdType GetCapacity() const { return this->Buffer->GetNumberOfElements(); }
243
245
248 vtkIdType* begin() { return this->Buffer->GetBuffer(); }
249 vtkIdType* end() { return this->Buffer->GetBuffer() + this->NumberOfIds; }
250 const vtkIdType* begin() const { return this->Buffer->GetBuffer(); }
251 const vtkIdType* end() const { return this->Buffer->GetBuffer() + this->NumberOfIds; }
253protected:
255 ~vtkIdList() override;
256
260 VTK_DEPRECATED_IN_9_7_0("Use Allocate and SetNumberOfIds instead")
261 bool AllocateInternal(vtkIdType sz, vtkIdType numberOfIds);
265 VTK_DEPRECATED_IN_9_7_0("Use Allocate(0) instead")
267
270 vtkIdType Size VTK_DEPRECATED_IN_9_7_0("Use GetCapacity() instead");
271
272private:
273 vtkIdList(const vtkIdList&) = delete;
274 void operator=(const vtkIdList&) = delete;
275};
276
277// In-lined for performance
278inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType id)
279{
280 if (i >= this->GetCapacity())
281 {
282 this->Reserve(i + 1);
283 }
284 this->Buffer->GetBuffer()[i] = id;
285 if (i >= this->NumberOfIds)
286 {
287 this->NumberOfIds = i + 1;
288 }
289}
290
291// In-lined for performance
293{
294 if (this->NumberOfIds >= this->GetCapacity())
295 {
296 if (!this->Reserve(this->NumberOfIds + 1))
297 {
298 return this->NumberOfIds - 1;
299 }
300 }
301 this->Buffer->GetBuffer()[this->NumberOfIds++] = id;
302 return this->NumberOfIds - 1;
303}
304
305inline vtkIdType vtkIdList::IsId(vtkIdType id) VTK_FUTURE_CONST
306{
307 for (vtkIdType i = 0; i < this->NumberOfIds; ++i)
308 {
309 if (this->Buffer->GetBuffer()[i] == id)
310 {
311 return i;
312 }
313 }
314 return -1;
315}
316
317VTK_ABI_NAMESPACE_END
318#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:89
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:292
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:268
~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:270
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:249
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:305
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition vtkIdList.h:76
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:186
vtkBuffer< vtkIdType > * Buffer
Definition vtkIdList.h:269
void InsertId(vtkIdType i, vtkIdType id)
Set the id at location i.
Definition vtkIdList.h:278
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:81
void Sort()
Sort the ids in the list in ascending id order.
vtkIdType * begin()
To support range-based for loops.
Definition vtkIdList.h:248
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:242
const vtkIdType * end() const
To support range-based for loops.
Definition vtkIdList.h:251
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:113
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
Definition vtkIdList.h:150
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:250
@ VTK_DATA_ARRAY_DELETE
Definition vtkIdList.h:31
@ VTK_DATA_ARRAY_FREE
Definition vtkIdList.h:30
@ VTK_DATA_ARRAY_ALIGNED_FREE
Definition vtkIdList.h:32
@ VTK_DATA_ARRAY_USER_DEFINED
Definition vtkIdList.h:33
a simple class to control print indentation
Definition vtkIndent.h:29
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