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 -------------------------------------------------------------------------*/
43 #ifndef vtkVariantArray_h
44 #define vtkVariantArray_h
45 
46 #include "vtkAbstractArray.h"
47 #include "vtkCommonCoreModule.h" // For export macro
48 #include "vtkVariant.h" // For variant type
49 
50 class vtkVariantArrayLookup;
51 
53 namespace boost
54 {
55 namespace serialization
56 {
57 class access;
58 }
59 }
60 
61 class VTKCOMMONCORE_EXPORT vtkVariantArray : public vtkAbstractArray
62 {
63 
65  friend class boost::serialization::access;
66 
67 public:
69  {
71  VTK_DATA_ARRAY_DELETE = vtkAbstractArray::VTK_DATA_ARRAY_DELETE,
72  VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
73  VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
74  };
75 
76  static vtkVariantArray* New();
79  void PrintSelf(ostream& os, vtkIndent indent) override;
80 
81  //
82  // Functions required by vtkAbstractArray
83  //
84 
89  vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext = 1000) override;
90 
94  void Initialize() override;
95 
100  int GetDataType() const override;
101 
107  int GetDataTypeSize() const override;
108 
116  int GetElementComponentSize() const override;
117 
122  void SetNumberOfTuples(vtkIdType number) override;
123 
131 
137 
143  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
144 
146  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
147 
154  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
155 
162 
167  void* GetVoidPointer(vtkIdType id) override;
168 
174  void DeepCopy(vtkAbstractArray* da) override;
175 
184  vtkIdType i, vtkIdList* ptIndices, vtkAbstractArray* source, double* weights) override;
185 
195  vtkAbstractArray* source2, double t) override;
196 
202  void Squeeze() override;
203 
208  vtkTypeBool Resize(vtkIdType numTuples) override;
209 
211 
219  void SetVoidArray(void* arr, vtkIdType size, int save) override;
220  void SetVoidArray(void* arr, vtkIdType size, int save, int deleteM) override;
222 
231  unsigned long GetActualMemorySize() const override;
232 
236  int IsNumeric() const override;
237 
243 
244  //
245  // Additional functions
246  //
247 
252 
258  VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues());
259 
266 
271 
276 
282 
287 
291  void SetArray(
292  vtkVariant* arr, vtkIdType size, int save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
293 
300  void SetArrayFreeFunction(void (*callback)(void*)) override;
301 
305  vtkIdType GetNumberOfValues() const { return (this->MaxId + 1); }
306 
308 
312  void LookupValue(vtkVariant value, vtkIdList* ids) override;
314 
323  void DataChanged() override;
324 
330  virtual void DataElementChanged(vtkIdType id);
331 
337  void ClearLookup() override;
338 
343  ~vtkVariantArray() override;
344 
345 protected:
346  // Construct object with default tuple dimension (number of components) of 1.
348 
349  // Pointer to data
350 
352 
353  // Function to resize data
355 
356  void (*DeleteFunction)(void*);
357 
358 private:
359  vtkVariantArray(const vtkVariantArray&) = delete;
360  void operator=(const vtkVariantArray&) = delete;
361 
362  vtkVariantArrayLookup* Lookup;
363  void UpdateLookup();
364 };
365 
366 #endif
Abstract superclass for all arrays.
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:43
a simple class to control print indentation
Definition: vtkIndent.h:49
An array holding vtkVariants.
vtkVariant * Array
static vtkVariantArray * ExtendedNew()
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.
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...
~vtkVariantArray() override
This destructor is public to work around a bug in version 1.36.0 of the Boost.Serialization library.
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...
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...
vtkIdType InsertNextValue(vtkVariant value)
Expand the array by one and set the value at that location.
void InsertVariantValue(vtkIdType idx, vtkVariant value) override
Safely insert a value into the array from a variant.
void ClearLookup() override
Delete the associated fast lookup data structure on this array, if it exists.
vtkVariant * ResizeAndExtend(vtkIdType sz)
unsigned long GetActualMemorySize() const override
Return the memory in kibibytes (1024 bytes) consumed by this data array.
vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
vtkIdType LookupValue(vtkVariant value) override
Return the indices where a specific value appears.
vtkVariant & GetValue(vtkIdType id) const
Get the data at a particular index.
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.
void SetVariantValue(vtkIdType idx, vtkVariant value) override
Insert a value into the array from a variant.
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 LookupValue(vtkVariant value, vtkIdList *ids) override
Return the indices where a specific value appears.
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...
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.
vtkVariant * GetPointer(vtkIdType id)
Return a pointer to the location in the internal array at the specified index.
int IsNumeric() const override
Since each item can be of a different type, we say that a variant array is not numeric.
void * GetVoidPointer(vtkIdType id) override
Return a void pointer.
void SetArray(vtkVariant *arr, vtkIdType size, int save, int deleteMethod=VTK_DATA_ARRAY_DELETE)
Set the internal array used by this object.
void SetValue(vtkIdType id, vtkVariant value)
Set the data at a particular index.
vtkIdType GetNumberOfValues() const
Return the number of values in the array.
void Initialize() override
Release storage and reset array to initial state.
void InsertValue(vtkIdType id, vtkVariant value)
If id < GetNumberOfValues(), overwrite the array at that index.
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 atomic type representing the union of many types.
Definition: vtkVariant.h:79
Forward declaration required for Boost serialization.
@ value
Definition: vtkX3D.h:226
@ size
Definition: vtkX3D.h:259
int vtkTypeBool
Definition: vtkABI.h:69
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition: vtkType.h:332
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_EXPECTS(x)
#define VTK_NEWINSTANCE