I have a template class for generic resource management. It's template parameters are as follows:
class Resource, class LoadData = Void, void (*Loader)(Resource&, const URI&, const LoadData&) = 0, class UnloadData = Void, void (*Unloader)(Resource&, const UnloadData&) = 0
However, it would obviously be better to just load with the constructor of
class Resource
where possible. But it could be some 3rd party class with all sorts of arguments necessary for full construction.
Is the best solution, therefore, to add another template parameter
class ConstructionData
, and then expect the user to write a constructor with this parameter like this:
If our Resource is
sf::Image
then we would just set
ConstructionData
to const char*.
And if we had some 3rd party class in this form:
class foo { public: foo(int a, const std::string& b) {} };
then the user could do this:
1 2 3 4 5 6
|
struct FooConstructionData { int a; const std::string b; };
class user_foo : public foo {
public:
user_foo(const FooConstructionData& data) : foo(data.a, data.b) {}
};
|
So is this a sensible solution, or can someone suggest a better way of doing this?