Commit 1eedaf88 authored by T.J. Corona's avatar T.J. Corona
Browse files

Propagate safe variant setting through children of vtkAbstractArray.

This fix is in reference to bug report 0014340, and is an extension of the
change made in commit 84b126f9. vtkAbstractArray and its children have the
convention of a fast, unsafe method for setting elements (SetXXX) and a safer,
slower method (InsertXXX). In the prior commit, this convention was extended to
setting with variant values. In vtkAbstractArray, InsertVariantValue was not a
pure virtual method, and it called the unsafe SetXXX method (which led to
problems, see the bug report). By making this method pure virtual, we ensure
that InsertXXX is indeed safe for each container. It also enforces the pattern
in place for SetXXX vs InsertXXX with other variable types.
parent e2478fb6
......@@ -459,26 +459,6 @@ void vtkAbstractArray::PrintSelf(ostream& os, vtkIndent indent)
}
}
//--------------------------------------------------------------------------
void vtkAbstractArray::InsertVariantValue(vtkIdType id, vtkVariant value)
{
if ( id >= this->Size )
{
int status = this->Resize(id+1);
if (!status)
{
vtkErrorMacro(<<"FAILED to extend array to accommodate new ID "
<< id);
return;
}
}
if ( id > this->MaxId )
{
this->MaxId = id;
}
this->SetVariantValue(id, value);
}
//--------------------------------------------------------------------------
void vtkAbstractArray::GetProminentComponentValues(
int comp, vtkVariantArray* values,
......
......@@ -333,7 +333,7 @@ public:
// Description:
// Insert a value into the array from a variant. This method does
// bounds checking.
virtual void InsertVariantValue(vtkIdType idx, vtkVariant value);
virtual void InsertVariantValue(vtkIdType idx, vtkVariant value) = 0;
// Description:
// Set a value in the array from a variant. This method does NOT do
......
......@@ -149,13 +149,17 @@ public:
void SetValue(vtkIdType id, int value);
// Description:
// Insets values and checks to make sure there is enough memory
// Inserts values and checks to make sure there is enough memory
void InsertValue(vtkIdType id, int i);
// Description:
// Set a value in the array from a variant.
void SetVariantValue(vtkIdType idx, vtkVariant value);
// Description:
// Inserts values from a variant and checks to ensure there is enough memory
void InsertVariantValue(vtkIdType idx, vtkVariant value);
vtkIdType InsertNextValue(int i);
// Description:
......@@ -307,6 +311,11 @@ inline void vtkBitArray::SetVariantValue(vtkIdType id, vtkVariant value)
this->SetValue(id, value.ToInt());
}
inline void vtkBitArray::InsertVariantValue(vtkIdType id, vtkVariant value)
{
this->InsertValue(id, value.ToInt());
}
inline vtkIdType vtkBitArray::InsertNextValue(int i)
{
this->InsertValue (++this->MaxId,i);
......
......@@ -193,6 +193,10 @@ public:
// Read only container, not supported.
void SetVariantValue(vtkIdType idx, vtkVariant value);
// Description:
// Read only container, not supported.
void InsertVariantValue(vtkIdType idx, vtkVariant value);
// Description:
// Read only container, not supported.
void RemoveTuple(vtkIdType id);
......
......@@ -526,6 +526,13 @@ template <class Scalar> void vtkPeriodicDataArray<Scalar>
vtkErrorMacro("Read only container.");
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkPeriodicDataArray<Scalar>
::InsertVariantValue(vtkIdType, vtkVariant)
{
vtkErrorMacro("Read only container.");
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkPeriodicDataArray<Scalar>
::RemoveTuple(vtkIdType)
......
......@@ -958,6 +958,11 @@ void vtkStringArray::SetVariantValue( vtkIdType id, vtkVariant value )
this->SetValue( id, value.ToString() );
}
void vtkStringArray::InsertVariantValue( vtkIdType id, vtkVariant value )
{
this->InsertValue( id, value.ToString() );
}
vtkIdType vtkStringArray::InsertNextValue( const char *value )
{
if( value )
......
......@@ -186,6 +186,11 @@ public:
// Insert a value into the array from a variant.
void SetVariantValue(vtkIdType idx, vtkVariant value);
// Description:
// Safely set a value in the array form a variant.
// Safely insert a value into the array from a variant.
void InsertVariantValue(vtkIdType idx, vtkVariant value);
//BTX
// Description:
// Insert data at the end of the array. Return its location in the array.
......
......@@ -363,6 +363,11 @@ void vtkUnicodeStringArray::SetVariantValue(vtkIdType id, vtkVariant value)
this->SetValue( id, value.ToUnicodeString() );
}
void vtkUnicodeStringArray::InsertVariantValue(vtkIdType id, vtkVariant value)
{
this->InsertValue( id, value.ToUnicodeString() );
}
void vtkUnicodeStringArray::DataChanged()
{
this->MaxId = static_cast<vtkIdType>(this->Internal->Storage.size()) - 1;
......
......@@ -72,6 +72,7 @@ public:
virtual void LookupValue(vtkVariant value, vtkIdList* ids);
virtual void SetVariantValue(vtkIdType idx, vtkVariant value);
virtual void InsertVariantValue(vtkIdType idx, vtkVariant value);
virtual void DataChanged();
virtual void ClearLookup();
......
......@@ -658,6 +658,12 @@ void vtkVariantArray::SetVariantValue(vtkIdType id, vtkVariant value)
this->SetValue(id, value);
}
//----------------------------------------------------------------------------
void vtkVariantArray::InsertVariantValue(vtkIdType id, vtkVariant value)
{
this->InsertValue(id, value);
}
//----------------------------------------------------------------------------
vtkIdType vtkVariantArray::InsertNextValue(vtkVariant value)
{
......
......@@ -215,6 +215,10 @@ public:
// Insert a value into the array from a variant.
void SetVariantValue(vtkIdType idx, vtkVariant value);
// Description:
// Safely insert a value into the array from a variant.
void InsertVariantValue(vtkIdType idx, vtkVariant value);
// Description:
// Expand the array by one and set the value at that location.
// Return the array index of the inserted value.
......
......@@ -91,6 +91,7 @@ public:
void InterpolateTuple(vtkIdType i, vtkIdType id1, vtkAbstractArray *source1,
vtkIdType id2, vtkAbstractArray *source2, double t);
void SetVariantValue(vtkIdType idx, vtkVariant value);
void InsertVariantValue(vtkIdType idx, vtkVariant value);
void RemoveTuple(vtkIdType id);
void RemoveFirstTuple();
void RemoveLastTuple();
......
......@@ -395,6 +395,14 @@ template <class Scalar> void vtkCPExodusIINodalCoordinatesTemplate<Scalar>
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPExodusIINodalCoordinatesTemplate<Scalar>
::InsertVariantValue(vtkIdType, vtkVariant)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPExodusIINodalCoordinatesTemplate<Scalar>
::RemoveTuple(vtkIdType)
......
......@@ -91,6 +91,7 @@ public:
void InterpolateTuple(vtkIdType i, vtkIdType id1, vtkAbstractArray *source1,
vtkIdType id2, vtkAbstractArray *source2, double t);
void SetVariantValue(vtkIdType idx, vtkVariant value);
void InsertVariantValue(vtkIdType idx, vtkVariant value);
void RemoveTuple(vtkIdType id);
void RemoveFirstTuple();
void RemoveLastTuple();
......
......@@ -417,6 +417,14 @@ template <class Scalar> void vtkCPExodusIIResultsArrayTemplate<Scalar>
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPExodusIIResultsArrayTemplate<Scalar>
::InsertVariantValue(vtkIdType, vtkVariant)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPExodusIIResultsArrayTemplate<Scalar>
::RemoveTuple(vtkIdType)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment