Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef RESOURCEMANAGER_H
- #define RESOURCEMANAGER_H
- #include <iostream>
- #include <map>
- namespace BPE
- {
- template <class T>
- class Resource
- {
- public:
- Resource(const std::string &, const std::string &);
- T* const getResource() const;
- const std::string &getFilename() const;
- const std::string &getToken() const;
- private:
- T* resource;
- std::string filename,
- token;
- };
- template <class T>
- class ResourceManager
- {
- public:
- void addResource(const std::string &, const std::string &);
- T* getResource(const std::string &) const;
- private:
- std::map<const std::string, Resource<T> > resources;
- };
- template <class T>
- Resource<T>::Resource(const std::string &fname, const std::string &tok) : resource(new T), filename(fname), token(tok)
- {
- resource -> LoadFromFile(filename);
- std::cout << "Loading: " << token << " (" << filename << ")\n";
- }
- template <class T>
- T* const Resource<T>::getResource() const
- {
- return resource;
- }
- template <class T>
- const std::string &Resource<T>::getFilename() const
- {
- return filename;
- }
- template <class T>
- const std::string &Resource<T>::getToken() const
- {
- return token;
- }
- template <class T>
- void ResourceManager<T>::addResource(const std::string &filename, const std::string &token)
- {
- resources.push_back(Resource<T>(filename, token));
- }
- template <class T>
- T* ResourceManager<T>::getResource(const std::string &token) const
- {
- if (token != "")
- return resources[token];
- return NULL;
- }
- }
- #endif // RESOURCEMANAGER_H
Add Comment
Please, Sign In to add comment