RE: [libxml++] keek blancs.



> From: andy glew amd com [mailto:andy glew amd com] 
> A slight trick, from Stroustrup, that gives you the equivalent 
> of keyword options:
> 
> Instead of 
>   void Parser::set_keepblanks(bool value)
> make it
>   Parser& Parser::set_keepblanks(bool value)
> as in
>   Parser& Parser::set_keepblanks(bool value) {
>       this->m_keepblanks = value;
>       return *this;
>   }
> 
> So, instead of  
>   DomParser domparser;
>   domparser.parse_file(filename,/*keepblanks=*/true);
> you do
>   domparser.set_keepblanks(true).parse_file(filename);
> 
> 
> Such "Stroustrup keywords" have some minor issues:
> either you want to make parse_file a virtual function in Parser,
> so that it picks up the derived DomParser::parse_file or 
> SaxParser::parse_file; or you have to make set_keepblanks
> a delegate in derived classes, with a slightly different
> return.  {Virtual functions better, IMHO.}

I don't think we want this kind of complication. I don't think it's
necessary.

> >  3) add following functions to Document :
> > Document::write_to_formated_file(const std::string& filename, const 
> > std::string& encoding = std::string()) throw(exception);
> > Document::write_to_formated_memory(const std::string& 
> filename, const 
> > std::string& encoding = std::string()) throw(exception);
> 
> First, spelling: write_to_formatted_file...
> 
> Second, this caused me to notice the assymmetry:
>    Parser::parse_file(string_filename), 
>    Parser::parse_memory(string), 
>    Parser::parse_stream(istream)
>    Document::write_to_file(string_filename), 
>    Document::write_to_string(string)
> "Obviously" want write_to_stream(ostream).

Feel free.

> It also tends to suggest that what is wanted is a Formatter object,

Assuming that there are more than these use cases:
- Write it normally.
- Write it with indenting.
Otherwise I don't see the point of the complication.

Xerces-C++ has, or used to have, a Formatting class. It was a pain.

But still, it might be a worthwhile addition to libxml++ 2.

Murray Cumming
murrayc usa net
www.murrayc.com 




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]