mirror of
https://github.com/overte-org/overte.git
synced 2025-04-12 14:42:11 +02:00
Couple improvements to the dependency manager
This commit is contained in:
parent
14cda00ebc
commit
50fd52377f
2 changed files with 12 additions and 11 deletions
|
@ -16,17 +16,10 @@ DependencyManager& DependencyManager::getInstance() {
|
|||
return instance;
|
||||
}
|
||||
|
||||
DependencyManager::DependencyManager() {
|
||||
// Guard against request of ourself
|
||||
// We could set the value to this, but since it doesn't make sense to access
|
||||
// the DependencyManager instance from the outside let's set it to NULL
|
||||
_instanceHash.insert(typeid(DependencyManager).name(), NULL);
|
||||
}
|
||||
|
||||
DependencyManager::~DependencyManager() {
|
||||
foreach (Dependency* instance, _instanceHash) {
|
||||
if (instance) {
|
||||
instance->deleteInstance();
|
||||
delete instance;
|
||||
}
|
||||
}
|
||||
_instanceHash.clear();
|
||||
|
|
|
@ -19,16 +19,24 @@
|
|||
|
||||
class DependencyManager {
|
||||
public:
|
||||
// Only accessible method.
|
||||
// usage: T* instance = DependencyManager::get<T>();
|
||||
template<typename T>
|
||||
static T* get();
|
||||
|
||||
// Any class T in the DependencyManager needs to subclass Dependency
|
||||
// They also need to have protected constructor(s) and virtual destructor
|
||||
// As well as declare DependencyManager a friend class
|
||||
class Dependency {
|
||||
virtual void deleteInstance() = 0;
|
||||
protected:
|
||||
Dependency() {}
|
||||
virtual ~Dependency() {} // Ensure the proper destruction of the object
|
||||
friend DependencyManager;
|
||||
};
|
||||
|
||||
private:
|
||||
static DependencyManager& getInstance();
|
||||
DependencyManager();
|
||||
DependencyManager() {}
|
||||
~DependencyManager();
|
||||
|
||||
typedef QHash<QString, Dependency*> InstanceHash;
|
||||
|
@ -52,4 +60,4 @@ T* DependencyManager::get() {
|
|||
return newInstance;
|
||||
}
|
||||
|
||||
#endif // hifi_DependencyManager_h
|
||||
#endif // hifi_DependencyManager_h
|
||||
|
|
Loading…
Reference in a new issue