Skip to content

Commit

Permalink
vtkDataArrayTemplate: Add a safe method to change an element with vtk…
Browse files Browse the repository at this point in the history
…Variant.

This fix is in reference to bug report 0013143.
  • Loading branch information
tjcorona committed Aug 18, 2015
1 parent 2e0acc8 commit c7ebe5b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Common/Core/vtkDataArrayTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions Common/Core/vtkDataArrayTemplate.txx
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,22 @@ void vtkDataArrayTemplate<T>::SetVariantValue(vtkIdType id, vtkVariant value)
}
}

//----------------------------------------------------------------------------
template <class T>
void vtkDataArrayTemplate<T>::InsertVariantValue(vtkIdType id, vtkVariant value)
{
bool valid;
T toInsert = vtkVariantCast<T>(value, &valid);
if (valid)
{
this->InsertValue(id, toInsert);
}
else
{
vtkErrorMacro("unable to set value of type " << value.GetType());
}
}

//----------------------------------------------------------------------------
template <class T>
vtkIdType vtkDataArrayTemplate<T>::InsertNextValue(T f)
Expand Down

0 comments on commit c7ebe5b

Please sign in to comment.