VTK  9.7.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
18 #ifndef vtkVariantArray_h
19 #define vtkVariantArray_h
20 
21 #include "vtkAbstractArray.h"
22 #include "vtkBuffer.h" // For vtkBuffer
23 #include "vtkCommonCoreModule.h" // For export macro
24 #include "vtkVariant.h" // For variant type
25 #include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
26 
28 namespace boost
29 {
30 namespace serialization
31 {
32 class access;
33 }
34 }
35 
36 VTK_ABI_NAMESPACE_BEGIN
37 class vtkVariantArrayLookup;
38 
39 class VTKCOMMONCORE_EXPORT VTK_MARSHALMANUAL vtkVariantArray : public vtkAbstractArray
40 {
41 
43  friend class boost::serialization::access;
44 
45 public:
47  {
49  VTK_DATA_ARRAY_DELETE = vtkAbstractArray::VTK_DATA_ARRAY_DELETE,
50  VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
51  VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
52  };
53  using ArrayTypeTag = std::integral_constant<int, vtkArrayTypes::VTK_VARIANT_ARRAY>;
54  using DataTypeTag = std::integral_constant<int, VTK_VARIANT>;
56 
57  static vtkVariantArray* New();
58  static vtkVariantArray* ExtendedNew();
60  void PrintSelf(ostream& os, vtkIndent indent) override;
61 
68  static vtkVariantArray* FastDownCast(vtkAbstractArray* source);
69 
70  //
71  // Functions required by vtkAbstractArray
72  //
73 
84  vtkTypeBool ReserveTuples(vtkIdType numTuples) override;
85 
90  bool CopyComponent(int dstComponent, vtkAbstractArray* src, int srcComponent) override;
91 
95  int GetArrayType() const override { return vtkVariantArray::ArrayTypeTag::value; }
96 
101  int GetDataType() const override;
102 
108  int GetDataTypeSize() const override;
109 
117  int GetElementComponentSize() const override;
118 
125  void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) override;
126 
131  void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) override;
132 
138  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
139 
141  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
142 
148  void InsertTuples(
149  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
150 
157 
162  void* GetVoidPointer(vtkIdType id) override;
163 
169  void DeepCopy(vtkAbstractArray* da) override;
170 
176  void ShallowCopy(vtkAbstractArray* src) override;
177 
185  void InterpolateTuple(
186  vtkIdType i, vtkIdList* ptIndices, vtkAbstractArray* source, double* weights) override;
187 
197  vtkAbstractArray* source2, double t) override;
198 
203  void Squeeze() override;
204 
206 
214  void SetVoidArray(void* array, vtkIdType size, int save) override
215  {
216  this->SetArray(static_cast<ValueType*>(array), size, save);
217  }
218  void SetVoidArray(void* array, vtkIdType size, int save, int deleteMethod) override
219  {
220  this->SetArray(static_cast<ValueType*>(array), size, save, deleteMethod);
221  }
223 
232  unsigned long GetActualMemorySize() const override;
233 
237  int IsNumeric() const override;
238 
243  VTK_DEPRECATED_IN_9_7_0("Use vtk::DataArrayValueRange, or the array directly")
244  VTK_NEWINSTANCE vtkArrayIterator* NewIterator() override;
245 
249  ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
250  VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + comp < GetNumberOfValues())
251  VTK_EXPECTS(0 <= comp && comp < GetNumberOfComponents());
252 
254 
257  void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
258  VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + comp < GetNumberOfValues())
259  VTK_EXPECTS(0 <= comp && comp < GetNumberOfComponents());
261 
263 
266  void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
267  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
269 
271 
274  void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
275  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
277 
281  ValueType& GetValue(vtkIdType id) const;
282 
287  void SetValue(vtkIdType id, ValueType value)
288  VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues());
289 
295  void InsertValue(vtkIdType id, ValueType value) VTK_EXPECTS(0 <= id);
296 
300  vtkVariant GetVariantValue(vtkIdType idx) override;
301 
305  void SetVariantValue(vtkIdType idx, ValueType value) override;
306 
310  void InsertVariantValue(vtkIdType idx, ValueType value) override;
311 
316  vtkIdType InsertNextValue(ValueType value);
317 
321  vtkVariant* GetPointer(vtkIdType id);
322 
328 #ifdef __VTK_WRAP__
329  vtkAbstractBuffer* GetBuffer() { return this->Buffer; }
330 #else
331  vtkBuffer<ValueType>* GetBuffer() { return this->Buffer; }
332 #endif // __VTK_WRAP__
333 
337  void SetArray(ValueType* arr, vtkIdType size, int save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
338 
345  void SetArrayFreeFunction(void (*callback)(void*)) override;
346 
348 
351  vtkIdType LookupValue(ValueType value) override;
352  void LookupValue(ValueType value, vtkIdList* ids) override;
354 
363  void DataChanged() override;
364 
370  VTK_DEPRECATED_IN_9_7_0("Use DataChanged() instead")
371  virtual void DataElementChanged(vtkIdType id);
372 
378  void ClearLookup() override;
379 
384  ~vtkVariantArray() override;
385 
386 protected:
387  // Construct object with default tuple dimension (number of components) of 1.
388  vtkVariantArray();
389 
393  bool ReallocateTuples(vtkIdType numTuples);
394 
398  bool EnsureAccessToTuple(vtkIdType tupleIdx);
399 
401 
405  VTK_DEPRECATED_IN_9_7_0("Use ReserveTuples")
406  ValueType* ResizeAndExtend(vtkIdType sz)
407  {
408  this->ReserveTuples(sz);
409  return this->Buffer->GetBuffer();
410  }
411 
412 private:
413  vtkVariantArray(const vtkVariantArray&) = delete;
414  void operator=(const vtkVariantArray&) = delete;
415 
416  vtkVariantArrayLookup* Lookup;
417  void UpdateLookup();
418 };
419 
420 // Declare vtkArrayDownCast implementations for vtkVariantArray:
422 
423 VTK_ABI_NAMESPACE_END
424 #endif
vtkBuffer< ValueType > * GetBuffer()
Return the underlying buffer object.
virtual void InsertTuplesStartingAt(vtkIdType dstStart, vtkIdList *srcIds, vtkAbstractArray *source)=0
Copy the tuples indexed in srcIds from the source array to the tuple locations starting at index dstS...
Forward declaration required for Boost serialization.
virtual void DataChanged()=0
Tell the array explicitly that the data has changed.
virtual void DeepCopy(vtkAbstractArray *da)
Deep copy of data.
virtual void * GetVoidPointer(vtkIdType valueIdx)=0
Return a void pointer.
An array holding vtkVariants.
Abstract superclass for all arrays.
virtual vtkIdType LookupValue(vtkVariant value)=0
Return the value indices where a specific value appears.
void SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod) override
This method lets the user specify data to be held by the array.
virtual int IsNumeric() const =0
This method is here to make backward compatibility easier.
virtual int GetElementComponentSize() const =0
Return the size, in bytes, of the lowest-level element of an array.
virtual bool CopyComponent(int dstComponent, vtkAbstractArray *src, int srcComponent)=0
Copy a component from one array into a component on this array.
virtual vtkTypeBool ReserveTuples(vtkIdType numTuples)=0
Reserve the array to the requested number of tuples and preserve data.
int vtkIdType
Definition: vtkType.h:363
virtual void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList *ptIndices, vtkAbstractArray *source, double *weights)=0
Set the tuple at dstTupleIdx in this array to the interpolated tuple value, given the ptIndices in th...
void SetVoidArray(void *array, vtkIdType size, int save) override
This method lets the user specify data to be held by the array.
A type representing the union of many types.
Definition: vtkVariant.h:52
int vtkTypeBool
Definition: vtkABI.h:64
virtual int GetDataTypeSize() const =0
Return the size of the underlying data type.
int GetArrayType() const override
Return the array type.
#define VTK_MARSHALMANUAL
virtual unsigned long GetActualMemorySize() const =0
Return the memory in kibibytes (1024 bytes) consumed by this data array.
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
vtkArrayDownCast_FastCastMacro(vtkVariantArray)
Abstract superclass to iterate over elements in an vtkAbstractArray.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_NEWINSTANCE
virtual void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Insert the tuple at srcTupleIdx in the source array into this array at dstTupleIdx.
std::integral_constant< int, VTK_OPAQUE > DataTypeTag
virtual vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Insert the tuple from srcTupleIdx in the source array at the end of this array.
virtual void SetArrayFreeFunction(void(*callback)(void *))=0
This method allows the user to specify a custom free function to be called when the array is dealloca...
Abstract base class for vtkBuffer providing buffer protocol support.
virtual void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Set the tuple at dstTupleIdx in this array to the tuple at srcTupleIdx in the source array...
std::integral_constant< int, vtkArrayTypes::VTK_ABSTRACT_ARRAY > ArrayTypeTag
virtual int GetDataType() const
Return the underlying data type.
virtual void Squeeze()=0
Free any unnecessary memory.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
virtual void ShallowCopy(vtkAbstractArray *src)
This method will copy the data from the source array to this array.
#define VTK_EXPECTS(x)
#define VTK_DEPRECATED_IN_9_7_0(reason)
virtual void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source)=0
Copy the tuples indexed in srcIds from the source array to the tuple locations indexed by dstIds in t...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.