Commit d36bf40a authored by Jeff Baumes's avatar Jeff Baumes
Browse files

ENH: Changing GetRow() to not return a new instance, and changing dependent...

ENH: Changing GetRow() to not return a new instance, and changing dependent code to not call Delete() on the returned array.
parent 7da71949
......@@ -19,20 +19,21 @@
#include "vtkArrayIteratorIncludes.h"
#include "vtkTable.h"
#include "vtkAbstractArray.h"
#include "vtkDataArray.h"
#include "vtkFieldData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkStringArray.h"
#include "vtkVariantArray.h"
#include <vtkFieldData.h>
#include <vtkObjectFactory.h>
#include <vtkStringArray.h>
#include <vtkDataArray.h>
#include <vtkAbstractArray.h>
#include <vtkInformation.h>
#include <vtkInformationVector.h>
//
// Standard functions
//
vtkCxxRevisionMacro(vtkTable, "1.9");
vtkCxxRevisionMacro(vtkTable, "1.10");
vtkStandardNewMacro(vtkTable);
//----------------------------------------------------------------------------
......@@ -40,6 +41,7 @@ vtkStandardNewMacro(vtkTable);
vtkTable::vtkTable()
{
this->Rows = 0;
this->RowArray = vtkVariantArray::New();
this->Information->Set(vtkDataObject::DATA_EXTENT_TYPE(), VTK_PIECES_EXTENT);
this->Information->Set(vtkDataObject::DATA_PIECE_NUMBER(), -1);
......@@ -49,6 +51,13 @@ vtkTable::vtkTable()
//----------------------------------------------------------------------------
vtkTable::~vtkTable()
{
this->RowArray->Delete();
}
//----------------------------------------------------------------------------
void vtkTable::PrintSelf(ostream &os, vtkIndent indent)
{
vtkDataObject::PrintSelf(os, indent);
......@@ -94,17 +103,28 @@ vtkIdType vtkTable::GetNumberOfRows()
vtkVariantArray* vtkTable::GetRow(vtkIdType row)
{
vtkVariantArray* varr = vtkVariantArray::New();
this->RowArray->SetNumberOfTuples(0);
for (int i = 0; i < this->FieldData->GetNumberOfArrays(); i++)
{
this->RowArray->InsertNextValue(this->GetValue(row, i));
}
return this->RowArray;
}
//----------------------------------------------------------------------------
void vtkTable::GetRow(vtkIdType row, vtkVariantArray *values)
{
values->SetNumberOfTuples(0);
for (int i = 0; i < this->FieldData->GetNumberOfArrays(); i++)
{
varr->InsertNextValue(this->GetValue(row, i));
values->InsertNextValue(this->GetValue(row, i));
}
return varr;
}
//----------------------------------------------------------------------------
void vtkTable::SetRow(vtkIdType row, vtkVariantArray* values)
void vtkTable::SetRow(vtkIdType row, vtkVariantArray *values)
{
for (int i = 0; i < this->GetNumberOfColumns(); i++)
{
......
......@@ -71,11 +71,16 @@ public:
// Description:
// Get a row of the table as a vtkVariantArray which has one entry for each column.
// NOTE: This version of the method is NOT thread safe.
vtkVariantArray* GetRow(vtkIdType row);
// Description:
// Get a row of the table as a vtkVariantArray which has one entry for each column.
void GetRow(vtkIdType row, vtkVariantArray *values);
// Description:
// Set a row of the table with a vtkVariantArray which has one entry for each column.
void SetRow(vtkIdType row, vtkVariantArray* values);
void SetRow(vtkIdType row, vtkVariantArray *values);
// Description:
// Insert a blank row at the end of the table.
......@@ -157,12 +162,19 @@ public:
protected:
vtkTable();
~vtkTable() {}
~vtkTable();
// Description:
// Holds row information returned by GetRow().
vtkVariantArray *RowArray;
// Description:
// The number of rows in the table.
vtkIdType Rows;
private:
vtkTable(const vtkTable&); // Not implemented
void operator=(const vtkTable&); // Not implemented
vtkIdType Rows;
};
#endif
......
......@@ -80,9 +80,6 @@ TestDelimitedTextReader(int argc, char *argv[])
<< value.ToString() << endl;
}
}
row->Delete();
}
reader->Delete();
......@@ -133,9 +130,6 @@ TestDelimitedTextReader(int argc, char *argv[])
<< value.ToString() << endl;
}
}
row->Delete();
}
reader->Delete();
......
......@@ -80,7 +80,6 @@ TestFixedWidthTextReader(int argc, char *argv[])
<< value.ToString() << endl;
}
}
row->Delete();
}
reader->Delete();
......@@ -134,7 +133,6 @@ TestFixedWidthTextReader(int argc, char *argv[])
<< value.ToString() << endl;
}
}
row->Delete();
}
reader->Delete();
......
......@@ -118,7 +118,6 @@ void CheckEqual(vtkTable* table, vector<vector<double> > & stdTable)
exit(1);
}
}
arr->Delete();
}
}
......
......@@ -28,7 +28,7 @@
#include "vtkVariant.h"
#include "vtkVariantArray.h"
vtkCxxRevisionMacro(vtkThresholdTable, "1.4");
vtkCxxRevisionMacro(vtkThresholdTable, "1.5");
vtkStandardNewMacro(vtkThresholdTable);
vtkThresholdTable::vtkThresholdTable() : MinValue(0), MaxValue(VTK_INT_MAX)
......@@ -94,7 +94,6 @@ void vtkThresholdTableThresholdRows(iterT* it, vtkTable* input, vtkTable* output
{
vtkVariantArray* row = input->GetRow(i);
output->InsertNextRow(row);
row->Delete();
}
}
}
......
Supports Markdown
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