Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T>
- class Resource
- {
- public:
- static Data<T> Create(std::string name);
- static Data<T> Get(std::string name);
- static void Free(Data<T> resource);
- private:
- static bool ResourceExists(std::string name){ return resources.find(name) != resources.end(); }
- static std::map<std::string, Data<T>> resources;
- };
- template<typename T>
- std::map<std::string, Data<T>> Resource<T>::resources;
- template<typename T>
- Data<T> Resource<T>::Create(std::string name)
- {
- Data<T> data;
- if (ResourceExists(name))
- {
- data = Data<T>();
- }
- else
- {
- data = Data<T>::Create();
- resources.insert(std::make_pair(name, data));
- }
- return data;
- }
- template<typename T>
- Data<T> Resource<T>::Get(std::string name)
- {
- Data<T> data;
- if (ResourceExists(name))
- {
- data = resources[name];
- }
- else
- {
- File file = File::Open(name, File::READ);
- T value = ResourceFactory::Create<T>(file);
- data = Data<T>::Create(value);
- }
- return data;
- }
- template<typename T>
- void Resource<T>::Free(Data<T> resource)
- {
- resources.erase(resource->GetName());
- resource->Release();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement