Commit 617e07a6 authored by Brad King's avatar Brad King

COMP: Reading and writing of ascii data for signed char must have special...

COMP: Reading and writing of ascii data for signed char must have special handling to be treated as an integer type.
parent bb1316f2
......@@ -22,7 +22,7 @@
#include "vtkObjectFactory.h"
#include "vtkXMLDataElement.h"
vtkCxxRevisionMacro(vtkXMLDataParser, "1.27");
vtkCxxRevisionMacro(vtkXMLDataParser, "1.28");
vtkStandardNewMacro(vtkXMLDataParser);
vtkCxxSetObjectMacro(vtkXMLDataParser, Compressor, vtkDataCompressor);
......@@ -947,6 +947,40 @@ unsigned char* vtkXMLParseAsciiData(istream& is, int* length, unsigned char*,
return dataBuffer;
}
//----------------------------------------------------------------------------
signed char* vtkXMLParseAsciiData(istream& is, int* length, signed char*,
int)
{
int dataLength = 0;
int dataBufferSize = 64;
signed char* dataBuffer = new signed char[dataBufferSize];
signed char element;
short inElement;
while(is >> inElement)
{
element = inElement;
if(dataLength == dataBufferSize)
{
int newSize = dataBufferSize*2;
signed char* newBuffer = new signed char[newSize];
memcpy(newBuffer, dataBuffer, dataLength*sizeof(signed char));
delete [] dataBuffer;
dataBuffer = newBuffer;
dataBufferSize = newSize;
}
dataBuffer[dataLength++] = element;
}
if(length)
{
*length = dataLength;
}
return dataBuffer;
}
//----------------------------------------------------------------------------
int vtkXMLDataParser::ParseAsciiData(int wordType)
{
......
......@@ -37,7 +37,7 @@
# include <io.h> /* unlink */
#endif
vtkCxxRevisionMacro(vtkXMLWriter, "1.47");
vtkCxxRevisionMacro(vtkXMLWriter, "1.48");
vtkCxxSetObjectMacro(vtkXMLWriter, Compressor, vtkDataCompressor);
//----------------------------------------------------------------------------
......@@ -1377,6 +1377,36 @@ int vtkXMLWriteAsciiData(ostream& os, unsigned char* data, int length,
return (os? 1:0);
}
//----------------------------------------------------------------------------
int vtkXMLWriteAsciiData(ostream& os, signed char* data, int length,
vtkIndent indent, int)
{
int columns = 6;
int rows = length/columns;
int lastRowLength = length%columns;
int r,c;
int pos=0;
for(r=0;r < rows;++r)
{
os << indent << short(data[pos++]);
for(c=1;c < columns;++c)
{
os << " " << short(data[pos++]);
}
os << "\n";
}
if(lastRowLength > 0)
{
os << indent << short(data[pos++]);
for(c=1;c < lastRowLength;++c)
{
os << " " << short(data[pos++]);
}
os << "\n";
}
return (os? 1:0);
}
//----------------------------------------------------------------------------
int vtkXMLWriter::WriteAsciiData(void* data, int numWords, int wordType,
vtkIndent indent)
......
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