Boost logo

Boost Users :

From: Dan Posluns (dan_at_[hidden])
Date: 2007-09-14 21:11:03


Okay, I'm a lot closer to my goal of having an automated factory of
objects that are dynamically polymorphic but have their inheritance set
up through static means.

What I have now is something like this:

// My factory template
template<class Base, class Derived>
struct Factory
{
    Base *create() { return new Derived(); }
};

// My vector of factories for the different Derived types
typedef mpl::vector<
    Factory<Base, Derived1>,
    Factory<Base, Derived2>,
    Factory<Base, Derived3> > MyFactories;

(I actually use MPL to automatically cross and combine different
classes, which is pretty cool.)

Now I could create a vector of the same length with every type as a
pointer to a Factory function, and with Fusion I could probably
instantiate it (although I haven't got that working yet). But that still
wouldn't get me what I want, which is a table of those factory functions
that I can index into at run-time.

Can anyone suggest a technique for doing this?

Thanks,

Dan.

-- 
Dan Posluns, B. Eng. & Scty. (Software Engineering and Society)
dan_at_[hidden] - ICQ: 35758902
http://www.danposluns.com
"The great thing about being the only species on the planet that makes
a distinction between right and wrong is that we get to make the rules
up for ourselves as we go."
- Douglas Adams, Last Chance to See

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net