Boost logo

Boost :

From: Stefan Seefeld (seefeld_at_[hidden])
Date: 2006-11-01 08:28:37


Hi Boris,

Boris Kolpackov wrote:
> 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.next()) 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.

Are you arguing against the pull model here or against my use of
callbacks ?

> 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 = r.next()) v.visit (n);

That's right, but that is inefficient: The reader already does know
the type of the token, but in the name of 'modular design' you throw
it away only to recover it later with an extra round-robin dispatch
through the visitor. What is the advantage of that ?

Regards,
                Stefan

-- 
      ...ich hab' noch einen Koffer in Berlin...

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk