Browse Source

Resource: assert when accessing not loaded data.

pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
1809107ff2
  1. 22
      src/ResourceManager.h

22
src/ResourceManager.h

@ -333,22 +333,30 @@ template<class T, class U = T> class Resource {
return data; return data;
} }
/** @brief %Resource data */ /**
inline U& operator*() { * @brief %Resource data
*
* The resource must be loaded before accessing it. Use boolean
* conversion operator or state() for testing whether it is loaded.
*/
inline operator U*() {
acquire(); acquire();
return *static_cast<U*>(data); CORRADE_ASSERT(data, "Resource: accessing not loaded data with key" << key(), nullptr);
return static_cast<U*>(data);
} }
/** @brief %Resource data */ /** @overload */
inline U* operator->() { inline U* operator->() {
acquire(); acquire();
CORRADE_ASSERT(data, "Resource: accessing not loaded data with key" << key(), nullptr);
return static_cast<U*>(data); return static_cast<U*>(data);
} }
/** @brief %Resource data */ /** @overload */
inline operator U*() { inline U& operator*() {
acquire(); acquire();
return static_cast<U*>(data); CORRADE_ASSERT(data, "Resource: accessing not loaded data with key" << key(), *static_cast<U*>(data));
return *static_cast<U*>(data);
} }
private: private:

Loading…
Cancel
Save