*
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
#ifndef IResourceCollection_h__
|
||||
#define IResourceCollection_h__
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include "resource_ptr.h"
|
||||
#include "LString.h"
|
||||
#include "Globals.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
template<typename T>
|
||||
class IResourceCollection
|
||||
{
|
||||
private:
|
||||
typedef std::map<int, resource_ptr<T>> 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<T> 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<T>& resource)
|
||||
{
|
||||
resource = collection[id];
|
||||
return 0;
|
||||
}
|
||||
int GetResource(String name, resource_ptr<T>& resource)
|
||||
{
|
||||
for(resourceMap::iterator it = collection.begin(); it != collection.end(); it++)
|
||||
{
|
||||
if(it->second->Name == name)
|
||||
{
|
||||
resource = it->second;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user