Commit 20b7dc8b authored by Andy Cedilnik's avatar Andy Cedilnik

Add support for directo support for parsing files and messages

parent 4fd5d00d
......@@ -21,7 +21,13 @@
#include "expat.h"
#include <ctype.h>
vtkCxxRevisionMacro(vtkXMLParser, "1.4");
#ifdef VTK_USE_ANSI_STDLIB
#define VTK_IOS_NOCREATE
#else
#define VTK_IOS_NOCREATE | ios::nocreate
#endif
vtkCxxRevisionMacro(vtkXMLParser, "1.5");
vtkStandardNewMacro(vtkXMLParser);
//----------------------------------------------------------------------------
......@@ -29,13 +35,16 @@ vtkXMLParser::vtkXMLParser()
{
this->Stream = 0;
this->Parser = 0;
this->LegacyHack = 0;
this->LegacyHack = 0;
this->FileName = 0;
this->InputString = 0;
}
//----------------------------------------------------------------------------
vtkXMLParser::~vtkXMLParser()
{
this->SetStream(0);
this->SetFileName(0);
}
//----------------------------------------------------------------------------
......@@ -52,9 +61,30 @@ void vtkXMLParser::PrintSelf(ostream& os, vtkIndent indent)
}
}
//----------------------------------------------------------------------------
int vtkXMLParser::Parse(const char* inputString)
{
this->InputString = inputString;
int result = this->vtkXMLParser::Parse();
this->InputString = 0;
return result;
}
//----------------------------------------------------------------------------
int vtkXMLParser::Parse()
{
ifstream ifs;
if ( !this->InputString && !this->Stream && this->FileName )
{
ifs.open(this->FileName, ios::in VTK_IOS_NOCREATE);
if ( !ifs )
{
return 0;
}
this->Stream = &ifs;
}
// Create the expat XML parser.
this->Parser = XML_ParserCreate(0);
XML_SetElementHandler(this->Parser,
......@@ -81,12 +111,23 @@ int vtkXMLParser::Parse()
XML_ParserFree(this->Parser);
this->Parser = 0;
if ( this->Stream == &ifs )
{
this->Stream = 0;
}
return result;
}
//----------------------------------------------------------------------------
int vtkXMLParser::ParseXML()
{
// Parsing of message
if ( this->InputString )
{
return this->ParseBuffer(this->InputString);
}
// Make sure we have input.
if(!this->Stream)
{
......
......@@ -53,6 +53,15 @@ public:
// Description:
// Parse the XML input.
virtual int Parse();
// Description:
// Parse the XML message.
virtual int Parse(const char* inputString);
// Description:
// Set and get file name.
vtkSetStringMacro(FileName);
vtkGetStringMacro(FileName);
protected:
vtkXMLParser();
......@@ -60,6 +69,12 @@ protected:
// Input stream. Set by user.
istream* Stream;
// File name to parse
char* FileName;
// Character message to parse
const char* InputString;
// Expat parser structure. Exists only during call to Parse().
void* Parser;
......
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