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