$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Dave Handley (dave_at_[hidden])
Date: 2005-01-12 17:01:07
Following on from my last post regarding composites, I've dug out my work on 
acyclic visitors, and dealing with them alongside composites.  I've put 
these up on a web server for people to have a look at as well.  Again I 
would be interested in comments.
http://dah.me.uk/pattern_tl/acyclic_visitor.hpp
http://dah.me.uk/pattern_tl/composite_visitor.hpp
I've also added some demonstration files to show the sorts of class you 
might create with the composite and the composite visitors
http://dah.me.uk/pattern_tl/NodeBase.h
http://dah.me.uk/pattern_tl/VisitorBase.h
In use the acyclic visitor is very similar to Alexandrescu's - with only one 
notable change.  I have moved the default visit function into the visitor 
rather than having it in the visitable.  This means that any visitable 
hierarchy can interact with lots of different visitors, with different 
default actions and potentially different return types.  I find this much 
more intuitive than the DefaultCatchAll template in Alexandrescu's version.
The composite visitors allow you to traverse a given composite in a given 
order calling the visitor on every node in the tree.  I wrote this because 
of the number of times that you tend to do this particular operation when 
using composites.  You simply need to inject in the composite visitor to 
turn a visitor into a composite visitor.  This results in a slightly odd 
double-visitation stage where the visitor accepts the visitable, iterates 
over it and accepts the visitor back again.  I generally tend to use this by 
first setting up a visitor eg:
class MyVisitor : public pattern_tl::base_visitor<>, public 
pattern_tl::visitor<MyNode>;
Then creating versions that implement the different ordering strategies as 
necessary eg:
class MyVisitorTopToBottom : public MyVisitor,
    public pattern_tl::composite_visitor<MyVisitorTopToBottom,MyNode>
{
};
Then the visiting sequence is initiating by letting the visitor accept the 
head of the composite:
MyVisitorTopToBottom visitor;
visitor.accept( head );
Again, any feedback and/or interest would be appreciated.
Dave Handley