VTK: Common/Core/vtkVariantArray.h Source File

| VTK 9.3.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
27 #ifndef vtkVariantArray_h
28 #define vtkVariantArray_h
29
30 #include "vtkAbstractArray.h"
31 #include "vtkCommonCoreModule.h" // For export macro
32 #include "vtkVariant.h" // For variant type
33
35 namespace boost
36 {
37 namespace serialization
38 {
39 class access;
40 }
41 }
42
43 VTK_ABI_NAMESPACE_BEGIN
44 class vtkVariantArrayLookup;
45
46 class VTKCOMMONCORE_EXPORT vtkVariantArray : public vtkAbstractArray
47 {
48
50 friend class boost::serialization::access;
51
52 public:
53 enum DeleteMethod
54 {
55 VTK_DATA_ARRAY_FREE = vtkAbstractArray::VTK_DATA_ARRAY_FREE,
56 VTK_DATA_ARRAY_DELETE = vtkAbstractArray::VTK_DATA_ARRAY_DELETE,
57 VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
58 VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
59 };
60
61 static vtkVariantArray* New();
62 static vtkVariantArray* ExtendedNew();
63 vtkTypeMacro(vtkVariantArray, vtkAbstractArray);
64 void PrintSelf(ostream& os, vtkIndent indent) override;
65
66 //
67 // Functions required by vtkAbstractArray
68 //
69
74 vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext = 1000) override;
75
79 void Initialize() override;
80
85 int GetDataType() const override;
86
92 int GetDataTypeSize() const override;
93
101 int GetElementComponentSize() const override;
102
107 void SetNumberOfTuples(vtkIdType number) override;
108
115 void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) override;
116
121 void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) override;
122
128 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
129
130 void InsertTuplesStartingAt(
131 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
132
138 void InsertTuples(
139 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
140
146 vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray* source) override;
147
152 void* GetVoidPointer(vtkIdType id) override;
153
159 void DeepCopy(vtkAbstractArray* da) override;
160
168 void InterpolateTuple(
169 vtkIdType i, vtkIdList* ptIndices, vtkAbstractArray* source, double* weights) override;
170
179 void InterpolateTuple(vtkIdType i, vtkIdType id1, vtkAbstractArray* source1, vtkIdType id2,
180 vtkAbstractArray* source2, double t) override;
181
187 void Squeeze() override;
188
193 vtkTypeBool Resize(vtkIdType numTuples) override;
194
196
204 void SetVoidArray(void* arr, vtkIdType size, int save) override;
205 void SetVoidArray(void* arr, vtkIdType size, int save, int deleteM) override;
207
216 unsigned long GetActualMemorySize() const override;
217
221 int IsNumeric() const override;
222
227 VTK_NEWINSTANCE vtkArrayIterator* NewIterator() override;
228
229 //
230 // Additional functions
231 //
232
236 vtkVariant& GetValue(vtkIdType id) const;
237
242 void SetValue(vtkIdType id, vtkVariant value)
243 VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues());
244
250 void InsertValue(vtkIdType id, vtkVariant value) VTK_EXPECTS(0 <= id);
251
255 void SetVariantValue(vtkIdType idx, vtkVariant value) override;
256
260 void InsertVariantValue(vtkIdType idx, vtkVariant value) override;
261
266 vtkIdType InsertNextValue(vtkVariant value);
267
271 vtkVariant* GetPointer(vtkIdType id);
272
276 void SetArray(
277 vtkVariant* arr, vtkIdType size, int save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
278
285 void SetArrayFreeFunction(void (*callback)(void*)) override;
286
290 vtkIdType GetNumberOfValues() const { return (this->MaxId + 1); }
291
293
296 vtkIdType LookupValue(vtkVariant value) override;
297 void LookupValue(vtkVariant value, vtkIdList* ids) override;
299
308 void DataChanged() override;
309
315 virtual void DataElementChanged(vtkIdType id);
316
322 void ClearLookup() override;
323
328 ~vtkVariantArray() override;
329
330 protected:
331 // Construct object with default tuple dimension (number of components) of 1.
332 vtkVariantArray();
333
334 // Pointer to data
335
336 vtkVariant* Array;
337
338 // Function to resize data
339 vtkVariant* ResizeAndExtend(vtkIdType sz);
340
341 void (*DeleteFunction)(void*);
342
343 private:
344 vtkVariantArray(const vtkVariantArray&) = delete;
345 void operator=(const vtkVariantArray&) = delete;
346
347 vtkVariantArrayLookup* Lookup;
348 void UpdateLookup();
349 };
350
351 VTK_ABI_NAMESPACE_END
352 #endif
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:76
vtkAbstractArray::DeleteMethod
DeleteMethod
Definition: vtkAbstractArray.h:330
vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
@ VTK_DATA_ARRAY_USER_DEFINED
Definition: vtkAbstractArray.h:334
vtkAbstractArray::VTK_DATA_ARRAY_FREE
@ VTK_DATA_ARRAY_FREE
Definition: vtkAbstractArray.h:331
vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE
@ VTK_DATA_ARRAY_ALIGNED_FREE
Definition: vtkAbstractArray.h:333
vtkAbstractArray::VTK_DATA_ARRAY_DELETE
@ VTK_DATA_ARRAY_DELETE
Definition: vtkAbstractArray.h:332
vtkAbstractArray::GetNumberOfValues
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
Definition: vtkAbstractArray.h:180
vtkArrayIterator
Abstract superclass to iterate over elements in an vtkAbstractArray.
Definition: vtkArrayIterator.h:42
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:32
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkVariantArray
An array holding vtkVariants.
Definition: vtkVariantArray.h:47
vtkVariantArray::Array
vtkVariant * Array
Definition: vtkVariantArray.h:336
vtkVariantArray::ExtendedNew
static vtkVariantArray * ExtendedNew()
vtkVariantArray::SetVoidArray
void SetVoidArray(void *arr, vtkIdType size, int save, int deleteM) override
This method lets the user specify data to be held by the array.
vtkVariantArray::SetVoidArray
void SetVoidArray(void *arr, vtkIdType size, int save) override
This method lets the user specify data to be held by the array.
vtkVariantArray::New
static vtkVariantArray * New()
vtkVariantArray::Allocate
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000) override
Allocate memory for this array.
vtkVariantArray::GetDataType
int GetDataType() const override
Return the underlying data type.
vtkVariantArray::SetArrayFreeFunction
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...
vtkVariantArray::~vtkVariantArray
~vtkVariantArray() override
This destructor is public to work around a bug in version 1.36.0 of the Boost.Serialization library.
vtkVariantArray::InsertTuples
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...
vtkVariantArray::Resize
vtkTypeBool Resize(vtkIdType numTuples) override
Resize the array while conserving the data.
vtkVariantArray::InsertTuplesStartingAt
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...
vtkVariantArray::InsertNextValue
vtkIdType InsertNextValue(vtkVariant value)
Expand the array by one and set the value at that location.
vtkVariantArray::InsertVariantValue
void InsertVariantValue(vtkIdType idx, vtkVariant value) override
Safely insert a value into the array from a variant.
vtkVariantArray::ClearLookup
void ClearLookup() override
Delete the associated fast lookup data structure on this array, if it exists.
vtkVariantArray::ResizeAndExtend
vtkVariant * ResizeAndExtend(vtkIdType sz)
vtkVariantArray::GetActualMemorySize
unsigned long GetActualMemorySize() const override
Return the memory in kibibytes (1024 bytes) consumed by this data array.
vtkVariantArray::NewIterator
vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
vtkVariantArray::LookupValue
vtkIdType LookupValue(vtkVariant value) override
Return the indices where a specific value appears.
vtkVariantArray::GetValue
vtkVariant & GetValue(vtkIdType id) const
Get the data at a particular index.
vtkVariantArray::SetTuple
void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source) override
Set the tuple at the ith location using the jth tuple in the source array.
vtkVariantArray::InsertNextTuple
vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray *source) override
Insert the jth tuple in the source array, at the end in this array.
vtkVariantArray::SetVariantValue
void SetVariantValue(vtkIdType idx, vtkVariant value) override
Insert a value into the array from a variant.
vtkVariantArray::GetDataTypeSize
int GetDataTypeSize() const override
Return the size of the underlying data type.
vtkVariantArray::SetNumberOfTuples
void SetNumberOfTuples(vtkIdType number) override
Set the number of tuples (a component group) in the array.
vtkVariantArray::LookupValue
void LookupValue(vtkVariant value, vtkIdList *ids) override
Return the indices where a specific value appears.
vtkVariantArray::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkVariantArray::DataElementChanged
virtual void DataElementChanged(vtkIdType id)
Tell the array explicitly that a single data element has changed.
vtkVariantArray::InterpolateTuple
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...
vtkVariantArray::vtkVariantArray
vtkVariantArray()
vtkVariantArray::InterpolateTuple
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,...
vtkVariantArray::DeepCopy
void DeepCopy(vtkAbstractArray *da) override
Deep copy of data.
vtkVariantArray::DataChanged
void DataChanged() override
Tell the array explicitly that the data has changed.
vtkVariantArray::InsertTuple
void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source) override
Insert the jth tuple in the source array, at ith location in this array.
vtkVariantArray::Squeeze
void Squeeze() override
Free any unnecessary memory.
vtkVariantArray::GetPointer
vtkVariant * GetPointer(vtkIdType id)
Return a pointer to the location in the internal array at the specified index.
vtkVariantArray::IsNumeric
int IsNumeric() const override
Since each item can be of a different type, we say that a variant array is not numeric.
vtkVariantArray::GetVoidPointer
void * GetVoidPointer(vtkIdType id) override
Return a void pointer.
vtkVariantArray::SetArray
void SetArray(vtkVariant *arr, vtkIdType size, int save, int deleteMethod=VTK_DATA_ARRAY_DELETE)
Set the internal array used by this object.
vtkVariantArray::SetValue
void SetValue(vtkIdType id, vtkVariant value)
Set the data at a particular index.
vtkVariantArray::GetNumberOfValues
vtkIdType GetNumberOfValues() const
Return the number of values in the array.
Definition: vtkVariantArray.h:290
vtkVariantArray::Initialize
void Initialize() override
Release storage and reset array to initial state.
vtkVariantArray::InsertValue
void InsertValue(vtkIdType id, vtkVariant value)
If id < GetNumberOfValues(), overwrite the array at that index.
vtkVariantArray::GetElementComponentSize
int GetElementComponentSize() const override
Return the size, in bytes, of the lowest-level element of an array.
vtkVariantArray::InsertTuples
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,...
vtkVariant
A type representing the union of many types.
Definition: vtkVariant.h:62
boost
Forward declaration required for Boost serialization.
Definition: vtkVariantArray.h:36
vtkX3D::value
@ value
Definition: vtkX3D.h:220
vtkX3D::size
@ size
Definition: vtkX3D.h:253
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:64
vtkAbstractArray.h
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:964
vtkIdType
int vtkIdType
Definition: vtkType.h:315
save
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
Definition: vtkVariantBoostSerialization.h:46
vtkVariant.h
VTK_EXPECTS
#define VTK_EXPECTS(x)
Definition: vtkWrappingHints.h:35
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:32