T
TheOne
I have two classes:
class OntologyParser
{
...
protected:
virtual void startElement(void *userData, const char *name, const
char **atts);
virtual void endElement(void *userData, const char *name);
virtual void charData( void *userData, const XML_Char *s, int len );
....
public:
void initXMLParse(const string& fname);
.....
};
This class is a base class for
class ProtegeOntologyParser : public OntologyParser
{
public:
inline ProtegeOntologyParser(const string& strFileName)
{
initXMLParse(strFileName);
}
};
I am using G++ on RedHat 9.0 Linux with Expat library.
The initXMLParse function is common to all (here just
ProtegeOntologyParser) derived classes hence I want to keep that in
parent class. The functions startElement, endElement and charData must
be implemented separately by all derived classes.
However the problem is expat needs call backs setup for startElement,
endElement and charData functions from within initXMLParse like this:
void OntologyParser::initXMLParse(const string& fname)
{
char buffer[BUFSIZ];
int len;
int done;
int depth = 0;
//Get the Parser
XML_Parser parser = XML_ParserCreate(NULL);
//User Data Handler
XML_SetUserData(parser, &depth);
//Element Level Handler
XML_SetElementHandler(parser, startElement, endElement);
//Set What to do with the data
XML_SetCharacterDataHandler( parser, charData );
....
}
But the functions that I pass there as argument must be the functions
of derived classes and right function addresses should be passed based
upon which object was responsible for invoking initXMLParse().
As you know ISO C++ forbids somthing like &(this->charData)
Secondly i do not want to make those 3 function static. and they must
be "virtual" in the base class so that all derived classes are forced
to implement them.
How can I pass those arguments?
class OntologyParser
{
...
protected:
virtual void startElement(void *userData, const char *name, const
char **atts);
virtual void endElement(void *userData, const char *name);
virtual void charData( void *userData, const XML_Char *s, int len );
....
public:
void initXMLParse(const string& fname);
.....
};
This class is a base class for
class ProtegeOntologyParser : public OntologyParser
{
public:
inline ProtegeOntologyParser(const string& strFileName)
{
initXMLParse(strFileName);
}
};
I am using G++ on RedHat 9.0 Linux with Expat library.
The initXMLParse function is common to all (here just
ProtegeOntologyParser) derived classes hence I want to keep that in
parent class. The functions startElement, endElement and charData must
be implemented separately by all derived classes.
However the problem is expat needs call backs setup for startElement,
endElement and charData functions from within initXMLParse like this:
void OntologyParser::initXMLParse(const string& fname)
{
char buffer[BUFSIZ];
int len;
int done;
int depth = 0;
//Get the Parser
XML_Parser parser = XML_ParserCreate(NULL);
//User Data Handler
XML_SetUserData(parser, &depth);
//Element Level Handler
XML_SetElementHandler(parser, startElement, endElement);
//Set What to do with the data
XML_SetCharacterDataHandler( parser, charData );
....
}
But the functions that I pass there as argument must be the functions
of derived classes and right function addresses should be passed based
upon which object was responsible for invoking initXMLParse().
As you know ISO C++ forbids somthing like &(this->charData)
Secondly i do not want to make those 3 function static. and they must
be "virtual" in the base class so that all derived classes are forced
to implement them.
How can I pass those arguments?