VTK  9.2.6
vtkVariantArray.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkVariantArray.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*-------------------------------------------------------------------------
16  Copyright 2008 Sandia Corporation.
17  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18  the U.S. Government retains certain rights in this software.
19 -------------------------------------------------------------------------*/
34 #ifndef vtkVariantArray_h
35 #define vtkVariantArray_h
36 
37 #include "vtkAbstractArray.h"
38 #include "vtkCommonCoreModule.h" // For export macro
39 #include "vtkVariant.h" // For variant type
40 
41 class vtkVariantArrayLookup;
42 
44 namespace boost
45 {
46 namespace serialization
47 {
48 class access;
49 }
50 }
51 
52 class VTKCOMMONCORE_EXPORT vtkVariantArray : public vtkAbstractArray
53 {
54 
56  friend class boost::serialization::access;
57 
58 public:
60  {
62  VTK_DATA_ARRAY_DELETE = vtkAbstractArray::VTK_DATA_ARRAY_DELETE,
63  VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
64  VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
65  };
66 
67  static vtkVariantArray* New();
68  static vtkVariantArray* ExtendedNew();
70  void PrintSelf(ostream& os, vtkIndent indent) override;
71 
72  //
73  // Functions required by vtkAbstractArray
74  //
75 
80  vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext = 1000) override;
81 
85  void Initialize() override;
86 
91  int GetDataType() const override;
92 
98  int GetDataTypeSize() const override;
99 
107  int GetElementComponentSize() const override;
108 
113  void SetNumberOfTuples(vtkIdType number) override;
114 
121  void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) override;
122 
127  void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) override;
128 
134  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
135 
137  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
138 
144  void InsertTuples(
145  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
146 
153 
158  void* GetVoidPointer(vtkIdType id) override;
159 
165  void DeepCopy(vtkAbstractArray* da) override;
166 
174  void InterpolateTuple(
175  vtkIdType i, vtkIdList* ptIndices, vtkAbstractArray* source, double* weights) override;
176 
186  vtkAbstractArray* source2, double t) override;
187 
193  void Squeeze() override;
194 
199  vtkTypeBool Resize(vtkIdType numTuples) override;
200 
202 
210  void SetVoidArray(void* arr, vtkIdType size, int save) override;
211  void SetVoidArray(void* arr, vtkIdType size, int save, int deleteM) override;
213 
222  unsigned long GetActualMemorySize() const override;
223 
227  int IsNumeric() const override;
228 
234 
235  //
236  // Additional functions
237  //
238 
242  vtkVariant& GetValue(vtkIdType id) const;
243 
248  void SetValue(vtkIdType id, vtkVariant value)
249  VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues());
250 
256  void InsertValue(vtkIdType id, vtkVariant value) VTK_EXPECTS(0 <= id);
257 
261  void SetVariantValue(vtkIdType idx, vtkVariant value) override;
262 
266  void InsertVariantValue(vtkIdType idx, vtkVariant value) override;
267 
272  vtkIdType InsertNextValue(vtkVariant value);
273 
277  vtkVariant* GetPointer(vtkIdType id);
278 
282  void SetArray(
283  vtkVariant* arr, vtkIdType size, int save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
284 
291  void SetArrayFreeFunction(void (*callback)(void*)) override;
292 
296  vtkIdType GetNumberOfValues() const { return (this->MaxId + 1); }
297 
299 
303  void LookupValue(vtkVariant value, vtkIdList* ids) override;
305 
314  void DataChanged() override;
315 
321  virtual void DataElementChanged(vtkIdType id);
322 
328  void ClearLookup() override;
329 
334  ~vtkVariantArray() override;
335 
336 protected:
337  // Construct object with default tuple dimension (number of components) of 1.
338  vtkVariantArray();
339 
340  // Pointer to data
341 
343 
344  // Function to resize data
345  vtkVariant* ResizeAndExtend(vtkIdType sz);
346 
347  void (*DeleteFunction)(void*);
348 
349 private:
350  vtkVariantArray(const vtkVariantArray&) = delete;
351  void operator=(const vtkVariantArray&) = delete;
352 
353  vtkVariantArrayLookup* Lookup;
354  void UpdateLookup();
355 };
356 
357 #endif
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.
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 int GetDataType() const =0
Return the underlying data type.
int vtkIdType
Definition: vtkType.h:332
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...
virtual void SetVoidArray(void *vtkNotUsed(array), vtkIdType vtkNotUsed(size), int vtkNotUsed(save))=0
This method lets the user specify data to be held by the array.
virtual void Initialize()=0
Release storage and reset array to initial state.
A atomic type representing the union of many types.
Definition: vtkVariant.h:69
int vtkTypeBool
Definition: vtkABI.h:69
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
virtual int GetDataTypeSize() const =0
Return the size of the underlying data type.
virtual unsigned long GetActualMemorySize() const =0
Return the memory in kibibytes (1024 bytes) consumed by this data array.
virtual void ClearLookup()=0
Delete the associated fast lookup data structure on this array, if it exists.
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkVariant * Array
list of point or cell ids
Definition: vtkIdList.h:33
virtual vtkArrayIterator * NewIterator()=0
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Insert a value into the array from a variant.
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.
virtual vtkTypeBool Allocate(vtkIdType numValues, vtkIdType ext=1000)=0
Allocate memory for this array.
virtual vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Insert the tuple from srcTupleIdx in the source array at the end of this array.
virtual vtkTypeBool Resize(vtkIdType numTuples)=0
Resize the array to the requested number of tuples and preserve data.
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...
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...
virtual void SetNumberOfTuples(vtkIdType numTuples)=0
Set the number of tuples (a component group) in the array.
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...
vtkIdType GetNumberOfValues() const
Return the number of values in the array.
#define VTK_EXPECTS(x)
virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Set a value in the array from a variant.
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.