After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 329281 - Parsers could be given a stream with the usual operator >>
Parsers could be given a stream with the usual operator >>
Status: RESOLVED FIXED
Product: libxml++
Classification: Bindings
Component: General
git master
Other All
: Normal enhancement
: ---
Assigned To: Christophe de Vienne
Christophe de Vienne
Depends on:
Blocks:
 
 
Reported: 2006-01-30 23:57 UTC by Pierre THIERRY
Modified: 2014-10-21 14:32 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
Patch to include the new header file (1.36 KB, patch)
2006-01-30 23:59 UTC, Pierre THIERRY
none Details | Review
New header file (518 bytes, text/plain)
2006-01-31 00:01 UTC, Pierre THIERRY
  Details
patch: Parser: Add input operator>>() (857 bytes, patch)
2014-10-01 14:18 UTC, Kjell Ahlstedt
none Details | Review

Description Pierre THIERRY 2006-01-30 23:57:47 UTC
It is a common way to deal wioth streams to use the << and >> operators. As
Parsers can deal with istreams, they could provide a >> operator to take such a
stream, as a convenience.
Comment 1 Pierre THIERRY 2006-01-30 23:59:48 UTC
Created attachment 58435 [details] [review]
Patch to include the new header file

The patch doesn't contain the header itself, as I have no write access to the CVS repository, and CVS needs write access to produce a diff on an added file <sick>.
Comment 2 Pierre THIERRY 2006-01-31 00:01:10 UTC
Created attachment 58436 [details]
New header file

This file contains the actual header implementing operator>> for parsers objects.
Comment 3 Murray Cumming 2006-11-17 07:51:09 UTC
1. The use of a template does not see wise. Wouldn't that match any class, causing mismatches or clashes with other (even non-libxml++ classes) that are used with the stream operator?
2. Wouldn't the use of the stream operator imply that the data can be provided gradually, with repeated calls to the stream operator? That is not the case - parse_stream() pulls the whole docucment from the stream in one go.
Comment 4 Murray Cumming 2007-02-10 12:24:53 UTC
Do you have any thoughts about my reply above?
Comment 5 Pierre THIERRY 2007-02-10 16:49:15 UTC
Sorry for the delay, I didn't notive your comment in November...

(In reply to comment #3)
> Wouldn't that match any class,
> causing mismatches or clashes with other (even non-libxml++ classes) that are
> used with the stream operator?

I don't think so. The first argument of the template must provide a parse_stream method with a single argument of type std::istream&.

That's pretty restrictive.

> 2. Wouldn't the use of the stream operator imply that the data can be provided
> gradually, with repeated calls to the stream operator? That is not the case -
> parse_stream() pulls the whole docucment from the stream in one go.

Semantically, it seems to me that the stream operator is meant to take from the stream whatever is needed to fill the appropriate right operand. If it's a number, it will take as many digit characters as necessary. For the parser, it will take everything.

Comment 6 Kjell Ahlstedt 2014-10-01 14:17:05 UTC
namespace xmlpp
{
  template<typename Parser_T> Parser_T& operator>>(std::istream& in,
                                                   Parser_T& parser)
  {
    parser.parse_stream(in);
    return parser;
  }
}

The return type is wrong. It shall be std::istream&.

A template is unnecessary and unwise. Overload resolution does not consider
function bodies, only function prototypes. Overload resolution may find that
the template is a viable function even if Parser_T is a class without a
parse_stream() method. Usually this will be no great problem, because

1. It's in namespace xmlpp. Argument-dependent lookup includes it in the set of
   candidate functions only if Parser_T is also in namespace xmlpp.
2. A non-template function with an exact match of argument types is a better
   choice than a template function.

Still, there is no reason to use a template. A non-template operator will do,
and it's less risky. Like so:

namespace xmlpp
{
  inline std::istream& operator>>(std::istream& in, Parser& parser)
  {
    parser.parse_stream(in);
    return in;
  }
}

Parser::parse_stream() is virtual.
Comment 7 Kjell Ahlstedt 2014-10-01 14:18:38 UTC
Created attachment 287519 [details] [review]
patch: Parser: Add input operator>>()

This is a patch with a non-template operator.
Comment 8 Kjell Ahlstedt 2014-10-21 14:32:33 UTC
I have pushed this patch:
https://git.gnome.org/browse/libxml++/commit/?id=2bd4773ca3e89fe83b0cbc8c3b476b682735028f