VTK  9.5.2
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
15#ifndef vtkIdList_h
16#define vtkIdList_h
17
18#include "vtkCommonCoreModule.h" // For export macro
19#include "vtkObject.h"
20#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
21
22VTK_ABI_NAMESPACE_BEGIN
23class VTKCOMMONCORE_EXPORT VTK_MARSHALAUTO vtkIdList : public vtkObject
24{
25public:
27
30 static vtkIdList* New();
31 vtkTypeMacro(vtkIdList, vtkObject);
32 void PrintSelf(ostream& os, vtkIndent indent) override;
34
38 void Initialize();
39
45 int Allocate(vtkIdType sz, int strategy = 0);
46
50 vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
51
55 vtkIdType GetId(vtkIdType i) VTK_EXPECTS(0 <= i && i < GetNumberOfIds()) { return this->Ids[i]; }
56
61 {
62 for (int i = 0; i < this->NumberOfIds; i++)
63 if (this->Ids[i] == id)
64 return i;
65 return -1;
66 }
67
73
79 void SetId(vtkIdType i, vtkIdType vtkid) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
80 {
81 this->Ids[i] = vtkid;
82 }
83
88 void InsertId(vtkIdType i, vtkIdType vtkid) VTK_EXPECTS(0 <= i);
89
93 vtkIdType InsertNextId(vtkIdType vtkid);
94
100
105 void Sort();
106
112
116 vtkIdType* GetPointer(vtkIdType i) { return this->Ids + i; }
117
124
130 void SetArray(vtkIdType* array, vtkIdType size, bool save = true);
131
135 void Reset() { this->NumberOfIds = 0; }
136
140 void Squeeze() { this->Resize(this->NumberOfIds); }
141
145 void DeepCopy(vtkIdList* ids);
146
150 void DeleteId(vtkIdType vtkid);
151
156 vtkIdType IsId(vtkIdType vtkid) VTK_FUTURE_CONST;
157
162 void IntersectWith(vtkIdList* otherIds);
163
169
170#ifndef __VTK_WRAP__
178#endif
179
181
184 vtkIdType* begin() { return this->Ids; }
185 vtkIdType* end() { return this->Ids + this->NumberOfIds; }
186 const vtkIdType* begin() const { return this->Ids; }
187 const vtkIdType* end() const { return this->Ids + this->NumberOfIds; }
189protected:
191 ~vtkIdList() override;
192
196 bool AllocateInternal(vtkIdType sz, vtkIdType numberOfIds);
201
206
207private:
208 vtkIdList(const vtkIdList&) = delete;
209 void operator=(const vtkIdList&) = delete;
210};
211
212// In-lined for performance
213inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
214{
215 if (i >= this->Size)
216 {
217 this->Resize(i + 1);
218 }
219 this->Ids[i] = vtkid;
220 if (i >= this->NumberOfIds)
221 {
222 this->NumberOfIds = i + 1;
223 }
224}
225
226// In-lined for performance
228{
229 if (this->NumberOfIds >= this->Size)
230 {
231 if (!this->Resize(2 * this->NumberOfIds + 1)) // grow by factor of 2
232 {
233 return this->NumberOfIds - 1;
234 }
235 }
236 this->Ids[this->NumberOfIds++] = vtkid;
237 return this->NumberOfIds - 1;
238}
239
240inline vtkIdType vtkIdList::IsId(vtkIdType vtkid) VTK_FUTURE_CONST
241{
242 vtkIdType *ptr, i;
243 for (ptr = this->Ids, i = 0; i < this->NumberOfIds; i++, ptr++)
244 {
245 if (vtkid == *ptr)
246 {
247 return i;
248 }
249 }
250 return (-1);
251}
252
253VTK_ABI_NAMESPACE_END
254#endif
list of point or cell ids
Definition: vtkIdList.h:24
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition: vtkIdList.h:60
void DeleteId(vtkIdType vtkid)
Delete specified id from list.
vtkIdType * Ids
Definition: vtkIdList.h:204
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:202
~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:203
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:140
vtkIdType IsId(vtkIdType vtkid) VTK_FUTURE_CONST
Return -1 if id specified is not contained in the list; otherwise return the position in the list.
Definition: vtkIdList.h:240
vtkIdType * end()
To support range-based for loops.
Definition: vtkIdList.h:185
void InitializeMemory()
Release memory.
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:50
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:227
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:135
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:79
vtkIdType GetId(vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:55
void Sort()
Sort the ids in the list in ascending id order.
vtkIdType * begin()
To support range-based for loops.
Definition: vtkIdList.h:184
bool ManageMemory
Definition: vtkIdList.h:205
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:213
const vtkIdType * end() const
To support range-based for loops.
Definition: vtkIdList.h:187
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:116
static vtkIdList * New()
Standard methods for instantiation, type information, and printing.
const vtkIdType * begin() const
To support range-based for loops.
Definition: vtkIdList.h:186
a simple class to control print indentation
Definition: vtkIndent.h:29
abstract base class for most VTK objects
Definition: vtkObject.h:53
@ value
Definition: vtkX3D.h:220
@ size
Definition: vtkX3D.h:253
int vtkIdType
Definition: vtkType.h:332
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_EXPECTS(x)
#define VTK_MARSHALAUTO