Commit 7fcb2cda authored by Brad King's avatar Brad King

vtkXML*: Use 64-bit integer types where appropriate

Use size_t for memory buffer sizes and vtkTypeInt64 for file positions
and offsets exposed in header files.  Use vtkTypeUInt64 for sizing and
indexing of whole data.  The latter will be necessary to read small
portions of data requiring 64-bit indexes on 32-bit architectures.
Use std::streampos for stream seek operations but avoid exposing it
in header files because its type can vary on some platforms depending
on preprocessor definitions for large file support.

Change-Id: I5c6eb335fb2415de652f012fbf34e2f2952e443a
parent b0a1c940
......@@ -191,8 +191,8 @@ public:
// Description:
// Set/Get the offset from the beginning of the XML document to this element.
vtkGetMacro(XMLByteIndex, unsigned long);
vtkSetMacro(XMLByteIndex, unsigned long);
vtkGetMacro(XMLByteIndex, vtkTypeInt64);
vtkSetMacro(XMLByteIndex, vtkTypeInt64);
// Description:
// Check if the instance has the same name, attributes, character data
......@@ -256,12 +256,12 @@ protected:
int IgnoreCharacterData;
// Get/Set the stream position of the elements inline data.
vtkGetMacro(InlineDataPosition,unsigned long);
vtkSetMacro(InlineDataPosition,unsigned long);
vtkGetMacro(InlineDataPosition,vtkTypeInt64);
vtkSetMacro(InlineDataPosition,vtkTypeInt64);
// The offset into the XML stream where the inline data begins.
unsigned long InlineDataPosition;
vtkTypeInt64 InlineDataPosition;
// The offset into the XML stream where the element begins.
unsigned long XMLByteIndex;
vtkTypeInt64 XMLByteIndex;
// The raw property name/value pairs read from the XML attributes.
char** AttributeNames;
......
This diff is collapsed.
......@@ -49,48 +49,41 @@ public:
// Enumerate big and little endian byte order settings.
enum { BigEndian, LittleEndian };
// Description:
// A type used for data sizes and offsets for stream i/o. Using
// vtkIdType should satisfy most users. This could be streamoff if
// it is deemed portable. It could also be split into OffsetType
// (streamoff) and PositionType (streampos).
typedef vtkIdType OffsetType;
// Description:
// Read inline data from inside the given element. Returns the
// number of words read.
OffsetType ReadInlineData(vtkXMLDataElement* element, int isAscii,
void* buffer, OffsetType startWord,
OffsetType numWords, int wordType);
OffsetType ReadInlineData(vtkXMLDataElement* element, int isAscii,
char* buffer, OffsetType startWord,
OffsetType numWords)
size_t ReadInlineData(vtkXMLDataElement* element, int isAscii,
void* buffer, vtkTypeUInt64 startWord,
size_t numWords, int wordType);
size_t ReadInlineData(vtkXMLDataElement* element, int isAscii,
char* buffer, vtkTypeUInt64 startWord,
size_t numWords)
{ return this->ReadInlineData(element, isAscii, buffer, startWord,
numWords, VTK_CHAR); }
// Description:
// Read from an appended data section starting at the given appended
// data offset. Returns the number of words read.
OffsetType ReadAppendedData(OffsetType offset, void* buffer,
OffsetType startWord,
OffsetType numWords, int wordType);
OffsetType ReadAppendedData(OffsetType offset, char* buffer,
OffsetType startWord,
OffsetType numWords)
{ return this->ReadAppendedData(offset, buffer, startWord, numWords,
size_t ReadAppendedData(vtkTypeInt64 offset, void* buffer,
vtkTypeUInt64 startWord,
size_t numWords, int wordType);
size_t ReadAppendedData(vtkTypeInt64 offset, char* buffer,
vtkTypeUInt64 startWord,
size_t numWords)
{ return this->ReadAppendedData(offset, buffer, startWord, numWords,
VTK_CHAR); }
// Description:
// Read from an ascii data section starting at the current position in
// the stream. Returns the number of words read.
OffsetType ReadAsciiData(void* buffer, OffsetType startWord,
OffsetType numWords, int wordType);
size_t ReadAsciiData(void* buffer, vtkTypeUInt64 startWord,
size_t numWords, int wordType);
// Description:
// Read from a data section starting at the current position in the
// stream. Returns the number of words read.
OffsetType ReadBinaryData(void* buffer, OffsetType startWord,
OffsetType maxWords, int wordType);
size_t ReadBinaryData(void* buffer, vtkTypeUInt64 startWord,
size_t maxWords, int wordType);
//ETX
// Description:
......@@ -101,7 +94,7 @@ public:
// Description:
// Get the size of a word of the given type.
unsigned long GetWordTypeSize(int wordType);
size_t GetWordTypeSize(int wordType);
// Description:
// Parse the XML input and check that the file is safe to read.
......@@ -162,17 +155,17 @@ protected:
// Data reading methods.
void ReadCompressionHeader();
unsigned int FindBlockSize(unsigned int block);
int ReadBlock(unsigned int block, unsigned char* buffer);
unsigned char* ReadBlock(unsigned int block);
OffsetType ReadUncompressedData(unsigned char* data,
OffsetType startWord,
OffsetType numWords,
int wordSize);
OffsetType ReadCompressedData(unsigned char* data,
OffsetType startWord,
OffsetType numWords,
int wordSize);
size_t FindBlockSize(vtkTypeUInt64 block);
int ReadBlock(vtkTypeUInt64 block, unsigned char* buffer);
unsigned char* ReadBlock(vtkTypeUInt64 block);
size_t ReadUncompressedData(unsigned char* data,
vtkTypeUInt64 startWord,
size_t numWords,
size_t wordSize);
size_t ReadCompressedData(unsigned char* data,
vtkTypeUInt64 startWord,
size_t numWords,
size_t wordSize);
// Go to the start of the inline data
void SeekInlineDataPosition(vtkXMLDataElement *element);
......@@ -193,7 +186,7 @@ protected:
unsigned int OpenElementsSize;
// The position of the appended data section, if found.
OffsetType AppendedDataPosition;
vtkTypeInt64 AppendedDataPosition;
// How much of the string "<AppendedData" has been matched in input.
int AppendedDataMatched;
......@@ -228,17 +221,17 @@ protected:
// Decompression data.
vtkDataCompressor* Compressor;
unsigned int NumberOfBlocks;
unsigned int BlockUncompressedSize;
unsigned int PartialLastBlockUncompressedSize;
vtkTypeUInt64 NumberOfBlocks;
size_t BlockUncompressedSize;
size_t PartialLastBlockUncompressedSize;
HeaderType* BlockCompressedSizes;
OffsetType* BlockStartOffsets;
vtkTypeInt64* BlockStartOffsets;
// Ascii data parsing.
unsigned char* AsciiDataBuffer;
OffsetType AsciiDataBufferLength;
size_t AsciiDataBufferLength;
int AsciiDataWordType;
OffsetType AsciiDataPosition;
vtkTypeInt64 AsciiDataPosition;
// Progress during reading of data.
float Progress;
......
......@@ -321,8 +321,8 @@ void vtkXMLDataReader::SetupOutputData()
vtkCellData* cellData = output->GetCellData();
// Get the size of the output arrays.
unsigned long pointTuples = this->GetNumberOfPoints();
unsigned long cellTuples = this->GetNumberOfCells();
vtkIdType pointTuples = this->GetNumberOfPoints();
vtkIdType cellTuples = this->GetNumberOfCells();
// Allocate the arrays in the output. We only need the information
// from one piece because all pieces have the same set of arrays.
......@@ -398,11 +398,11 @@ void vtkXMLDataReader::SetupOutputData()
delete [] this->PointDataOffset;
}
this->PointDataTimeStep = new int[this->NumberOfPointArrays];
this->PointDataOffset = new unsigned long[this->NumberOfPointArrays];
this->PointDataOffset = new vtkTypeInt64[this->NumberOfPointArrays];
for(int i=0; i<this->NumberOfPointArrays;i++)
{
this->PointDataTimeStep[i] = -1;
this->PointDataOffset[i] = static_cast<unsigned long>(-1);
this->PointDataOffset[i] = -1;
}
}
if( this->NumberOfCellArrays )
......@@ -416,11 +416,11 @@ void vtkXMLDataReader::SetupOutputData()
delete[] this->CellDataOffset;
}
this->CellDataTimeStep = new int[this->NumberOfCellArrays];
this->CellDataOffset = new unsigned long[this->NumberOfCellArrays];
this->CellDataOffset = new vtkTypeInt64[this->NumberOfCellArrays];
for(int i=0; i<this->NumberOfCellArrays;i++)
{
this->CellDataTimeStep[i] = -1;
this->CellDataOffset[i] = static_cast<unsigned long>(-1);
this->CellDataOffset[i] = -1;
}
}
}
......@@ -625,12 +625,12 @@ int vtkXMLDataReaderReadArrayValues(vtkXMLDataElement* da,
}
vtkAbstractArray* array = iter->GetArray();
// For all contiguous arrays (except vtkBitArray).
vtkIdType num = numValues;
size_t num = numValues;
int result;
void* data = array->GetVoidPointer(arrayIndex);
if(da->GetAttribute("offset"))
{
unsigned long offset = 0;
vtkTypeInt64 offset = 0;
da->GetScalarAttribute("offset", offset);
result = (xmlparser->ReadAppendedData(offset, data, startIndex,
numValues, array->GetDataType()) == num);
......@@ -670,7 +670,7 @@ int vtkXMLDataReaderReadArrayValues(
int inline_data = (da->GetAttribute("offset") == NULL);
unsigned long offset = 0;
vtkTypeInt64 offset = 0;
if (inline_data == 0)
{
da->GetScalarAttribute("offset", offset);
......@@ -691,7 +691,7 @@ int vtkXMLDataReaderReadArrayValues(
vtkStdString prev_string;
while (result && inIndex < actualNumValues)
{
int chars_read = 0;
size_t chars_read = 0;
if (inline_data)
{
chars_read = xmlparser->ReadInlineData(da, isAscii, buffer,
......@@ -843,7 +843,7 @@ int vtkXMLDataReader::PointDataNeedToReadTimeStep(vtkXMLDataElement *eNested)
// we know that time steps are specified and that CurrentTimeStep is in the array
// we need to figure out if we need to read the array or if it was forwarded
// Need to check the current 'offset'
unsigned long offset;
vtkTypeInt64 offset;
if( eNested->GetScalarAttribute("offset", offset) )
{
if( this->PointDataOffset[idx] != offset )
......@@ -913,7 +913,7 @@ int vtkXMLDataReader::CellDataNeedToReadTimeStep(vtkXMLDataElement *eNested)
// we know that time steps are specified and that CurrentTimeStep is in the array
// we need to figure out if we need to read the array or if it was forwarded
// Need to check the current 'offset'
unsigned long offset;
vtkTypeInt64 offset;
if( eNested->GetScalarAttribute("offset", offset) )
{
if( this->CellDataOffset[idx] != offset )
......
......@@ -122,12 +122,12 @@ protected:
// Specify the last time step read, useful to know if we need to rearead data
// //PointData
int *PointDataTimeStep;
unsigned long *PointDataOffset;
vtkTypeInt64 *PointDataOffset;
int PointDataNeedToReadTimeStep(vtkXMLDataElement *eNested);
//CellData
int *CellDataTimeStep;
unsigned long *CellDataOffset;
vtkTypeInt64 *CellDataOffset;
int CellDataNeedToReadTimeStep(vtkXMLDataElement *eNested);
private:
......
......@@ -51,12 +51,6 @@
class OffsetsManager
{
public:
// A type used for data sizes and offsets for stream i/o. Using
// vtkIdType should satisfy most users. This could be streamoff if
// it is deemed portable. It could also be split into OffsetType
// (streamoff) and PositionType (streampos).
typedef vtkIdType OffsetType;
// Construct with default (unsigned long)-1 MTime
OffsetsManager()
{
......@@ -73,22 +67,22 @@ public:
this->RangeMaxPositions.resize(numTimeStep);
this->OffsetValues.resize(numTimeStep);
}
OffsetType &GetPosition(unsigned int t)
vtkTypeInt64 &GetPosition(unsigned int t)
{
assert( t < this->Positions.size());
return this->Positions[t];
}
OffsetType &GetRangeMinPosition(unsigned int t)
vtkTypeInt64 &GetRangeMinPosition(unsigned int t)
{
assert( t < this->RangeMinPositions.size());
return this->RangeMinPositions[t];
}
OffsetType &GetRangeMaxPosition(unsigned int t)
vtkTypeInt64 &GetRangeMaxPosition(unsigned int t)
{
assert( t < this->RangeMaxPositions.size());
return this->RangeMaxPositions[t];
}
OffsetType &GetOffsetValue(unsigned int t)
vtkTypeInt64 &GetOffsetValue(unsigned int t)
{
assert( t < this->OffsetValues.size());
return this->OffsetValues[t];
......@@ -104,11 +98,11 @@ private:
// and slow, but if another couple offsets are added then we should
// consider doing it
// Position in the stream to write the offset
std::vector<OffsetType> Positions;
std::vector<OffsetType> RangeMinPositions; // Where is this
std::vector<OffsetType> RangeMaxPositions; // Whee is this
std::vector<vtkTypeInt64> Positions;
std::vector<vtkTypeInt64> RangeMinPositions; // Where is this
std::vector<vtkTypeInt64> RangeMaxPositions; // Whee is this
std::vector<OffsetType> OffsetValues; // Value of offset
std::vector<vtkTypeInt64> OffsetValues; // Value of offset
};
//----------------------------------------------------------------------------
......
......@@ -90,7 +90,7 @@ static int vtkXMLParserFail(istream* stream)
}
//----------------------------------------------------------------------------
long vtkXMLParser::TellG()
vtkTypeInt64 vtkXMLParser::TellG()
{
// Standard tellg returns -1 if fail() is true.
if(!this->Stream || vtkXMLParserFail(this->Stream))
......@@ -101,8 +101,8 @@ long vtkXMLParser::TellG()
// No work-around required. Just return the position.
return this->Stream->tellg();
#else
long pos = this->Stream->tellg();
if(pos == -1)
std::streampos pos = this->Stream->tellg();
if(pos < 0)
{
// Clear the fail bit from failing tellg.
this->Stream->clear(this->Stream->rdstate() & ~ios::failbit);
......@@ -139,7 +139,7 @@ long vtkXMLParser::TellG()
}
//----------------------------------------------------------------------------
void vtkXMLParser::SeekG(long position)
void vtkXMLParser::SeekG(vtkTypeInt64 position)
{
// Standard seekg does nothing if fail() is true.
if(!this->Stream || vtkXMLParserFail(this->Stream))
......@@ -148,7 +148,7 @@ void vtkXMLParser::SeekG(long position)
}
#if VTK_STREAM_EOF_SEVERITY == 0
// No work-around required. Just seek to the position.
this->Stream->seekg(position);
this->Stream->seekg(std::streampos(position));
#else
// Save the eof bit.
int eof = this->Stream->eof()?1:0;
......@@ -161,7 +161,7 @@ void vtkXMLParser::SeekG(long position)
# if VTK_STREAM_EOF_SEVERITY == 3
// Check if the stream is in the buggy state.
if(long(this->Stream->tellg()) == -1)
if(this->Stream->tellg() < 0)
{
// Call an internal filebuf method to escape the buggy stream
// state. This is a very ugly hack.
......@@ -172,7 +172,7 @@ void vtkXMLParser::SeekG(long position)
# endif
// Seek to the given position.
this->Stream->seekg(position);
this->Stream->seekg(std::streampos(position));
// Restore the eof bit.
if(eof)
......@@ -484,7 +484,7 @@ void vtkXMLParser::ReportXmlParseError()
}
//----------------------------------------------------------------------------
unsigned long vtkXMLParser::GetXMLByteIndex()
vtkTypeInt64 vtkXMLParser::GetXMLByteIndex()
{
return XML_GetCurrentByteIndex(static_cast<XML_Parser>(this->Parser));
}
......
......@@ -47,14 +47,14 @@ public:
// Get/Set the input stream.
vtkSetMacro(Stream, istream*);
vtkGetMacro(Stream, istream*);
//ETX
// Description:
// Used by subclasses and their supporting classes. These methods
// wrap around the tellg and seekg methods of the input stream to
// work-around stream bugs on various platforms.
long TellG();
void SeekG(long position);
vtkTypeInt64 TellG();
void SeekG(vtkTypeInt64 position);
//ETX
// Description:
// Parse the XML input.
......@@ -166,7 +166,7 @@ protected:
virtual void ReportXmlParseError();
// Get the current byte index from the beginning of the XML stream.
unsigned long GetXMLByteIndex();
vtkTypeInt64 GetXMLByteIndex();
// Send the given buffer to the XML parser.
virtual int ParseBuffer(const char* buffer, unsigned int count);
......
......@@ -99,7 +99,7 @@ vtkXMLRectilinearGridWriter::CreateExactCoordinates(vtkDataArray* a, int xyz)
{
// Create a subset of the coordinates array.
int components = a->GetNumberOfComponents();
int tupleSize = components*this->GetWordTypeSize(a->GetDataType());
size_t tupleSize = components*this->GetWordTypeSize(a->GetDataType());
vtkDataArray* b = a->NewInstance();
b->SetNumberOfComponents(components);
b->SetName(a->GetName());
......
......@@ -240,7 +240,7 @@ int vtkXMLUnstructuredDataWriter::ProcessRequest(vtkInformation* request,
//----------------------------------------------------------------------------
void vtkXMLUnstructuredDataWriter::AllocatePositionArrays()
{
this->NumberOfPointsPositions = new unsigned long[this->NumberOfPieces];
this->NumberOfPointsPositions = new vtkTypeInt64[this->NumberOfPieces];
this->PointsOM->Allocate(this->NumberOfPieces, this->NumberOfTimeSteps);
this->PointDataOM->Allocate(this->NumberOfPieces);
......@@ -506,8 +506,8 @@ void vtkXMLUnstructuredDataWriter::WriteAppendedPieceData(int index)
ostream& os = *(this->Stream);
vtkPointSet* input = this->GetInputAsPointSet();
unsigned long returnPosition = os.tellp();
os.seekp(this->NumberOfPointsPositions[index]);
std::streampos returnPosition = os.tellp();
os.seekp(std::streampos(this->NumberOfPointsPositions[index]));
vtkPoints* points = input->GetPoints();
this->WriteScalarAttribute("NumberOfPoints",
(points?points->GetNumberOfPoints():0));
......
......@@ -122,7 +122,7 @@ protected:
int GhostLevel;
// Positions of attributes for each piece.
unsigned long* NumberOfPointsPositions;
vtkTypeInt64* NumberOfPointsPositions;
// For TimeStep support
OffsetsManagerGroup *PointsOM;
......
......@@ -117,7 +117,7 @@ void vtkXMLUnstructuredGridWriter::AllocatePositionArrays()
{
this->Superclass::AllocatePositionArrays();
this->NumberOfCellsPositions = new unsigned long[this->NumberOfPieces];
this->NumberOfCellsPositions = new vtkTypeInt64[this->NumberOfPieces];
this->CellsOM->Allocate(this->NumberOfPieces,5,this->NumberOfTimeSteps);
}
......@@ -164,8 +164,8 @@ void vtkXMLUnstructuredGridWriter::WriteAppendedPieceData(int index)
ostream& os = *(this->Stream);
vtkUnstructuredGrid* input = this->GetInput();
unsigned long returnPosition = os.tellp();
os.seekp(this->NumberOfCellsPositions[index]);
std::streampos returnPosition = os.tellp();
os.seekp(std::streampos(this->NumberOfCellsPositions[index]));
this->WriteScalarAttribute("NumberOfCells", input->GetNumberOfCells());
if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
{
......
......@@ -73,7 +73,7 @@ protected:
void CalculateSuperclassFraction(float* fractions);
// Positions of attributes for each piece.
unsigned long* NumberOfCellsPositions;
vtkTypeInt64* NumberOfCellsPositions;
OffsetsManagerArray *CellsOM; //one per piece
private:
......
This diff is collapsed.
......@@ -58,15 +58,6 @@ public:
enum { BigEndian, LittleEndian };
//ETX
//BTX
// Description:
// A type used for data sizes and offsets for stream i/o. Using
// vtkIdType should satisfy most users. This could be streamoff if
// it is deemed portable. It could also be split into OffsetType
// (streamoff) and PositionType (streampos).
typedef vtkIdType OffsetType;
//ETX
//BTX
// Description:
// Enumerate the supported data modes.
......@@ -234,7 +225,7 @@ protected:
int EncodeAppendedData;
// The stream position at which appended data starts.
OffsetType AppendedDataPosition;
vtkTypeInt64 AppendedDataPosition;
// appended data offsets for field data
OffsetsManagerGroup *FieldDataOM; //one per array
......@@ -278,10 +269,10 @@ protected:
// Compression information.
vtkDataCompressor* Compressor;
unsigned int BlockSize;
OffsetType CompressionBlockNumber;
unsigned int CompressionBlockNumber;
HeaderType* CompressionHeader;
unsigned int CompressionHeaderLength;
OffsetType CompressionHeaderPosition;
vtkTypeInt64 CompressionHeaderPosition;
// The output stream used to write binary and appended data. May
// transparently encode the data.
......@@ -325,18 +316,18 @@ protected:
// a double-precision floating point value written to 13 digits of
// precision (the other 7 come from a minus sign, decimal place, and
// a big exponent like "e+300").
OffsetType ReserveAttributeSpace(const char* attr, int length=20);
OffsetType GetAppendedDataOffset();
OffsetType WriteAppendedDataOffset(OffsetType streamPos,
OffsetType &lastoffset,
const char* attr=0);
OffsetType ForwardAppendedDataOffset(OffsetType streamPos,
OffsetType offset,
const char* attr=0);
OffsetType ForwardAppendedDataDouble(OffsetType streamPos,
double value,
const char* attr);
vtkTypeInt64 ReserveAttributeSpace(const char* attr, size_t length=20);
vtkTypeInt64 GetAppendedDataOffset();
void WriteAppendedDataOffset(vtkTypeInt64 streamPos,
vtkTypeInt64 &lastoffset,
const char* attr=0);
void ForwardAppendedDataOffset(vtkTypeInt64 streamPos,
vtkTypeInt64 offset,
const char* attr=0);
void ForwardAppendedDataDouble(vtkTypeInt64 streamPos,
double value,
const char* attr);
int WriteScalarAttribute(const char* name, int data);
int WriteScalarAttribute(const char* name, float data);
......@@ -368,9 +359,9 @@ protected:
int timestep=0);
int WriteAsciiData(vtkAbstractArray* a, vtkIndent indent);
int WriteBinaryData(vtkAbstractArray* a);
int WriteBinaryDataInternal(vtkAbstractArray* a, OffsetType data_size);
void WriteArrayAppendedData(vtkAbstractArray* a, OffsetType pos,
OffsetType &lastoffset);
int WriteBinaryDataInternal(vtkAbstractArray* a);
void WriteArrayAppendedData(vtkAbstractArray* a, vtkTypeInt64 pos,
vtkTypeInt64 &lastoffset);
// Methods for writing points, point data, and cell data.
void WriteFieldData(vtkIndent indent);
......@@ -413,15 +404,14 @@ protected:
vtkDataArray* zc, vtkIndent indent);
// Internal utility methods.
int WriteBinaryDataInternal(void* data, OffsetType numWords, int wordType);
int WriteBinaryDataBlock(unsigned char* in_data, OffsetType numWords, int wordType);
int WriteBinaryDataBlock(unsigned char* in_data, size_t numWords, int wordType);
void PerformByteSwap(void* data, size_t numWords, size_t wordSize);
int CreateCompressionHeader(OffsetType size);
int WriteCompressionBlock(unsigned char* data, OffsetType size);
int CreateCompressionHeader(size_t size);
int WriteCompressionBlock(unsigned char* data, size_t size);
int WriteCompressionHeader();
OffsetType GetWordTypeSize(int dataType);
size_t GetWordTypeSize(int dataType);
const char* GetWordTypeName(int dataType);
OffsetType GetOutputWordTypeSize(int dataType);
size_t GetOutputWordTypeSize(int dataType);
char** CreateStringArray(int numStrings);
void DestroyStringArray(int numStrings, char** strings);
......@@ -451,7 +441,7 @@ protected:
// when using the Start/Stop/WriteNextTime API
int UserContinueExecuting; //can only be -1 = invalid, 0 = stop, 1 = start
unsigned long *NumberOfTimeValues; //one per piece / per timestep
vtkTypeInt64 *NumberOfTimeValues; //one per piece / per timestep
//BTX
friend class vtkXMLWriterHelper;
//ETX
......
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