VTK  9.6.20260405
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 VTK_DEPRECATED_IN_9_7_0("Use Reserve() to allocate or Initialize() to deallocate.")
168 vtkTypeBool Allocate(vtkIdType size, int strategy = 0);
169
181
185 vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
186
191 {
192 return this->Buffer->GetBuffer()[i];
193 }
194
199 {
200 for (int i = 0; i < this->NumberOfIds; i++)
201 {
202 if (this->Buffer->GetBuffer()[i] == id)
203 {
204 return i;
205 }
206 }
207 return -1;
208 }
209
216
223 {
224 this->Buffer->GetBuffer()[i] = id;
225 }
226
231 void InsertId(vtkIdType i, vtkIdType id) VTK_EXPECTS(0 <= i);
232
236 vtkIdType InsertNextId(vtkIdType id);
237
243
248 void Sort();
249
254 void Fill(vtkIdType value);
255
259 vtkIdType* GetPointer(vtkIdType i) { return this->Buffer->GetBuffer() + i; }
260
267
283 vtkIdType* array, vtkIdType size, bool save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
284
289 VTK_DEPRECATED_IN_9_7_0("Use SetList instead")
290 void SetArray(vtkIdType* array, vtkIdType size, bool manageMemory = true);
291
295 void Reset() { this->NumberOfIds = 0; }
296
300 void Squeeze();
301
307
311 void DeepCopy(vtkIdList* ids);
312
317
322 vtkIdType IsId(vtkIdType id) VTK_FUTURE_CONST;
323
328 void IntersectWith(vtkIdList* otherIds);
329
334 VTK_DEPRECATED_IN_9_7_0("Use Reserve, Squeeze or Initialize")
336
337#ifndef __VTK_WRAP__
345#endif
346
351 vtkIdType GetCapacity() const { return this->Buffer->GetNumberOfElements(); }
352
354
357 vtkIdType* begin() { return this->Buffer->GetBuffer(); }
358 vtkIdType* end() { return this->Buffer->GetBuffer() + this->NumberOfIds; }
359 const vtkIdType* begin() const { return this->Buffer->GetBuffer(); }
360 const vtkIdType* end() const { return this->Buffer->GetBuffer() + this->NumberOfIds; }
362protected:
364 ~vtkIdList() override;
365
369 VTK_DEPRECATED_IN_9_7_0("Use Allocate and SetNumberOfIds instead")
370 bool AllocateInternal(vtkIdType sz, vtkIdType numberOfIds);
374 VTK_DEPRECATED_IN_9_7_0("Use Allocate(0) instead")
376
379 vtkIdType Size VTK_DEPRECATED_IN_9_7_0("Use GetCapacity() instead");
380
381private:
382 vtkIdList(const vtkIdList&) = delete;
383 void operator=(const vtkIdList&) = delete;
384};
385
386// In-lined for performance
387inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType id)
388{
389 if (i >= this->GetCapacity())
390 {
391 this->Reserve(i + 1);
392 }
393 this->Buffer->GetBuffer()[i] = id;
394 if (i >= this->NumberOfIds)
395 {
396 this->NumberOfIds = i + 1;
397 }
398}
399
400// In-lined for performance
402{
403 if (this->NumberOfIds >= this->GetCapacity())
404 {
405 if (!this->Reserve(this->NumberOfIds + 1))
406 {
407 return this->NumberOfIds - 1;
408 }
409 }
410 this->Buffer->GetBuffer()[this->NumberOfIds++] = id;
411 return this->NumberOfIds - 1;
412}
413
414inline vtkIdType vtkIdList::IsId(vtkIdType id) VTK_FUTURE_CONST
415{
416 for (vtkIdType i = 0; i < this->NumberOfIds; ++i)
417 {
418 if (this->Buffer->GetBuffer()[i] == id)
419 {
420 return i;
421 }
422 }
423 return -1;
424}
425
426VTK_ABI_NAMESPACE_END
427#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:198
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:401
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:377
~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:379
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:358
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:414
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition vtkIdList.h:185
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:295
vtkBuffer< vtkIdType > * Buffer
Definition vtkIdList.h:378
void InsertId(vtkIdType i, vtkIdType id)
Set the id at location i.
Definition vtkIdList.h:387
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:190
void Sort()
Sort the ids in the list in ascending id order.
vtkIdType * begin()
To support range-based for loops.
Definition vtkIdList.h:357
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:351
const vtkIdType * end() const
To support range-based for loops.
Definition vtkIdList.h:360
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:222
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
Definition vtkIdList.h:259
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:359
@ 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