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