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

BUG: Added vtkXMLParser::TellG and vtkXMLParser::SeekG methods to work-around...

BUG: Added vtkXMLParser::TellG and vtkXMLParser::SeekG methods to work-around buggy stream implementations on some platforms.
parent b0cd30eb
......@@ -20,7 +20,7 @@
#include <ctype.h>
vtkCxxRevisionMacro(vtkXMLDataElement, "1.17");
vtkCxxRevisionMacro(vtkXMLDataElement, "1.18");
vtkStandardNewMacro(vtkXMLDataElement);
//----------------------------------------------------------------------------
......@@ -828,17 +828,17 @@ void vtkXMLDataElement::SeekInlineDataPosition(vtkXMLDataParser* parser)
{
// Scan for the start of the actual inline data.
char c=0;
stream->seekg(this->GetXMLByteIndex());
parser->SeekG(this->GetXMLByteIndex());
stream->clear(stream->rdstate() & ~ios::eofbit);
stream->clear(stream->rdstate() & ~ios::failbit);
while(stream->get(c) && (c != '>'));
while(stream->get(c) && this->IsSpace(c));
unsigned long pos = stream->tellg();
unsigned long pos = parser->TellG();
this->InlineDataPosition = pos-1;
}
// Seek to the data position.
stream->seekg(this->InlineDataPosition);
parser->SeekG(this->InlineDataPosition);
}
//----------------------------------------------------------------------------
......
......@@ -22,7 +22,7 @@
#include "vtkObjectFactory.h"
#include "vtkXMLDataElement.h"
vtkCxxRevisionMacro(vtkXMLDataParser, "1.20");
vtkCxxRevisionMacro(vtkXMLDataParser, "1.21");
vtkStandardNewMacro(vtkXMLDataParser);
vtkCxxSetObjectMacro(vtkXMLDataParser, Compressor, vtkDataCompressor);
......@@ -216,14 +216,14 @@ void vtkXMLDataParser::FindAppendedDataPosition()
// Scan for the start of the actual appended data.
char c=0;
unsigned long returnPosition = this->Stream->tellg();
this->Stream->seekg(this->GetXMLByteIndex());
long returnPosition = this->TellG();
this->SeekG(this->GetXMLByteIndex());
while(this->Stream->get(c) && (c != '>'));
while(this->Stream->get(c) && this->IsSpace(c));
// Store the start of the appended data. We skip the first
// character because it is always a "_".
this->AppendedDataPosition = this->Stream->tellg();
this->AppendedDataPosition = this->TellG();
// If first character was not an underscore, assume it is part of
// the data.
......@@ -235,7 +235,7 @@ void vtkXMLDataParser::FindAppendedDataPosition()
}
// Restore the stream position.
this->Stream->seekg(returnPosition);
this->SeekG(returnPosition);
}
//----------------------------------------------------------------------------
......@@ -243,13 +243,13 @@ unsigned long vtkXMLDataParser::FindInlineDataPosition(unsigned long start)
{
// Scan for the start of the actual inline data.
char c=0;
this->Stream->seekg(start);
this->SeekG(start);
while(this->Stream->get(c) && (c != '>'));
while(this->Stream->get(c) && this->IsSpace(c));
// Make sure some data were found.
if(c == '<') { return 0; }
unsigned long pos = this->Stream->tellg();
unsigned long pos = this->TellG();
return (pos-1);
}
......@@ -812,7 +812,7 @@ unsigned long vtkXMLDataParser::ReadAppendedData(unsigned long offset,
int numWords, int wordType)
{
this->DataStream = this->AppendedDataStream;
this->Stream->seekg(this->AppendedDataPosition+offset);
this->SeekG(this->AppendedDataPosition+offset);
return this->ReadBinaryData(buffer, startWord, numWords, wordType);
}
......@@ -920,13 +920,13 @@ int vtkXMLDataParser::ParseAsciiData(int wordType)
istream& is = *(this->Stream);
// Don't re-parse the same ascii data.
if(this->AsciiDataPosition == (unsigned long)(is.tellg()))
if(this->AsciiDataPosition == static_cast<unsigned long>(this->TellG()))
{
return (this->AsciiDataBuffer? 1:0);
}
// Prepare for new data.
this->AsciiDataPosition = is.tellg();
this->AsciiDataPosition = this->TellG();
if(this->AsciiDataBuffer) { this->FreeAsciiBuffer(); }
int length = 0;
......
......@@ -19,7 +19,7 @@
#include <ctype.h>
#include <sys/stat.h>
vtkCxxRevisionMacro(vtkXMLParser, "1.19");
vtkCxxRevisionMacro(vtkXMLParser, "1.20");
vtkStandardNewMacro(vtkXMLParser);
//----------------------------------------------------------------------------
......@@ -56,6 +56,60 @@ void vtkXMLParser::PrintSelf(ostream& os, vtkIndent indent)
<< "\n";
}
//----------------------------------------------------------------------------
#if defined(VTK_USE_ANSI_STDLIB)
# if defined(__sgi) && !defined(__GNUC__)
# define VTK_XML_NEED_TELLG_WORKAROUND
# elif defined(__BORLANDC__) && (__BORLANDC__>=0x0560)
# define VTK_XML_NEED_TELLG_WORKAROUND
# elif defined(__APPLE_CC__)
# define VTK_XML_NEED_TELLG_WORKAROUND
# endif
#endif
//----------------------------------------------------------------------------
long vtkXMLParser::TellG()
{
// Standard tellg returns -1 if fail() is true.
if(!this->Stream || this->Stream->fail())
{
return -1;
}
#if defined(VTK_XML_NEED_TELLG_WORKAROUND)
// This check is required for buggy streams libraries when VTK is
// built with VTK_USE_ANSI_STDLIB. It seems that after a read that
// just reaches EOF, tellg reports a -1.
long pos = this->Stream->tellg();
if(pos == -1)
{
// Save the eof flag.
int eof = this->Stream->eof()?1:0;
// Clear the eof and seek to the end. This works around the bug.
this->Stream->clear(this->Stream->rdstate() & ~ios::eofbit);
this->Stream->seekg(0, ios::end);
// Call tellg to get the position.
pos = this->Stream->tellg();
// Restore the eof flag.
if(eof)
{
this->Stream->clear(this->Stream->rdstate() | ios::eofbit);
}
}
return pos;
#else
return this->Stream->tellg();
#endif
}
//----------------------------------------------------------------------------
void vtkXMLParser::SeekG(long position)
{
this->Stream->seekg(position);
}
//----------------------------------------------------------------------------
int vtkXMLParser::Parse(const char* inputString)
{
......
......@@ -46,6 +46,13 @@ public:
// Get/Set the input stream.
vtkSetMacro(Stream, istream*);
vtkGetMacro(Stream, istream*);
// 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);
//ETX
// Description:
......
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