[4838] | 1 | /*! |
---|
[7193] | 2 | * @file resource.h |
---|
[7195] | 3 | * @brief Definition of a Resource. |
---|
[3245] | 4 | */ |
---|
[1853] | 5 | |
---|
[7193] | 6 | #ifndef _RESOURCE_H |
---|
| 7 | #define _RESOURCE_H |
---|
[1853] | 8 | |
---|
[3543] | 9 | #include "base_object.h" |
---|
[7193] | 10 | #include "multi_type.h" |
---|
[7195] | 11 | #include <string> |
---|
[9714] | 12 | #include <vector> |
---|
| 13 | #include <set> |
---|
[1853] | 14 | |
---|
[9785] | 15 | #include "filesys/directory.h" |
---|
| 16 | |
---|
[9714] | 17 | //! A Resource is an Object, that can be loaded from Disk |
---|
[7195] | 18 | /** |
---|
[9714] | 19 | * |
---|
[7195] | 20 | */ |
---|
[9714] | 21 | class Resource : virtual public BaseObject |
---|
[7195] | 22 | { |
---|
[9718] | 23 | ObjectListDeclaration(Resource); |
---|
[9714] | 24 | public: |
---|
[9718] | 25 | class KeepLevel |
---|
[9714] | 26 | { |
---|
| 27 | public: |
---|
[9783] | 28 | void setKeepLevelName(unsigned int level, const std::string& name); |
---|
[9714] | 29 | private: |
---|
[9718] | 30 | std::vector<std::string> _keepLevelName; |
---|
[9714] | 31 | }; |
---|
[7195] | 32 | |
---|
[9783] | 33 | protected: |
---|
[9714] | 34 | class Type |
---|
| 35 | { |
---|
| 36 | public: |
---|
[9783] | 37 | Type(const ClassID& classID) : _id(-1), _classID(classID) { }; |
---|
[7195] | 38 | |
---|
[9714] | 39 | void addExtension(const std::string& extension); |
---|
[1853] | 40 | |
---|
[9784] | 41 | void addResourcePath(const std::string& path); |
---|
| 42 | void addResourceSubPath(const std::string& subPath); |
---|
| 43 | |
---|
| 44 | /// Retrieve Functions |
---|
[9783] | 45 | const ClassID& storedClassID() const { return _classID; }; |
---|
| 46 | int id() const { return _id; }; |
---|
| 47 | const std::vector<std::string>& resourcePaths() const { return _resourcePaths; }; |
---|
[9784] | 48 | const std::vector<std::string>& resourceSubPaths() const { return _resourceSubPaths; }; |
---|
| 49 | const std::vector<Resource*>& storedResources() const { return _storedResources; }; |
---|
[9783] | 50 | |
---|
| 51 | void setID(int id); |
---|
[9785] | 52 | void addResource(Resource* resource); |
---|
[9783] | 53 | |
---|
[9714] | 54 | private: |
---|
[9783] | 55 | int _id; |
---|
[9715] | 56 | const ClassID& _classID; |
---|
[9714] | 57 | std::vector<std::string> _resourcePaths; |
---|
| 58 | std::vector<std::string> _resourceSubPaths; |
---|
| 59 | std::vector<std::string> _fileExtensions; |
---|
[9784] | 60 | |
---|
| 61 | std::vector<Resource*> _storedResources; |
---|
[9714] | 62 | }; |
---|
| 63 | |
---|
[9784] | 64 | class Pointer |
---|
| 65 | { |
---|
| 66 | public: |
---|
| 67 | Pointer(const std::string& loadString, const Resource::KeepLevel& keeplevel); |
---|
| 68 | const std::string& loadString() const { return _loadString; }; |
---|
| 69 | const Resource::KeepLevel& keepLevel() const { return _keepLevel; }; |
---|
[9758] | 70 | |
---|
[9784] | 71 | private: |
---|
| 72 | std::string _loadString; //!< An identifier, to match when loading a File. |
---|
| 73 | Resource::KeepLevel _keepLevel; //!< The Priority of this resource. (can only be increased, so none else will delete this) |
---|
| 74 | }; |
---|
[9758] | 75 | |
---|
[9784] | 76 | |
---|
[9714] | 77 | public: |
---|
[9785] | 78 | Resource(Resource::Type* type); |
---|
[7193] | 79 | virtual ~Resource(); |
---|
[1853] | 80 | |
---|
[9785] | 81 | virtual bool reload() { return false; }; |
---|
| 82 | virtual bool unload() { return false; }; |
---|
[3245] | 83 | |
---|
[9785] | 84 | std::string locateFile(const std::string& fileName); |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | public: |
---|
| 88 | static void setMainGlobalPath(const Directory& directory); |
---|
| 89 | static void addGlobalPath(const Directory& directory); |
---|
| 90 | |
---|
| 91 | |
---|
[9784] | 92 | protected: |
---|
[9785] | 93 | Resource::Pointer* acquireResource(const std::string& loadString); |
---|
| 94 | void addResource(Resource::Pointer* pointer); |
---|
[3245] | 95 | |
---|
[9714] | 96 | private: |
---|
[9784] | 97 | Resource::Pointer* _pointer; //!< Virtual Pointer to the ResourceData. |
---|
[9785] | 98 | Resource::Type* _type; //!< Type of the Resource. |
---|
[7195] | 99 | |
---|
[9714] | 100 | |
---|
[9784] | 101 | static std::vector<Resource::Type*> _resourceTypes; |
---|
[9714] | 102 | |
---|
| 103 | //! GLOBALS |
---|
[9785] | 104 | static Directory _mainGlobalPath; |
---|
| 105 | static std::vector<Directory> _globalPaths; |
---|
[1853] | 106 | }; |
---|
| 107 | |
---|
[7193] | 108 | #endif /* _RESOURCE_H */ |
---|