Boost logo

Boost :

From: Dave Handley (dave_at_[hidden])
Date: 2005-01-12 16:14:52


During the recent discussions on Jason's Singleton implementation, I
mentioned that I had some other code for patterns available. I have just
put my composite implementation up on a web-server for people to have a look
at, the following links lead to the code:

http://dah.me.uk/pattern_tl/Composite.h
http://dah.me.uk/pattern_tl/CompositeShallowIterator.h
http://dah.me.uk/pattern_tl/CompositeDeepIterator.h
http://dah.me.uk/pattern_tl/CompositeTypedShallowIterator.h
http://dah.me.uk/pattern_tl/CompositeTypedDeepIterator.h
http://dah.me.uk/pattern_tl/CompositeFunctorIterator.h

Usage of the code is pretty simple. A composite is created using CRTP - for
example

class node: public class pattern_tl::composite<node>;

You are required to implement a Clone function since this is used for tree
duplication.

There is a basic set of functions to add entries to the tree (for example
push_back), remove entries from the tree, and navigate up the tree. Then
there are a whole bunch of iterators to use in getting around the tree. The
shallow iterators just iterate over direct descendents of a node, the deep
iterators iterate over the entire tree below a node (including the start
node), the typed iterators use RTTI to allow you to shallow/deep iterator
over the tree picking out nodes of a particular type; and the functor
iterator applies a functor to each node to decide whether to return it in an
iteration (note that there are no const versions of the functor iterators).
If you don't include either CompositeTypedShallowIterator.h or
CompositeTypedDeepIterator.h then you don't need to build with RTTI.

I'm pretty sure that there is scope for improvement, and I would appreciate
any constructive feedback. Plus I would be interested in the general view
about creating a "pattern_tl" library within Boost to contain, for example,
this code, plus other generic design pattern implementations including
singletons and visitors etc.

Finally, I know that for submission to Boost I would need to do some tidying
up, changes to naming standards etc, plus I would need to write a test
suite - but I'm just interested in general opinions at the moment, and
suggestions for improvements.

Dave Handley


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