Boost logo

Boost :

From: Boris Kolpackov (boris_at_[hidden])
Date: 2006-11-01 03:26:14

Hi Stefan,

Stefan Seefeld <seefeld_at_[hidden]> writes:

> What about an interface similar to SAX, where the user provides a set
> of handlers, one per type, and then the reader calls the appropriate
> one ? For example:
> void handle1(token1 const &);
> void handle2(token2 const &);
> ...
> typedef reader<handle1, handle2, ...> my_reader;
> my_reader r(filename);
> while ( r.process();

I think there is not much you can do in that while loop except calling
process() which then brings the question of why not use the push model
(e.g., SAX) since that is what you are essentially emulating.

Also note that you can get this behavior with a normal reader and a
visitor but with a modular design as a bonus:

typedef visitor<handle1, handle2, ...> v;
reader r (filename);
while (node* n = v.visit (n);

> ... so an iterator is still possible, for example to 'fast-forward' to
> a particular position in the stream.

In order to skip to a particular position you will need to examine the
data (and thus cast, etc.). There is not much use of skipping 5 nodes
from now. One common example would be skipping a sub-tree for which
you will need node types and/or names.


Boris Kolpackov
Code Synthesis Tools CC
Open-Source, Cross-Platform C++ XML Data Binding

Boost list run by bdawes at, gregod at, cpdaniel at, john at