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