VTK  9.7.1
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 "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 
24 VTK_ABI_NAMESPACE_BEGIN
25 class VTKCOMMONCORE_EXPORT VTK_MARSHALAUTO vtkIdList : public vtkObject
26 {
27 public:
29  {
31  VTK_DATA_ARRAY_DELETE = vtkAbstractArray::VTK_DATA_ARRAY_DELETE,
32  VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
33  VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
34  };
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 
71  vtkTypeBool Reserve(vtkIdType size);
72 
76  vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
77 
81  vtkIdType GetId(vtkIdType i) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
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 
106  void SetNumberOfIds(vtkIdType number);
107 
113  void SetId(vtkIdType i, vtkIdType id) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
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 
133  vtkIdType InsertUniqueId(vtkIdType id);
134 
139  void Sort();
140 
145  void Fill(vtkIdType value);
146 
150  vtkIdType* GetPointer(vtkIdType i) { return this->Buffer->GetBuffer() + i; }
151 
157  vtkIdType* WritePointer(vtkIdType i, vtkIdType number);
158 
173  void SetList(
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 
197  void ShallowCopy(vtkIdList* list);
198 
202  void DeepCopy(vtkIdList* ids);
203 
207  void DeleteId(vtkIdType id);
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")
226  vtkIdType* Resize(vtkIdType sz);
227 
228 #ifndef __VTK_WRAP__
229 
235  vtkIdType* Release();
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; }
253 protected:
254  vtkIdList();
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")
266  void InitializeMemory();
267 
268  vtkIdType NumberOfIds;
270  vtkIdType Size VTK_DEPRECATED_IN_9_7_0("Use GetCapacity() instead");
271 
272 private:
273  vtkIdList(const vtkIdList&) = delete;
274  void operator=(const vtkIdList&) = delete;
275 };
276 
277 // In-lined for performance
278 inline 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 
305 inline 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 
317 VTK_ABI_NAMESPACE_END
318 #endif
vtkIdType InsertNextId(vtkIdType id)
Add the id specified to the end of the list.
Definition: vtkIdList.h:292
abstract base class for most VTK objects
Definition: vtkObject.h:52
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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
void Sort(RandomIt bitr, RandomIt eitr, BackToFront< T > &me)
int vtkIdType
Definition: vtkType.h:363
int vtkTypeBool
Definition: vtkABI.h:64
vtkIdType GetId(vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:81
void SetId(vtkIdType i, vtkIdType id)
Set the id at location i.
Definition: vtkIdList.h:113
internal storage class used by vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate, and others...
Definition: vtkBuffer.h:31
a simple class to control print indentation
Definition: vtkIndent.h:28
void save(Archiver &ar, const std::string &str, const unsigned int version)
list of point or cell ids
Definition: vtkIdList.h:25
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
const vtkIdType * begin() const
To support range-based for loops.
Definition: vtkIdList.h:250
vtkIdType * end()
To support range-based for loops.
Definition: vtkIdList.h:249
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition: vtkIdList.h:89
#define VTK_MARSHALAUTO
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
#define VTK_EXPECTS(x)
vtkIdType * begin()
To support range-based for loops.
Definition: vtkIdList.h:248
#define VTK_DEPRECATED_IN_9_7_0(reason)
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:150