17 #ifndef NURIA_DEPEDENCYMANAGER_HPP
18 #define NURIA_DEPEDENCYMANAGER_HPP
20 #include "essentials.hpp"
25 class DependencyManagerPrivate;
133 ThreadingPolicy defaultThreadingPolicy ()
const;
141 void setDefaultThreadingPolicy (ThreadingPolicy policy);
155 void *objectByName (
const QByteArray &name,
int type = -1, ThreadingPolicy policy = DefaultPolicy);
160 int objectType (
const QByteArray &name, ThreadingPolicy policy = DefaultPolicy)
const;
166 {
return objectType (name, policy) != -1; }
175 void storeObject (
const QByteArray &name,
void *
object,
int type,
176 ThreadingPolicy policy = DefaultPolicy);
179 template<
typename T >
181 { storeObject (name,
object, qMetaTypeId< T * > ()); }
194 void setCreator (
const QByteArray &name,
const std::function< QObject *() > &creator);
200 template<
typename T >
201 inline static T *
get (
const QByteArray &name,
ThreadingPolicy policy = DefaultPolicy) {
202 return static_cast< T *
> (instance ()->objectByName (name, qMetaTypeId< T * > (), policy));
207 void freeAllObjects ();
212 DependencyManagerPrivate *d_ptr;
251 template<
typename T >
253 mutable T *m_obj =
nullptr;
262 : m_name (objectName)
264 if (objectName.isEmpty ()) {
265 const char *name = QMetaType::typeName (qMetaTypeId< T * > ());
266 this->m_name.setRawData (name, ::qstrlen (name) - 1);
273 {
return (this->m_name == other.m_name); }
277 {
return (this->m_name != other.m_name); }
280 operator bool ()
const
281 {
return (
get () !=
nullptr); }
293 this->m_obj = DependencyManager::get< T > (this->m_name);
303 #endif // NURIA_DEPEDENCYMANAGER_HPP
Definition: dependencymanager.hpp:104
bool hasObject(const QByteArray &name, ThreadingPolicy policy=DefaultPolicy) const
Definition: dependencymanager.hpp:165
void storeObject(const QByteArray &name, T *object)
Definition: dependencymanager.hpp:180
bool operator==(const Dependency< T > &other) const
Definition: dependencymanager.hpp:272
bool operator!=(const Dependency< T > &other) const
Definition: dependencymanager.hpp:276
Smart pointer class for dependency injection.
Definition: dependencymanager.hpp:252
Definition: abstractsessionmanager.hpp:24
Dependency(const QByteArray &objectName=QByteArray())
Definition: dependencymanager.hpp:261
Dependency injection manager.
Definition: dependencymanager.hpp:86
T * operator->() const
Definition: dependencymanager.hpp:284
Definition: dependencymanager.hpp:110
ThreadingPolicy
Definition: dependencymanager.hpp:94
Definition: dependencymanager.hpp:98