jeudi 30 avril 2015

What pattern to use to make chain of convertors?

Okay, I need to make chain of convertors, for example, I have a 3D vector: Vec3 and:

Vec3->[Projector]->Vec2->[Rotator]->Vec2->[Moduler]->float->[Processor]->bool

[Projector], [Rotator] and others are convertors. Convertor can have any type as input, and any type as output. And I'll build it as lib, and end user should be able to make his own convertor and add it to chain.

I've thought about double dispatch:

struct Value;

struct Convertor
{
    virtual void Convert(Value& value);
}


struct Value
{
    virtual void ConvertMe(Convertor& conv)
    {
         conv->Convert(*this);
    }
}

It allows me to give user freedom to subclass Value, but problem is: Convertor should have overload of void Convert(SpecificUserValue& value). Which is not possible with built library.

Is it possible to do such thing? If so, how?

Thank you!

Aucun commentaire:

Enregistrer un commentaire