VTK  9.2.6
vtkIdList.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkIdList.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
23
24#ifndef vtkIdList_h
25#define vtkIdList_h
26
27#include "vtkCommonCoreModule.h" // For export macro
28#include "vtkObject.h"
29
30class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
31{
32public:
34
37 static vtkIdList* New();
38 vtkTypeMacro(vtkIdList, vtkObject);
39 void PrintSelf(ostream& os, vtkIndent indent) override;
41
45 void Initialize();
46
52 int Allocate(const vtkIdType sz, const int strategy = 0);
53
57 vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
58
63 {
64 return this->Ids[i];
65 }
66
71 {
72 for (int i = 0; i < this->NumberOfIds; i++)
73 if (this->Ids[i] == id)
74 return i;
75 return -1;
76 }
77
82 void SetNumberOfIds(const vtkIdType number);
83
89 void SetId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
90 {
91 this->Ids[i] = vtkid;
92 }
93
98 void InsertId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i);
99
103 vtkIdType InsertNextId(const vtkIdType vtkid);
104
110
115 void Sort();
116
121 void Fill(vtkIdType value);
122
126 vtkIdType* GetPointer(const vtkIdType i) { return this->Ids + i; }
127
133 vtkIdType* WritePointer(const vtkIdType i, const vtkIdType number);
134
140 void SetArray(vtkIdType* array, vtkIdType size, bool save = true);
141
145 void Reset() { this->NumberOfIds = 0; }
146
150 void Squeeze() { this->Resize(this->NumberOfIds); }
151
155 void DeepCopy(vtkIdList* ids);
156
160 void DeleteId(vtkIdType vtkid);
161
166 vtkIdType IsId(vtkIdType vtkid);
167
172 void IntersectWith(vtkIdList* otherIds);
173
179
180#ifndef __VTK_WRAP__
188#endif
189
191
194 vtkIdType* begin() { return this->Ids; }
195 vtkIdType* end() { return this->Ids + this->NumberOfIds; }
196 const vtkIdType* begin() const { return this->Ids; }
197 const vtkIdType* end() const { return this->Ids + this->NumberOfIds; }
199protected:
201 ~vtkIdList() override;
202
207
208private:
209 vtkIdList(const vtkIdList&) = delete;
210 void operator=(const vtkIdList&) = delete;
211};
212
213// In-lined for performance
214inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
215{
216 if (i >= this->Size)
217 {
218 this->Resize(i + 1);
219 }
220 this->Ids[i] = vtkid;
221 if (i >= this->NumberOfIds)
222 {
223 this->NumberOfIds = i + 1;
224 }
225}
226
227// In-lined for performance
229{
230 if (this->NumberOfIds >= this->Size)
231 {
232 if (!this->Resize(2 * this->NumberOfIds + 1)) // grow by factor of 2
233 {
234 return this->NumberOfIds - 1;
235 }
236 }
237 this->Ids[this->NumberOfIds++] = vtkid;
238 return this->NumberOfIds - 1;
239}
240
242{
243 vtkIdType *ptr, i;
244 for (ptr = this->Ids, i = 0; i < this->NumberOfIds; i++, ptr++)
245 {
246 if (vtkid == *ptr)
247 {
248 return i;
249 }
250 }
251 return (-1);
252}
253
254#endif
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition vtkIdList.h:70
void DeleteId(vtkIdType vtkid)
Delete specified id from list.
vtkIdType * Ids
Definition vtkIdList.h:205
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition vtkIdList.h:214
void IntersectWith(vtkIdList *otherIds)
Intersect this list with another vtkIdList.
vtkIdType NumberOfIds
Definition vtkIdList.h:203
~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.
vtkIdType * Resize(const vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).
vtkIdType Size
Definition vtkIdList.h:204
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
Definition vtkIdList.h:228
vtkIdType InsertUniqueId(const vtkIdType vtkid)
If id is not already in list, insert it and return location in list.
void Squeeze()
Free any unused memory.
Definition vtkIdList.h:150
vtkIdType * end()
To support range-based for loops.
Definition vtkIdList.h:195
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition vtkIdList.h:57
void Initialize()
Release memory and restore to unallocated state.
int Allocate(const vtkIdType sz, const int strategy=0)
Allocate a capacity for sz ids in the list and set the number of stored ids in the list to 0.
void SetId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition vtkIdList.h:89
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:241
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition vtkIdList.h:145
vtkIdType * WritePointer(const vtkIdType i, const vtkIdType number)
Get a pointer to a particular data index.
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instantiation, type information, and printing.
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition vtkIdList.h:62
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition vtkIdList.h:126
void Sort()
Sort the ids in the list in ascending id order.
vtkIdType * begin()
To support range-based for loops.
Definition vtkIdList.h:194
bool ManageMemory
Definition vtkIdList.h:206
vtkIdType * Release()
This releases the ownership of the internal vtkIdType array and returns the pointer to it.
void SetNumberOfIds(const vtkIdType number)
Specify the number of ids for this object to hold.
const vtkIdType * end() const
To support range-based for loops.
Definition vtkIdList.h:197
void DeepCopy(vtkIdList *ids)
Copy an id list by explicitly copying the internal array.
static vtkIdList * New()
Standard methods for instantiation, type information, and printing.
const vtkIdType * begin() const
To support range-based for loops.
Definition vtkIdList.h:196
a simple class to control print indentation
Definition vtkIndent.h:34
int vtkIdType
Definition vtkType.h:332
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_EXPECTS(x)