Browse Source

ResourceManager: wrap global instance pointer in a function.

This way only single function can be marked with "extern template" to
avoid nasty issues with multiple definition errors.
pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
124b5b73b6
  1. 21
      src/ResourceManager.h

21
src/ResourceManager.h

@ -453,8 +453,8 @@ template<class... Types> class ResourceManager: protected Implementation::Resour
public: public:
/** @brief Global instance */ /** @brief Global instance */
inline static ResourceManager<Types...>* instance() { inline static ResourceManager<Types...>* instance() {
CORRADE_ASSERT(_instance, "ResourceManager::instance(): no instance exists", nullptr); CORRADE_ASSERT(internalInstance(), "ResourceManager::instance(): no instance exists", nullptr);
return _instance; return internalInstance();
} }
/** /**
@ -466,8 +466,8 @@ template<class... Types> class ResourceManager: protected Implementation::Resour
* @see instance() * @see instance()
*/ */
inline ResourceManager() { inline ResourceManager() {
CORRADE_ASSERT(!_instance, "ResourceManager::ResourceManager(): another instance is already created", ); CORRADE_ASSERT(!internalInstance(), "ResourceManager::ResourceManager(): another instance is already created", );
_instance = this; internalInstance() = this;
} }
/** /**
@ -477,8 +477,8 @@ template<class... Types> class ResourceManager: protected Implementation::Resour
* @see instance() * @see instance()
*/ */
inline ~ResourceManager() { inline ~ResourceManager() {
CORRADE_INTERNAL_ASSERT(_instance == this); CORRADE_INTERNAL_ASSERT(internalInstance() == this);
_instance = nullptr; internalInstance() = nullptr;
} }
/** @brief Count of resources of given type */ /** @brief Count of resources of given type */
@ -564,16 +564,19 @@ template<class... Types> class ResourceManager: protected Implementation::Resour
} }
inline void freeInternal() const {} inline void freeInternal() const {}
static ResourceManager<Types...>* _instance; static ResourceManager<Types...>*& internalInstance();
}; };
template<class ...Types> ResourceManager<Types...>*& ResourceManager<Types...>::internalInstance() {
static ResourceManager<Types...>* _instance(nullptr);
return _instance;
}
/** @debugoperator{Magnum::ResourceKey} */ /** @debugoperator{Magnum::ResourceKey} */
template<class T> inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const ResourceKey& value) { template<class T> inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const ResourceKey& value) {
return debug << static_cast<const Corrade::Utility::HashDigest<sizeof(std::size_t)>&>(value); return debug << static_cast<const Corrade::Utility::HashDigest<sizeof(std::size_t)>&>(value);
} }
template<class ...Types> ResourceManager<Types...>* ResourceManager<Types...>::_instance(nullptr);
} }
#endif #endif

Loading…
Cancel
Save