Boost logo

Boost :

From: Simon Richter (Simon.Richter_at_[hidden])
Date: 2005-06-02 06:16:05


Hi,

as probably everyone in here, I have written many factory
implementations and plugin managers in various projects, and decided to
throw them all together into a set of template classes.

My current approach looks like this:

 - class registrable

base class for objects that can be registered somewhere

 - class registry : public registrable

base class for objects that need to register some other objects.
inherits from registrable, so there can be a registry of all registries
(I think that can be made optional, but haven't found a compelling
reason to do so). defines a set of abstract functions that registries
need to implement (register/unregister of const/non-const objects), and
static functions to register/unregister objects (by going through the
list of registries and passing the object to each).

 - template<typename obj>
   class creator : public registrable

base class for objects responsible for instantiating a concrete class
and providing an object to match the factory argument against.

 - template<typename obj>
   class factory : public registry<creator<object_type>>

factory. registers creators and can be asked to instantiate objects.

 - template<typename obj, typename stream>
   class parser

base class for parsers. holds a stream reference and an object of "obj"
type, defines some abstract functions and knows how to create proxy
objects for the postincrement operator.

 - template<typename obj, typename stream>
   class parseiterator

holds and owns a pointer to a parser<obj, stream> object, behaves like
an iterator. can be instantiated on the stack, uses parameters to
instantiate parser by using factory<parser<obj, stream>>.

I believe these things are fairly generic and was surprised that they
weren't already there. Would it make sense to add these to boost (after
properly specifying and documenting them, of course)?

   Simon


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