From 1809107ff2e174b77b5613d17577925f136e6c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 18 Nov 2012 19:33:34 +0100 Subject: [PATCH] Resource: assert when accessing not loaded data. --- src/ResourceManager.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 19147bb11..bae717ad6 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -333,22 +333,30 @@ template class Resource { 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(); - return *static_cast(data); + CORRADE_ASSERT(data, "Resource: accessing not loaded data with key" << key(), nullptr); + return static_cast(data); } - /** @brief %Resource data */ + /** @overload */ inline U* operator->() { acquire(); + CORRADE_ASSERT(data, "Resource: accessing not loaded data with key" << key(), nullptr); return static_cast(data); } - /** @brief %Resource data */ - inline operator U*() { + /** @overload */ + inline U& operator*() { acquire(); - return static_cast(data); + CORRADE_ASSERT(data, "Resource: accessing not loaded data with key" << key(), *static_cast(data)); + return *static_cast(data); } private: