VTK  9.7.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 "vtkBuffer.h" // For vtkBuffer
26 #include "vtkCommonCoreModule.h" // For export macro
27 #include "vtkStdString.h" // needed for vtkStdString definition
28 #include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
29 
30 VTK_ABI_NAMESPACE_BEGIN
31 class vtkStringArrayLookup;
32 
33 class VTKCOMMONCORE_EXPORT VTK_MARSHALMANUAL vtkStringArray : public vtkAbstractArray
34 {
35 public:
37  {
39  VTK_DATA_ARRAY_DELETE = vtkAbstractArray::VTK_DATA_ARRAY_DELETE,
40  VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
41  VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
42  };
43  using ArrayTypeTag = std::integral_constant<int, vtkArrayTypes::VTK_STRING_ARRAY>;
44  using DataTypeTag = std::integral_constant<int, VTK_STRING>;
46 
47  static vtkStringArray* New();
48  static vtkStringArray* ExtendedNew();
50  void PrintSelf(ostream& os, vtkIndent indent) override;
51 
58  static vtkStringArray* FastDownCast(vtkAbstractArray* source);
59 
63  int GetArrayType() const override { return vtkStringArray::ArrayTypeTag::value; }
64 
68  int GetDataType() const override { return vtkStringArray::DataTypeTag::value; }
69 
70  int IsNumeric() const override { return 0; }
71 
76  bool CopyComponent(int dstComponent, vtkAbstractArray* src, int srcComponent) override;
77 
84  int GetDataTypeSize() const override;
85 
90  void Squeeze() override;
91 
98  void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) override;
99 
104  void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) override;
105 
111  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
112 
114  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
115 
121  void InsertTuples(
122  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
123 
130 
138  void InterpolateTuple(
139  vtkIdType i, vtkIdList* ptIndices, vtkAbstractArray* source, double* weights) override;
140 
150  vtkAbstractArray* source2, double t) override;
151 
158  void GetTuples(vtkIdList* ptIds, vtkAbstractArray* output) override;
159 
167  void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) override;
168 
179  vtkTypeBool ReserveTuples(vtkIdType numTuples) override;
180 
184  ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
185  VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + comp < GetNumberOfValues())
186  VTK_EXPECTS(0 <= comp && comp < GetNumberOfComponents());
187 
189 
192  void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
193  VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + comp < GetNumberOfValues())
194  VTK_EXPECTS(0 <= comp && comp < GetNumberOfComponents());
196 
198 
201  void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
202  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
204 
206 
209  void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
210  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
212 
216  const ValueType& GetValue(vtkIdType id) const
217  VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues());
218 
222  ValueType& GetValue(vtkIdType id) VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues());
223 
228  void SetValue(vtkIdType id, ValueType value)
229  VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues())
230  {
231  this->Buffer->GetBuffer()[id] = value;
232  this->DataChanged();
233  }
234 
235  void SetValue(vtkIdType id, const char* value)
236  VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues()) VTK_EXPECTS(value != nullptr);
237 
238  VTK_DEPRECATED_IN_9_7_0("No longer needed")
239  int GetNumberOfElementComponents() { return 0; }
240  int GetElementComponentSize() const override
241  {
242  return static_cast<int>(sizeof(ValueType::value_type));
243  }
244 
248  void InsertValue(vtkIdType id, ValueType f) VTK_EXPECTS(0 <= id);
249  void InsertValue(vtkIdType id, const char* val) VTK_EXPECTS(0 <= id) VTK_EXPECTS(val != nullptr);
250 
254  vtkVariant GetVariantValue(vtkIdType idx) override;
255 
259  void SetVariantValue(vtkIdType idx, vtkVariant value) override;
260 
265  void InsertVariantValue(vtkIdType idx, vtkVariant value) override;
266 
270  vtkIdType InsertNextValue(ValueType f);
271  vtkIdType InsertNextValue(const char* f) VTK_EXPECTS(f != nullptr);
272 
278  ValueType* WritePointer(vtkIdType id, vtkIdType number);
279 
284  ValueType* GetPointer(vtkIdType id) { return this->Buffer->GetBuffer() + id; }
285  void* GetVoidPointer(vtkIdType id) override { return this->GetPointer(id); }
286 
292 #ifdef __VTK_WRAP__
293  vtkAbstractBuffer* GetBuffer() { return this->Buffer; }
294 #else
295  vtkBuffer<ValueType>* GetBuffer() { return this->Buffer; }
296 #endif // __VTK_WRAP__
297 
302  void DeepCopy(vtkAbstractArray* aa) override;
303 
309  void ShallowCopy(vtkAbstractArray* src) override;
310 
323  void SetArray(
324  ValueType* array, vtkIdType size, int save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
325  void SetVoidArray(void* array, vtkIdType size, int save) override
326  {
327  this->SetArray(static_cast<ValueType*>(array), size, save);
328  }
329  void SetVoidArray(void* array, vtkIdType size, int save, int deleteMethod) override
330  {
331  this->SetArray(static_cast<ValueType*>(array), size, save, deleteMethod);
332  }
333 
340  void SetArrayFreeFunction(void (*callback)(void*)) override;
341 
353  unsigned long GetActualMemorySize() const override;
354 
358  VTK_DEPRECATED_IN_9_7_0("Use vtk::DataArrayValueRange, or the array directly")
359  VTK_NEWINSTANCE vtkArrayIterator* NewIterator() override;
360 
366  vtkIdType GetDataSize() const override;
367 
369 
372  vtkIdType LookupValue(vtkVariant value) override;
373  void LookupValue(vtkVariant value, vtkIdList* ids) override;
375 
376  vtkIdType LookupValue(const ValueType& value);
377  void LookupValue(const ValueType& value, vtkIdList* ids);
378 
379  vtkIdType LookupValue(const char* value);
380  void LookupValue(const char* value, vtkIdList* ids);
381 
390  void DataChanged() override;
391 
397  VTK_DEPRECATED_IN_9_7_0("Use DataChanged() instead")
398  virtual void DataElementChanged(vtkIdType id);
399 
405  void ClearLookup() override;
406 
407 protected:
408  vtkStringArray();
409  ~vtkStringArray() override;
410 
414  bool ReallocateTuples(vtkIdType numTuples);
415 
419  bool EnsureAccessToTuple(vtkIdType tupleIdx);
420 
422 
426  VTK_DEPRECATED_IN_9_7_0("Use ReserveTuples")
427  ValueType* ResizeAndExtend(vtkIdType sz)
428  {
429  this->ReserveTuples(sz);
430  return this->Buffer->GetBuffer();
431  }
432 
433 private:
434  vtkStringArray(const vtkStringArray&) = delete;
435  void operator=(const vtkStringArray&) = delete;
436 
437  vtkStringArrayLookup* Lookup;
438  void UpdateLookup();
439 };
440 
441 // Declare vtkArrayDownCast implementations for vtkStringArray:
443 
444 VTK_ABI_NAMESPACE_END
445 #endif
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:27
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.
int GetNumberOfComponents() const
Set/Get the dimension (n) of the components.
virtual void GetTuples(vtkIdList *tupleIds, vtkAbstractArray *output)
Given a list of tuple ids, return an array of tuples.
Abstract superclass for all arrays.
int GetArrayType() const override
Return the array type.
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.
a vtkAbstractArray subclass for strings
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...
int IsNumeric() const override
This method is here to make backward compatibility easier.
A type representing the union of many types.
Definition: vtkVariant.h:52
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.
#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)
vtkBuffer< ValueType > * GetBuffer()
Return the underlying buffer object.
list of point or cell ids
Definition: vtkIdList.h:25
Abstract superclass to iterate over elements in an vtkAbstractArray.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
vtkArrayDownCast_FastCastMacro(vtkStringArray)
#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...
StdString::value_type value_type
Definition: vtkStdString.h:31
std::integral_constant< int, vtkArrayTypes::VTK_ABSTRACT_ARRAY > ArrayTypeTag
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 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)
void SetVoidArray(void *array, vtkIdType size, int save) override
This method lets the user specify data to be held by the array.
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.