Re: Expat and C++ ?
Albrecht Fritzsche <[email protected]>
| Newsgroups | gmane.text.xml.expat.general |
|---|---|
| Message-ID | <Pine.SOL.4.58.0607041226360.10@twen> |
On Tue, 4 Jul 2006 [email protected] wrote: > ---------------------------------------------------------------------- > > Message: 1 > Date: Mon, 03 Jul 2006 19:19:21 -0400 > From: hymedia <[email protected]> > Subject: Re: [Expat-discuss] Expat and C++ ? > To: [email protected] > Message-ID: <[email protected]> > Content-Type: text/plain; charset=us-ascii > > Hi all! > > Anyone have an exemple on how to wrap expat2 in a c++ class witout static or > global functions? Maybe something along the following lines... struct Wrapper { XML_Parser m_parser; void init( const XML_Char* encoding, const XML_Char* seperator) { m_parser = XML_ParserCreate_MM( encoding, 0, // memsuite seperator); // namespace seperator if (!m_parser) return; // Set the user data used in callbacks XML_SetUserData(m_parser, (void *) this); } void fini() { if (m_parser) XML_ParserFree(m_parser); m_parser = 0; } bool parse( const char* buffer, int length, bool isFinal) { assert(m_parser != NULL); // get the length if not specified if (length < 0) length = strlen(buffer); // invoke the parser return XML_Parse(m_parser,buffer,length,isFinal)!=0; } ... }; Hope it helps, Ali