Original Post
The stage:
Loader : A templated factory which creates object of a specific type.
Resource : End end object I want to have
IntermediateResource : An object used to create another object.
The problem:
Case 1: I want to create a Texture Object. The texture object must be initialised with an image object. I can use an image factory to create the image. I then create the texture by passing it the image.
Case 2: I want to create a Model Object. The model object needs no initialisation. I just load it.
This behaviour as to how to treat these two datatypes in my template resource manager appears to need to be different depending on the datatype.
Cut-Pasted code so it might look weird.
The problem I''m having is the "BaseResource->Create(Loader->Load(Name));" part. This works fine for textures, but models and many other datatypes need no two stage creation, and where I insert it in to the map I''d like to insert the resource returned by loader directly.
How do I do this? I _could_ do it at runtime but it seems sooo compile time... I should''nt have to query a type for capability to work out how to treat it... I can''t seem to nut this one out. I don''t know what ''partial template specialisation is, though I know my .net compiler doesn''t support it. Is this my problem?
Suggestions?
Chris Brodie
http:\\fourth.flipcode.com
inline void CResourceManager<ResourceType, LoaderType>::Aquire(const std::string& a_Name, CHandle<ResourceType, LoaderType>& a_Handle)
{
std::string Name(a_Name);
StringUtilities::Lower(Name);
ResourceItr itr = m_Resources.find(Name);
if (itr == m_Resources.end())
{
std::string Extention = CFile::GetExtention(Name);
if (Extention.empty() == true)
assert(0);
boost::shared_ptr<LoaderType> Loader(CFactory<std::string, LoaderType>::GetInstance().Create(Extention));
if (Loader.get() == 0)
assert(0);
boost::shared_ptr<ResourceType> BaseResource(new ResourceType);
BaseResource->Create(Loader->Load(Name));
std::pair<ResourceItr, bool> Result = m_Resources.insert(std::make_pair(Name, std::make_pair(BaseResource, 0)));
if (Result.second == false)
assert(0);
else
itr = Result.first;
}
++(itr->second.second);
a_Handle.SetResource(itr);
}