|
Nuria Framework - Core
Core module of the NuriaProject Framework
|
DepedencyManager enables easy to use dependency injection. More...
#include <dependencymanager.hpp>
Public Types | |
| enum | ThreadingPolicy { DefaultPolicy, ApplicationGlobal, SingleThread, ThreadLocal } |
Public Member Functions | |
| ~DependencyManager () | |
| ThreadingPolicy | defaultThreadingPolicy () const |
| void | setDefaultThreadingPolicy (ThreadingPolicy policy) |
| void * | objectByName (const QString &name, int type=-1, ThreadingPolicy policy=DefaultPolicy) |
| int | objectType (const QString &name, ThreadingPolicy policy=DefaultPolicy) const |
| bool | hasObject (const QString &name, ThreadingPolicy policy=DefaultPolicy) const |
| void | storeObject (const QString &name, void *object, int type, ThreadingPolicy policy=DefaultPolicy) |
| template<typename T > | |
| void | storeObject (const QString &name, T *object) |
Static Public Member Functions | |
| static DependencyManager * | instance () |
| template<typename T > | |
| static T * | get (const QString &name, ThreadingPolicy policy=DefaultPolicy) |
DepedencyManager enables easy to use dependency injection.
Dependency injection is interesting whenever a class has dependencies to other utility classes. Those classes usually only have a single application-wide instance, thus those are often implemented as singletons. While using singletons is mostly easy to do, it has also its flaws:
This line should come right after the class definition. Please note that the macro itself must be invoked on the global scope.
After this, you can start using it right away with the NURIA_DEPENDENCY macro: MyType *myType = NURIA_DEPENDENCY(MyType)
Behaviours for multi-threaded applications.
| Nuria::DependencyManager::~DependencyManager | ( | ) |
Destructor.
| ThreadingPolicy Nuria::DependencyManager::defaultThreadingPolicy | ( | ) | const |
Returns the current default threading policy.
|
inlinestatic |
Tries to find object name of type T. On failure, nullptr is returned.
|
inline |
Returns true if there is object name.
|
static |
Returns the global instance of the manager.
| void* Nuria::DependencyManager::objectByName | ( | const QString & | name, |
| int | type = -1, |
||
| ThreadingPolicy | policy = DefaultPolicy |
||
| ) |
Returns object name. If type is not -1 and name wasn't created yet, it will be created then, stored and returned. Else, nullptr is returned.
-1, it will be used as type check. If type and the type of object name don't match, nullptr is returned.| int Nuria::DependencyManager::objectType | ( | const QString & | name, |
| ThreadingPolicy | policy = DefaultPolicy |
||
| ) | const |
Returns the meta type of object name or -1 if not found.
| void Nuria::DependencyManager::setDefaultThreadingPolicy | ( | ThreadingPolicy | policy | ) |
Sets the default threading policy. Passing DefaultPolicy has no effect. Changing the policy is not thread-safe.
| void Nuria::DependencyManager::storeObject | ( | const QString & | name, |
| void * | object, | ||
| int | type, | ||
| ThreadingPolicy | policy = DefaultPolicy |
||
| ) |
Stores object of type as name. If there is already a object of the same name, it will be overwritten. object must be a registered type.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
1.8.7