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