VTK  9.3.1
vtkStringArray.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright 2004 Sandia Corporation
3 // SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
21 #ifndef vtkStringArray_h
22 #define vtkStringArray_h
23 
24 #include "vtkAbstractArray.h"
25 #include "vtkCommonCoreModule.h" // For export macro
26 #include "vtkStdString.h" // needed for vtkStdString definition
27 
28 VTK_ABI_NAMESPACE_BEGIN
29 class vtkStringArrayLookup;
30 
31 class VTKCOMMONCORE_EXPORT vtkStringArray : public vtkAbstractArray
32 {
33 public:
35  {
37  VTK_DATA_ARRAY_DELETE = vtkAbstractArray::VTK_DATA_ARRAY_DELETE,
38  VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
39  VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
40  };
41 
42  static vtkStringArray* New();
43  static vtkStringArray* ExtendedNew();
45  void PrintSelf(ostream& os, vtkIndent indent) override;
46 
47  //
48  //
49  // Functions required by vtkAbstractArray
50  //
51  //
52 
56  int GetDataType() const override { return VTK_STRING; }
57 
58  int IsNumeric() const override { return 0; }
59 
63  void Initialize() override;
64 
71  int GetDataTypeSize() const override;
72 
77  void Squeeze() override { this->ResizeAndExtend(this->MaxId + 1); }
78 
82  vtkTypeBool Resize(vtkIdType numTuples) override;
83 
90  void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) override;
91 
97 
103  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
104 
106  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
107 
113  void InsertTuples(
114  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
115 
122 
130  void InterpolateTuple(
131  vtkIdType i, vtkIdList* ptIndices, vtkAbstractArray* source, double* weights) override;
132 
142  vtkAbstractArray* source2, double t) override;
143 
150  void GetTuples(vtkIdList* ptIds, vtkAbstractArray* output) override;
151 
159  void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) override;
160 
165  vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext = 1000) override;
166 
170  const vtkStdString& GetValue(vtkIdType id) const
171  VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues());
172 
176  vtkStdString& GetValue(vtkIdType id) VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues());
177 
183  VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues())
184  {
185  this->Array[id] = value;
186  this->DataChanged();
187  }
188 
189  void SetValue(vtkIdType id, const char* value)
190  VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues()) VTK_EXPECTS(value != nullptr);
191 
196  void SetNumberOfTuples(vtkIdType number) override
197  {
198  this->SetNumberOfValues(this->NumberOfComponents * number);
199  }
200 
204  vtkIdType GetNumberOfValues() const { return (this->MaxId + 1); }
205 
206  int GetNumberOfElementComponents() { return 0; }
207  int GetElementComponentSize() const override
208  {
209  return static_cast<int>(sizeof(vtkStdString::value_type));
210  }
211 
215  void InsertValue(vtkIdType id, vtkStdString f) VTK_EXPECTS(0 <= id);
216  void InsertValue(vtkIdType id, const char* val) VTK_EXPECTS(0 <= id) VTK_EXPECTS(val != nullptr);
217 
222  void SetVariantValue(vtkIdType idx, vtkVariant value) override;
223 
228  void InsertVariantValue(vtkIdType idx, vtkVariant value) override;
229 
233  vtkIdType InsertNextValue(vtkStdString f);
234  vtkIdType InsertNextValue(const char* f) VTK_EXPECTS(f != nullptr);
235 
241  vtkStdString* WritePointer(vtkIdType id, vtkIdType number);
242 
247  vtkStdString* GetPointer(vtkIdType id) { return this->Array + id; }
248  void* GetVoidPointer(vtkIdType id) override { return this->GetPointer(id); }
249 
254  void DeepCopy(vtkAbstractArray* aa) override;
255 
268  void SetArray(
269  vtkStdString* array, vtkIdType size, int save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
270  void SetVoidArray(void* array, vtkIdType size, int save) override
271  {
272  this->SetArray(static_cast<vtkStdString*>(array), size, save);
273  }
274  void SetVoidArray(void* array, vtkIdType size, int save, int deleteMethod) override
275  {
276  this->SetArray(static_cast<vtkStdString*>(array), size, save, deleteMethod);
277  }
278 
285  void SetArrayFreeFunction(void (*callback)(void*)) override;
286 
298  unsigned long GetActualMemorySize() const override;
299 
304 
310  vtkIdType GetDataSize() const override;
311 
313 
317  void LookupValue(vtkVariant value, vtkIdList* ids) override;
319 
321  void LookupValue(const vtkStdString& value, vtkIdList* ids);
322 
323  vtkIdType LookupValue(const char* value);
324  void LookupValue(const char* value, vtkIdList* ids);
325 
334  void DataChanged() override;
335 
341  virtual void DataElementChanged(vtkIdType id);
342 
348  void ClearLookup() override;
349 
350 protected:
351  vtkStringArray();
352  ~vtkStringArray() override;
353 
354  vtkStdString* Array; // pointer to data
355  vtkStdString* ResizeAndExtend(vtkIdType sz); // function to resize data
356 
357  void (*DeleteFunction)(void*);
358 
359 private:
360  vtkStringArray(const vtkStringArray&) = delete;
361  void operator=(const vtkStringArray&) = delete;
362 
363  vtkStringArrayLookup* Lookup;
364  void UpdateLookup();
365 };
366 
367 VTK_ABI_NAMESPACE_END
368 #endif
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:28
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...
virtual void DataChanged()=0
Tell the array explicitly that the data has changed.
virtual void DeepCopy(vtkAbstractArray *da)
Deep copy of data.
virtual void GetTuples(vtkIdList *tupleIds, vtkAbstractArray *output)
Given a list of tuple ids, return an array of tuples.
Abstract superclass for all arrays.
virtual vtkIdType LookupValue(vtkVariant value)=0
Return the value indices where a specific value appears.
vtkStdString * Array
a vtkAbstractArray subclass for strings
int vtkIdType
Definition: vtkType.h:315
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...
int IsNumeric() const override
This method is here to make backward compatibility easier.
virtual void Initialize()=0
Release storage and reset array to initial state.
A type representing the union of many types.
Definition: vtkVariant.h:52
void SetValue(vtkIdType id, vtkStdString value)
Set the data at a particular index.
#define VTK_STRING
Definition: vtkType.h:48
int GetDataType() const override
Get the data type.
int GetElementComponentSize() const override
Return the size, in bytes, of the lowest-level element of an array.
int vtkTypeBool
Definition: vtkABI.h:64
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.
void * GetVoidPointer(vtkIdType id) override
Return a void pointer.
virtual vtkIdType GetDataSize() const
Returns the size of the data in DataTypeSize units.
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:28
list of point or cell ids
Definition: vtkIdList.h:22
vtkIdType GetNumberOfValues() const
Return the number of values in the array.
void Squeeze() override
Free any unnecessary memory.
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))
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...
StdString::value_type value_type
Definition: vtkStdString.h:32
void SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod) override
virtual bool SetNumberOfValues(vtkIdType numValues)
Specify the number of values (tuples * components) for this object to hold.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
#define VTK_EXPECTS(x)
void SetVoidArray(void *array, vtkIdType size, int save) override
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...
int GetNumberOfElementComponents()
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.