1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
template <typename Resource, typename Identifier>
void ResourceHolder<Resource, Identifier>::load(Identifier id, const std::string& filename)
{
std::unique_ptr<Resource> resource(new Resource());
if (!resource->loadFromFile(filename))
throw std::runtime_error("ResourceHolder::load - Failed to load " + filename);
auto inserted = resourceMap.insert(std::make_pair(id, std::move(resource)));
assert(inserted.second);
}
template <typename Resource, typename Identifier>
template <typename Parameter>
void ResourceHolder<Resource, Identifier>::load(Identifier id, const std::string& filename,
const Parameter& secondParam)
{
std::unique_ptr<Resource> resource(new Resource());
if (!resource->loadFromFile(filename, secondParam))
throw std::runtime_error("ResourceHolder::load - Failed to load " + filename);
auto inserted = resourceMap.insert(std::make_pair(id, std::move(resource)));
assert(inserted.second);
}
template <typename Resource, typename Identifier>
Resource& ResourceHolder<Resource, Identifier>::get(Identifier id)
{
auto foundResource = resourceMap.find(id);
assert(foundResource != resourceMap.end());
return *foundResource->second;
}
template <typename Resource, typename Identifier>
const Resource& ResourceHolder<Resource, Identifier>::get(Identifier id) const
{
auto foundResource = resourceMap.find(id);
assert(foundResource != resourceMap.end());
return *foundResource->second;
}
template <typename Resource, typename Identifier>
void ResourceHolder<Resource, Identifier>::insertResource(Identifier id, std::unique_ptr<Resource> resource)
{
auto inserted = resourceMap.insert(std::make_pair(id, std::move(resource)));
assert(inserted.second);
}
|