#ifndef IResourceCollection_h__ #define IResourceCollection_h__ #include #include #include "resource_ptr.h" #include "LString.h" #include "Globals.h" namespace LifeGraphics { template class IResourceCollection { private: typedef std::map> resourceMap; int resCnt; resourceMap collection; int lastId; int NextId() { return lastId++; } public: int CollectGarbage() { int cnt = collection.size(); for(int i = 0; i < cnt; i++) { } } IResourceCollection() { resCnt = 0; lastId = 0; } ~IResourceCollection() { } int push_back(resource_ptr resource) { resource->Id = NextId(); collection[resource->Id] = resource; resCnt++; return resource->Id; } void Release() { for(resourceMap::iterator it = collection.begin(); it != collection.end(); it++) { it->second->Release(); } } int Exists(const String& name) { for(resourceMap::iterator it = collection.begin(); it != collection.end(); it++) { if(it->second->Name == name) { return 1; } } return 0; } int GetResource(int id, resource_ptr& resource) { resource = collection[id]; return 0; } int GetResource(String name, resource_ptr& resource) { for(resourceMap::iterator it = collection.begin(); it != collection.end(); it++) { if(it->second->Name == name) { resource = it->second; return 1; } } return 0; } }; } #endif