VTK  9.3.20240419
vtkVoidArray.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
12 #ifndef vtkVoidArray_h
13 #define vtkVoidArray_h
14 
15 #include "vtkCommonCoreModule.h" // For export macro
16 #include "vtkObject.h"
17 
18 VTK_ABI_NAMESPACE_BEGIN
19 class VTKCOMMONCORE_EXPORT vtkVoidArray : public vtkObject
20 {
21 public:
25  static vtkVoidArray* New();
27 
28  vtkTypeMacro(vtkVoidArray, vtkObject);
29  void PrintSelf(ostream& os, vtkIndent indent) override;
30 
36 
40  void Initialize();
41 
45  int GetDataType() const { return VTK_VOID; }
46 
50  int GetDataTypeSize() { return sizeof(void*); }
51 
56  {
57  this->Allocate(number);
58  this->NumberOfPointers = number;
59  }
60 
64  vtkIdType GetNumberOfPointers() { return this->NumberOfPointers; }
65 
69  void* GetVoidPointer(vtkIdType id) { return this->Array[id]; }
70 
74  void SetVoidPointer(vtkIdType id, void* ptr) { this->Array[id] = ptr; }
75 
80  void InsertVoidPointer(vtkIdType i, void* ptr);
81 
87 
92  void Reset() { this->NumberOfPointers = 0; }
93 
97  void Squeeze() { this->ResizeAndExtend(this->NumberOfPointers); }
98 
103  void** GetPointer(vtkIdType id) { return this->Array + id; }
104 
110  void** WritePointer(vtkIdType id, vtkIdType number);
111 
116 
117 protected:
119  ~vtkVoidArray() override;
120 
123  void** Array; // pointer to data
124 
125  void** ResizeAndExtend(vtkIdType sz); // function to resize data
126 
127 private:
128  vtkVoidArray(const vtkVoidArray&) = delete;
129  void operator=(const vtkVoidArray&) = delete;
130 };
131 
132 VTK_ABI_NAMESPACE_END
133 #endif
a simple class to control print indentation
Definition: vtkIndent.h:108
abstract base class for most VTK objects
Definition: vtkObject.h:162
dynamic, self-adjusting array of void* pointers
Definition: vtkVoidArray.h:20
vtkIdType InsertNextVoidPointer(void *tuple)
Insert (memory allocation performed) the void* pointer at the end of the array.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkVoidArray * New()
Initialize with empty array.
static vtkVoidArray * ExtendedNew()
void Squeeze()
Resize the array to just fit the inserted memory.
Definition: vtkVoidArray.h:97
void ** WritePointer(vtkIdType id, vtkIdType number)
Get the address of a particular data index.
~vtkVoidArray() override
void SetVoidPointer(vtkIdType id, void *ptr)
Set the void* pointer value at the ith location in the array.
Definition: vtkVoidArray.h:74
void * GetVoidPointer(vtkIdType id)
Get the void* pointer at the ith location.
Definition: vtkVoidArray.h:69
void SetNumberOfPointers(vtkIdType number)
Set the number of void* pointers held in the array.
Definition: vtkVoidArray.h:55
void Initialize()
Release storage and reset array to initial state.
vtkIdType GetNumberOfPointers()
Get the number of void* pointers held in the array.
Definition: vtkVoidArray.h:64
vtkIdType NumberOfPointers
Definition: vtkVoidArray.h:121
void InsertVoidPointer(vtkIdType i, void *ptr)
Insert (memory allocation performed) the void* into the ith location in the array.
void Reset()
Reuse already allocated data; make the container look like it is empty.
Definition: vtkVoidArray.h:92
void ** ResizeAndExtend(vtkIdType sz)
void DeepCopy(vtkVoidArray *va)
Deep copy of another void array.
void ** Array
Definition: vtkVoidArray.h:123
int GetDataType() const
Return the type of data.
Definition: vtkVoidArray.h:45
void ** GetPointer(vtkIdType id)
Get the address of a particular data index.
Definition: vtkVoidArray.h:103
vtkIdType Size
Definition: vtkVoidArray.h:122
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000)
Allocate memory for this array.
int GetDataTypeSize()
Return the size of the data contained in the array.
Definition: vtkVoidArray.h:50
int vtkTypeBool
Definition: vtkABI.h:64
int vtkIdType
Definition: vtkType.h:315
#define VTK_VOID
Definition: vtkType.h:31