M
Matthias
Hello,
I basically want to implement a general resource manager which should have
a caching and a loading policy so that I can exchange those. Here's some
example code of how it should work:
ResourceManager< SimpleCachingPolicy<Image, SimpleImageLoader> > imageMgr;
ResourceManager< SimpleCachingPolicy<Sound, SimpleSoundLoader> > soundMgr;
imageMgr.Load(filename, 1234);
soundMgr.Load(filename, "foo", 5.37);
So we have two managers which load sound and images respectively and both
use the same caching policy. However, notice that the arguments of the
Load function are different.
Now I want to write a SimpleCachingPolicy that can take an arbitrary
object (or pointer to it). I tried like this:
template<typename ResourceType, typename LoadingPolicy>
class SimpleCachingPolicy
{
public:
ResourceType Load(... what to put here, the arguments into this func are
different for each ResourceType ...)
{
if ( IsCached(... same arguments as above ...) ) return obj;
obj=LoadingPolicy::LoadObject(... same args as above ...);
AddToCache(obj);
return obj;
}
};
The problem one can see here is that I would need to write the Load
function several times, one version for each parameter. I thought I could
apply functors here, but I am not sure how I can do this. Can you give me
any hints what I can do to solve this problem? Is there a way round
needing to make several versions of Load(...)?
Thanks a lot for your help!
-Matthias
I basically want to implement a general resource manager which should have
a caching and a loading policy so that I can exchange those. Here's some
example code of how it should work:
ResourceManager< SimpleCachingPolicy<Image, SimpleImageLoader> > imageMgr;
ResourceManager< SimpleCachingPolicy<Sound, SimpleSoundLoader> > soundMgr;
imageMgr.Load(filename, 1234);
soundMgr.Load(filename, "foo", 5.37);
So we have two managers which load sound and images respectively and both
use the same caching policy. However, notice that the arguments of the
Load function are different.
Now I want to write a SimpleCachingPolicy that can take an arbitrary
object (or pointer to it). I tried like this:
template<typename ResourceType, typename LoadingPolicy>
class SimpleCachingPolicy
{
public:
ResourceType Load(... what to put here, the arguments into this func are
different for each ResourceType ...)
{
if ( IsCached(... same arguments as above ...) ) return obj;
obj=LoadingPolicy::LoadObject(... same args as above ...);
AddToCache(obj);
return obj;
}
};
The problem one can see here is that I would need to write the Load
function several times, one version for each parameter. I thought I could
apply functors here, but I am not sure how I can do this. Can you give me
any hints what I can do to solve this problem? Is there a way round
needing to make several versions of Load(...)?
Thanks a lot for your help!
-Matthias