VTK  9.6.1
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
17
18#ifndef vtkVariantArray_h
19#define vtkVariantArray_h
20
21#include "vtkAbstractArray.h"
22#include "vtkCommonCoreModule.h" // For export macro
23#include "vtkVariant.h" // For variant type
24#include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
25
27namespace boost
28{
30{
31class access;
32}
33}
34
35VTK_ABI_NAMESPACE_BEGIN
36class vtkVariantArrayLookup;
37
38class VTKCOMMONCORE_EXPORT VTK_MARSHALMANUAL vtkVariantArray : public vtkAbstractArray
39{
40
42 friend class boost::serialization::access;
43
44public:
52 using ArrayTypeTag = std::integral_constant<int, vtkArrayTypes::VTK_VARIANT_ARRAY>;
53 using DataTypeTag = std::integral_constant<int, VTK_VARIANT>;
55
59 void PrintSelf(ostream& os, vtkIndent indent) override;
60
68
69 //
70 // Functions required by vtkAbstractArray
71 //
72
77 vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext = 1000) override;
78
82 void Initialize() override;
83
88 bool CopyComponent(int dstComponent, vtkAbstractArray* src, int srcComponent) override;
89
93 int GetArrayType() const override { return vtkVariantArray::ArrayTypeTag::value; }
94
99 int GetDataType() const override;
100
106 int GetDataTypeSize() const override;
107
115 int GetElementComponentSize() const override;
116
121 void SetNumberOfTuples(vtkIdType number) override;
122
130
136
142 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
143
145 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
146
153 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
154
161
166 void* GetVoidPointer(vtkIdType id) override;
167
173 void DeepCopy(vtkAbstractArray* da) override;
174
183 vtkIdType i, vtkIdList* ptIndices, vtkAbstractArray* source, double* weights) override;
184
194 vtkAbstractArray* source2, double t) override;
195
201 void Squeeze() override;
202
207 vtkTypeBool Resize(vtkIdType numTuples) override;
208
210
218 void SetVoidArray(void* arr, vtkIdType size, int save) override;
219 void SetVoidArray(void* arr, vtkIdType size, int save, int deleteM) override;
221
230 unsigned long GetActualMemorySize() const override;
231
235 int IsNumeric() const override;
236
242
243 //
244 // Additional functions
245 //
246
251
257 VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues());
258
264 void InsertValue(vtkIdType id, ValueType value) VTK_EXPECTS(0 <= id);
265
269 void SetVariantValue(vtkIdType idx, ValueType value) override;
270
274 void InsertVariantValue(vtkIdType idx, ValueType value) override;
275
281
286
290 void SetArray(ValueType* arr, vtkIdType size, int save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
291
298 void SetArrayFreeFunction(void (*callback)(void*)) override;
299
303 vtkIdType GetNumberOfValues() const { return (this->MaxId + 1); }
304
306
310 void LookupValue(ValueType value, vtkIdList* ids) override;
312
321 void DataChanged() override;
322
329
335 void ClearLookup() override;
336
342
343protected:
344 // Construct object with default tuple dimension (number of components) of 1.
346
347 // Pointer to data
348
350
351 // Function to resize data
353
354 void (*DeleteFunction)(void*);
355
356private:
357 vtkVariantArray(const vtkVariantArray&) = delete;
358 void operator=(const vtkVariantArray&) = delete;
359
360 vtkVariantArrayLookup* Lookup;
361 void UpdateLookup();
362};
363
364// Declare vtkArrayDownCast implementations for vtkVariantArray:
366
367VTK_ABI_NAMESPACE_END
368#endif
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
Abstract superclass to iterate over elements in an vtkAbstractArray.
list of point or cell ids
Definition vtkIdList.h:24
a simple class to control print indentation
Definition vtkIndent.h:29
An array holding vtkVariants.
void SetVoidArray(void *arr, vtkIdType size, int save, int deleteM) override
This method lets the user specify data to be held by the array.
void SetVoidArray(void *arr, vtkIdType size, int save) override
This method lets the user specify data to be held by the array.
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()
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.
~vtkVariantArray() override
This destructor is public to work around a bug in version 1.36.0 of the Boost.Serialization library.
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...
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
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.
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 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)
vtkVariant ValueType
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 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.
vtkIdType LookupValue(ValueType value) override
Return the indices where a specific value appears.
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.
vtkIdType GetNumberOfValues() const
Return the number of values in the array.
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(* DeleteFunction)(void *)
void * GetVoidPointer(vtkIdType id) override
Return a void pointer.
void SetVariantValue(vtkIdType idx, ValueType value) override
Insert a value into the array from a variant.
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:53
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 *)
int vtkIdType
Definition vtkType.h:368
void save(Archiver &ar, const std::string &str, const unsigned int version)
#define VTK_EXPECTS(x)
#define VTK_MARSHALMANUAL
#define VTK_NEWINSTANCE