VTK  9.6.20260222
vtkVariantArray.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-FileCopyrightText: Copyright 2008 Sandia Corporation
3// SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
86
87#ifndef vtkVariantArray_h
88#define vtkVariantArray_h
89
90#include "vtkAbstractArray.h"
91#include "vtkBuffer.h" // For vtkBuffer
92#include "vtkCommonCoreModule.h" // For export macro
93#include "vtkVariant.h" // For variant type
94#include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
95
97namespace boost
98{
100{
101class access;
102}
103}
104
105VTK_ABI_NAMESPACE_BEGIN
106class vtkVariantArrayLookup;
107
108class VTKCOMMONCORE_EXPORT VTK_MARSHALMANUAL vtkVariantArray : public vtkAbstractArray
109{
110
112 friend class boost::serialization::access;
113
114public:
122 using ArrayTypeTag = std::integral_constant<int, vtkArrayTypes::VTK_VARIANT_ARRAY>;
123 using DataTypeTag = std::integral_constant<int, VTK_VARIANT>;
125
129 void PrintSelf(ostream& os, vtkIndent indent) override;
130
138
139 //
140 // Functions required by vtkAbstractArray
141 //
142
147 vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext = 1000) override;
148
152 void Initialize() override;
153
158 bool CopyComponent(int dstComponent, vtkAbstractArray* src, int srcComponent) override;
159
163 int GetArrayType() const override { return vtkVariantArray::ArrayTypeTag::value; }
164
169 int GetDataType() const override;
170
176 int GetDataTypeSize() const override;
177
185 int GetElementComponentSize() const override;
186
191 void SetNumberOfTuples(vtkIdType number) override;
192
200
206
212 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
213
215 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
216
223 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
224
231
236 void* GetVoidPointer(vtkIdType id) override;
237
243 void DeepCopy(vtkAbstractArray* da) override;
244
250 void ShallowCopy(vtkAbstractArray* src) override;
251
260 vtkIdType i, vtkIdList* ptIndices, vtkAbstractArray* source, double* weights) override;
261
271 vtkAbstractArray* source2, double t) override;
272
278 void Squeeze() override { this->Resize(this->GetNumberOfTuples()); }
279
284 vtkTypeBool Resize(vtkIdType numTuples) override;
285
287
295 void SetVoidArray(void* array, vtkIdType size, int save) override
296 {
297 this->SetArray(static_cast<ValueType*>(array), size, save);
298 }
299 void SetVoidArray(void* array, vtkIdType size, int save, int deleteMethod) override
300 {
301 this->SetArray(static_cast<ValueType*>(array), size, save, deleteMethod);
302 }
303
304
313 unsigned long GetActualMemorySize() const override;
314
318 int IsNumeric() const override;
319
324 VTK_DEPRECATED_IN_9_7_0("Use vtk::DataArrayValueRange, or the array directly")
326
330 ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
331 VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + comp < GetNumberOfValues())
332 VTK_EXPECTS(0 <= comp && comp < GetNumberOfComponents());
333
335
338 void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
339 VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + comp < GetNumberOfValues())
340 VTK_EXPECTS(0 <= comp && comp < GetNumberOfComponents());
342
344
347 void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
348 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
350
352
355 void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
356 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
358
363
369 VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues());
370
376 void InsertValue(vtkIdType id, ValueType value) VTK_EXPECTS(0 <= id);
377
382
386 void SetVariantValue(vtkIdType idx, ValueType value) override;
387
391 void InsertVariantValue(vtkIdType idx, ValueType value) override;
392
398
403
409#ifdef __VTK_WRAP__
410 vtkAbstractBuffer* GetBuffer() { return this->Buffer; }
411#else
413#endif // __VTK_WRAP__
414
418 void SetArray(ValueType* arr, vtkIdType size, int save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
419
426 void SetArrayFreeFunction(void (*callback)(void*)) override;
427
429
433 void LookupValue(ValueType value, vtkIdList* ids) override;
435
444 void DataChanged() override;
445
451 VTK_DEPRECATED_IN_9_7_0("Use DataChanged() instead")
453
459 void ClearLookup() override;
460
465 ~vtkVariantArray() override;
466
467protected:
468 // Construct object with default tuple dimension (number of components) of 1.
470
475 bool AllocateTuples(vtkIdType numTuples);
476
481
486
488
492 VTK_DEPRECATED_IN_9_7_0("Use Resize")
494 {
495 this->Resize(sz);
496 return this->Buffer->GetBuffer();
497 }
498
499private:
500 vtkVariantArray(const vtkVariantArray&) = delete;
501 void operator=(const vtkVariantArray&) = delete;
502
503 vtkVariantArrayLookup* Lookup;
504 void UpdateLookup();
505};
506
507// Declare vtkArrayDownCast implementations for vtkVariantArray:
509
510VTK_ABI_NAMESPACE_END
511#endif
int GetNumberOfComponents() const
Set/Get the dimension (n) of the components.
virtual vtkTypeBool Resize(vtkIdType numTuples)=0
Resize the array to the requested number of tuples and preserve data.
vtkIdType GetNumberOfTuples() const
Get the number of complete tuples (a component group) in the array.
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
Abstract base class for vtkBuffer providing buffer protocol support.
Abstract superclass to iterate over elements in an vtkAbstractArray.
internal storage class used by vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate, and others.
Definition vtkBuffer.h:32
list of point or cell ids
Definition vtkIdList.h:133
a simple class to control print indentation
Definition vtkIndent.h:108
An array holding vtkVariants.
bool CopyComponent(int dstComponent, vtkAbstractArray *src, int srcComponent) override
Copy one component from src into a (potentially different) component of this array.
static vtkVariantArray * New()
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
Copy the tuple at tupleIdx into tuple.
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000) override
Allocate memory for this array.
int GetDataType() const override
Return the underlying data type.
void SetArrayFreeFunction(void(*callback)(void *)) override
This method allows the user to specify a custom free function to be called when the array is dealloca...
static vtkVariantArray * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkVariantArray.
vtkBuffer< ValueType > * Buffer
void LookupValue(ValueType value, vtkIdList *ids) override
Return the indices where a specific value appears.
void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source) override
Copy the tuples indexed in srcIds from the source array to the tuple locations indexed by dstIds in t...
void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
Set component comp of the tuple at tupleIdx to value.
static vtkVariantArray * ExtendedNew()
vtkTypeBool Resize(vtkIdType numTuples) override
Resize the array while conserving the data.
void InsertTuplesStartingAt(vtkIdType dstStart, vtkIdList *srcIds, vtkAbstractArray *source) override
Copy the tuples indexed in srcIds from the source array to the tuple locations starting at index dstS...
std::integral_constant< int, VTK_VARIANT > DataTypeTag
ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
Get component comp of the tuple at tupleIdx.
void SetValue(vtkIdType id, ValueType value)
Set the data at a particular index.
vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
void SetArray(ValueType *arr, vtkIdType size, int save, int deleteMethod=VTK_DATA_ARRAY_DELETE)
Set the internal array used by this object.
void ClearLookup() override
Delete the associated fast lookup data structure on this array, if it exists.
unsigned long GetActualMemorySize() const override
Return the memory in kibibytes (1024 bytes) consumed by this data array.
int GetArrayType() const override
Return the array type.
void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source) override
Set the tuple at the ith location using the jth tuple in the source array.
bool ReallocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
bool AllocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray *source) override
Insert the jth tuple in the source array, at the end in this array.
int GetDataTypeSize() const override
Return the size of the underlying data type.
void SetNumberOfTuples(vtkIdType number) override
Set the number of tuples (a component group) in the array.
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
Set this array's tuple at tupleIdx to the values in tuple.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void DataElementChanged(vtkIdType id)
Tell the array explicitly that a single data element has changed.
void InterpolateTuple(vtkIdType i, vtkIdList *ptIndices, vtkAbstractArray *source, double *weights) override
Set the ith tuple in this array as the interpolated tuple value, given the ptIndices in the source ar...
vtkIdType InsertNextValue(ValueType value)
Expand the array by one and set the value at that location.
ValueType & GetValue(vtkIdType id) const
Get the data at a particular index.
ValueType * ResizeAndExtend(vtkIdType sz)
Function to resize data.
void SetVoidArray(void *array, vtkIdType size, int save) override
This method lets the user specify data to be held by the array.
void InterpolateTuple(vtkIdType i, vtkIdType id1, vtkAbstractArray *source1, vtkIdType id2, vtkAbstractArray *source2, double t) override
Insert the ith tuple in this array as interpolated from the two values, p1 and p2,...
void DeepCopy(vtkAbstractArray *da) override
Deep copy of data.
void ShallowCopy(vtkAbstractArray *src) override
This method will copy the data from the source array to this array.
vtkBuffer< ValueType > * GetBuffer()
Return the underlying buffer object.
void DataChanged() override
Tell the array explicitly that the data has changed.
void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source) override
Insert the jth tuple in the source array, at ith location in this array.
void Squeeze() override
Free any unnecessary memory.
int IsNumeric() const override
Since each item can be of a different type, we say that a variant array is not numeric.
void InsertValue(vtkIdType id, ValueType value)
If id < GetNumberOfValues(), overwrite the array at that index.
void SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod) override
This method lets the user specify data to be held by the array.
vtkIdType LookupValue(ValueType value) override
Return the indices where a specific value appears.
vtkVariant GetVariantValue(vtkIdType idx) override
Get a value in the array as a variant.
std::integral_constant< int, vtkArrayTypes::VTK_VARIANT_ARRAY > ArrayTypeTag
vtkVariant * GetPointer(vtkIdType id)
Return a pointer to the location in the internal array at the specified index.
void Initialize() override
Release storage and reset array to initial state.
void InsertVariantValue(vtkIdType idx, ValueType value) override
Safely insert a value into the array from a variant.
void * GetVoidPointer(vtkIdType id) override
Return a void pointer.
void SetVariantValue(vtkIdType idx, ValueType value) override
Set a value into the array from a variant.
bool EnsureAccessToTuple(vtkIdType tupleIdx)
This method resizes the array if needed so that the given tuple index is valid/accessible.
int GetElementComponentSize() const override
Return the size, in bytes, of the lowest-level element of an array.
void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray *source) override
Copy n consecutive tuples starting at srcStart from the source array to this array,...
A type representing the union of many types.
Definition vtkVariant.h:162
Forward declaration required for Boost serialization.
int vtkTypeBool
Definition vtkABI.h:64
#define vtkArrayDownCast_FastCastMacro(ArrayT)
This macro is used to tell vtkArrayDownCast to use FastDownCast instead of SafeDownCast.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#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_MARSHALMANUAL
#define VTK_NEWINSTANCE