I've always had a resource manager in my client software that has different resource containers.
Basically this:
in library:
template<class _Type>
class Container {
// code dealing with loading resources
};
in client:
class Resources {
public:
Container<Sprite> sprite;
Container<Music> music;
Container<Font> font;
};
So in the client code, you just use it like this:
Sprite* player_idle = res->sprite["Objects"]["Characters"]["Player"]("idle");
I won't get into any more detail, but you now understand how it works, I presume.
So what I want is to have the "Resources" class in the library.
I want it to be like this:
class Resources {
std::vector<Container<?>> _containers;
public:
template<class _Type>
void add_type() {
_containers.push_back(Container<_Type>());
}
};
But that won't work, as the std::vector class only takes one specific type.
I've thought of making a wrapper class of every resource type, and just base them off a class, but that seems like a very unelegant solution, both for the library and client.
I could also just use a switch, but what would be the point - the client would not be able to create new types that way.
Thanks in advance! :)