All resources are derived from this type. The base type is only instantiated by the resource manager (the resource manager will return a base resource which a derived resource, Resource , will construct itself with). Base class handles locking and unlocking and provides several virtual functions to be defined by derived resource.
| 82 | // provides several virtual functions to be defined by |
| 83 | // derived resource. |
| 84 | class ResourceBase |
| 85 | { |
| 86 | friend class ResourceManager; |
| 87 | |
| 88 | protected: |
| 89 | class Header; |
| 90 | |
| 91 | public: |
| 92 | typedef U32 Signature; |
| 93 | |
| 94 | public: |
| 95 | ResourceBase(Header *header) { mResourceHeader = (header ? header : &smBlank); } |
| 96 | virtual ~ResourceBase() {} |
| 97 | |
| 98 | const Torque::Path &getPath() const |
| 99 | { |
| 100 | AssertFatal(mResourceHeader != NULL,"ResourceBase::getPath called on invalid resource"); |
| 101 | return mResourceHeader->getPath(); |
| 102 | } |
| 103 | |
| 104 | U32 getChecksum() const |
| 105 | { |
| 106 | AssertFatal(mResourceHeader != NULL,"ResourceBase::getChecksum called on invalid resource"); |
| 107 | return mResourceHeader->getChecksum(); |
| 108 | } |
| 109 | |
| 110 | protected: |
| 111 | |
| 112 | typedef void ( *NotifyUnloadFn )( const Torque::Path& path, void* resource ); |
| 113 | |
| 114 | class Header : public StrongRefBase |
| 115 | { |
| 116 | public: |
| 117 | Header() |
| 118 | : mSignature(0), |
| 119 | mResource(NULL), |
| 120 | mNotifyUnload( NULL ) |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | const Torque::Path &getPath() const { return mPath; } |
| 125 | |
| 126 | Signature getSignature() const { return mSignature; } |
| 127 | void *getResource() const { return (mResource ? mResource->getResource() : NULL); } |
| 128 | U32 getChecksum() const; |
| 129 | |
| 130 | virtual void destroySelf(); |
| 131 | |
| 132 | private: |
| 133 | |
| 134 | friend class ResourceBase; |
| 135 | friend class ResourceManager; |
| 136 | |
| 137 | Signature mSignature; |
| 138 | ResourceHolderBase* mResource; |
| 139 | Torque::Path mPath; |
| 140 | NotifyUnloadFn mNotifyUnload; |
| 141 | }; |
no test coverage detected