From c7ebe5bc87cfe5cc4acbc6f5be954d4a540eba40 Mon Sep 17 00:00:00 2001 From: "T.J. Corona" Date: Tue, 18 Aug 2015 10:01:00 -0400 Subject: [PATCH] vtkDataArrayTemplate: Add a safe method to change an element with vtkVariant. This fix is in reference to bug report 0013143. --- Common/Core/vtkDataArrayTemplate.h | 4 ++++ Common/Core/vtkDataArrayTemplate.txx | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Common/Core/vtkDataArrayTemplate.h b/Common/Core/vtkDataArrayTemplate.h index 7fcb4721501..4a61df3855c 100644 --- a/Common/Core/vtkDataArrayTemplate.h +++ b/Common/Core/vtkDataArrayTemplate.h @@ -212,6 +212,10 @@ class VTKCOMMONCORE_EXPORT vtkDataArrayTemplate: // Set a value in the array from a vtkVariant. void SetVariantValue(vtkIdType id, vtkVariant value); + // Description: + // Insert a value in the array from a vtkVariant. + void InsertVariantValue(vtkIdType id, vtkVariant value); + // Description: // Insert data at the end of the array. Return its location in the array. vtkIdType InsertNextValue(T f); diff --git a/Common/Core/vtkDataArrayTemplate.txx b/Common/Core/vtkDataArrayTemplate.txx index 9eee8e4ab46..975fc0ad3f3 100644 --- a/Common/Core/vtkDataArrayTemplate.txx +++ b/Common/Core/vtkDataArrayTemplate.txx @@ -979,6 +979,22 @@ void vtkDataArrayTemplate::SetVariantValue(vtkIdType id, vtkVariant value) } } +//---------------------------------------------------------------------------- +template +void vtkDataArrayTemplate::InsertVariantValue(vtkIdType id, vtkVariant value) +{ + bool valid; + T toInsert = vtkVariantCast(value, &valid); + if (valid) + { + this->InsertValue(id, toInsert); + } + else + { + vtkErrorMacro("unable to set value of type " << value.GetType()); + } +} + //---------------------------------------------------------------------------- template vtkIdType vtkDataArrayTemplate::InsertNextValue(T f)