Hey all,

Hope you're doing well.

I have a bit of a design problem that I can't quite figure out how to pull off. Essentially, I have a graph (happens to be directed, but that's not terribly important) of types of widgets. An edge in the graph represents that we know how to turn a widget of one type into a widget of another type, and it should be accompanied by the converter to do so. Each type of widget looks like:

Code:
template <typename WIDGET_TEST>
class WidgetInterface
{
public:
    virtual bool verify(const WIDGET_TEST& wt) const = 0;
    virtual float getAccuracy(const WIDGET_TEST& wt) const = 0;
};
Here's a sample implementation:
Code:
class FooWidgetTest;

class FooWidget : WidgetInterface<FooWidgetTest>
{
    virtual bool verify(const FooWidgetTest& wt) const;
    virtual float getAccuracy(const FooWidgetTest& wt) const;

protected:

    // various data structures - say a graph, an int, and a Ferrari
};
And here would be the converters.
Code:
template <typename WidgetA, typename WidgetB>
class Converter
{

public:
    virtual WidgetB convert(const WidgetA& aw) = 0;
    virtual WidgetATest reverseTest(const WidgetBTest& wbt) = 0;

    // not sure how to get it to work, but ideally would like to pull
    // the types of WidgetATest and WidgetBTest from WidgetA and WidgetB
};

class FooToBazConverter : Converter<FooWidget, BazWidget>
{
    virtual BazWidget convert(const FooWidget& aw);
    virtual FooWidgetTest reverseTest(const BazWidgetTest& wbt);
};
From this point, what I want to be able to do is, given an instance of a widget of one type and a target type, find the shortest path in the graph of conversions, then run through all of the converters to end up with that widget instance converted to another widget type. However, I see several problems with this.

1. WidgetInterface doesn't really help much if each Widget implementation uses a different template param, because then as far as I know, we can't store these in the same data structure, so I don't know what type to make the vertices in the graph. I could of course eliminate the template part, and make them all generic parameters (FooWidget inherits AbstractWidget, and AbstractWidget's interface uses AbstractWidgetTests), but then all of the subclasses have to manually cast their arguments whenever they receive them.

2. I have the same problem for the converters; I wouldn't know what type of structure to make the edges in the graph.

Does anybody have any advice on how to accomplish this problem? At this point I'm guessing this is NOT an appropriate use of templates, or even inheritance, but it also seems clunky to just implement all of these as standalone types if they have the same signatures just with different types. Thanks very much in advance.

--Fortress

P.S. I was planning to use the Boost graph classes, as I've never tried them before, so any advice specific to those would be fantastic.