NuriaProject Framework  0.1
The NuriaProject Framework
Public Member Functions | List of all members
Nuria::Dependency< T > Class Template Reference

Smart pointer class for dependency injection. More...

#include <dependencymanager.hpp>

Public Member Functions

 Dependency (const QByteArray &objectName=QByteArray())
 
T * get () const
 
 operator bool () const
 
bool operator!= (const Dependency< T > &other) const
 
T * operator-> () const
 
bool operator== (const Dependency< T > &other) const
 

Detailed Description

template<typename T>
class Nuria::Dependency< T >

Smart pointer class for dependency injection.

Smart pointer which lazy-loads a referenced dependency from DependencyManager.

Usage

For objects with the default name, it's sufficient to use the default constructor:

Dependency< MyType > myType;

If you're using a different object name, you can pass it:

Dependency< MyType > myType (QByteArrayLiteral("someType"));

To access the instance, use operator-> as you'd any other pointer:

Dependency< MyType > myType;
myType->doSomething ();
See also
DependencyManager
Comparison operators

Dependency offers operators for equality (==) and inequality (!=). Both operators only compare the object name.

A operator for implicit conversion to bool is offered for compatibility with raw pointers. This operator fetches the instance (If not already done) and returns true, if the instance is not nullptr.

Constructor & Destructor Documentation

template<typename T>
Nuria::Dependency< T >::Dependency ( const QByteArray &  objectName = QByteArray ())
inline

Constructor. Takes an optional argument objectName. If not set, the name of the type of T is used.

Member Function Documentation

template<typename T>
T* Nuria::Dependency< T >::get ( ) const
inline

Returns the referenced instance. On first invocation, it will be fetched from the DependencyManager.

template<typename T>
Nuria::Dependency< T >::operator bool ( ) const
inline

Raw-pointer compatibility bool operator.

template<typename T>
bool Nuria::Dependency< T >::operator!= ( const Dependency< T > &  other) const
inline

Inequality operator.

template<typename T>
T* Nuria::Dependency< T >::operator-> ( ) const
inline

Convenience accessor. See get().

template<typename T>
bool Nuria::Dependency< T >::operator== ( const Dependency< T > &  other) const
inline

Equality operator.


The documentation for this class was generated from the following file: