mercredi 27 mai 2015

How to generate typelist for factory?

I use library Loki. I need to generate concrete and abstract factory for classes:

class base1 {
public:
    virtual void print() = 0;
};
class base2 {};
class base3 {};

class derived1 : public base1 {
    int a;
public:
    derived1() : a(0) {}
    void print()override { std::cout << a << std::endl; }
};
class derived2 : public base2 {};
class derived3 : public base3 {};

The default declaration of factor in Loki:

typedef Loki::AbstractFactory <
     LOKI_TYPELIST_3(base1, base2, base3)
> BaseAbstarctFactory;

typedef
    Loki::ConcreteFactory
    <
        BaseAbstarctFactory,
        Loki::OpNewFactoryUnit,
        LOKI_TYPELIST_3(derived1, derived2, derived3)
    >
DerivedConcreteFactory;

I noticed that

LOKI_TYPELIST_3(base1, base2, base3)

is equal to

Typelist<base1, Typelist<base2, Typelist<base3, NullType>>>

If I had a list of types

typedef boost::mpl::vector <base1, base2, base3> base_types;

How can i generate Typelist to use it in a factory declaration which is equal to base_types?

Aucun commentaire:

Enregistrer un commentaire