[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: SAX/C++: First interface draft

  • From: "Richard Anderson" <rja@a...>
  • To: "XMLDev list" <xml-dev@i...>
  • Date: Fri, 3 Dec 1999 15:16:20 -0000

interface class c
> Actually, I don't see any strong argument not to provide empty inline
> implementations for the handler callbacks:
>
>     virtual void startDocument (void) {}
>     virtual void endDocument (void) {}
>     virtual void startElement (const char * name, const AttributeList
&atts) {}
>     virtual void endElement (const char * name) {}

I think the "= 0" is far more normal in the C/C++.  I personally prefer that
approach because if I derive a class from the parser class, and do a typo in
method implementation in the derived class I get a compile error, rather
than spending time figuring out the empty base class implementation is being
called.  Having a handler base is fine by me.

If we do go for the "= 0" approach I suggest the class be prefixed with an
"I" (for interface).  Those who work with COM will understand that rational
behind that ;)


> I appreciate James sharing some of his C++ experience here.  This
> sounds like a good idea to me, but I'm at best a C++ journeyman, so
> I'd be happy to hear from other masters on the list.

The other option is :

protected:
   virtual ~CSAXParser() {}

Of course, it is nice to be able to delete things so should the class should
probably include a delete or release method:

    virtual void delete() = 0;

That can then be implemented using referencing counting if so desired or a
straight delete.

> > - use iosfwd not istream as the header file

I've not used isofwd, but why not just define a SAX input stream class :

class CInputStream
{
public:

    virtual int ReadChar( unsigned char& ch ) = 0;
    ...
};

I for one have implemented by SAX support this way so people using the
toolkit can implement streams however they see fit, esp. if STL support on
their platform is a but shaky.

> > - solve the UTF-8/UTF-16 problem by having two namespaces: a SAX_UTF8
> > and a SAX_UTF16 namespace (since you're using std::istream, you are
> > assuming compiler support for namespaces); this will work nicely with
> > namespace aliases (eg namespace SAX = SAX_UTF8).

We've had problems with namespaces not being supported with some compilers,
so it is best to avoid them.  That is the reason why I suggest all
interface/class names are prefixed with SAX, CSAX or better still ISAX

Regards,

Richard.




xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@i...
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To unsubscribe, mailto:majordomo@i... the following message;
unsubscribe xml-dev
To subscribe to the digests, mailto:majordomo@i... the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@i...)



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.