Carousel
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ServiceLocator Class Reference

The ServiceLocator class provides default implementation of the central registry of the services. More...

#include <ServiceLocator.h>

Inherits IServiceLocator.

Public Member Functions

QObjectbuildObject (const QString &className)
 
QObjectbuildObject (const QString &className, const QString &tag)
 
QObjectlocateToObject (const QString &className)
 
QObjectlocateToObject (const QString &className, const QString &tag)
 
QStringList services () const
 Gets the services, registered with an empty tag. More...
 
QStringList services (const QString &tag) const
 Gets the registered with tag services;. More...
 
- Public Member Functions inherited from IServiceLocator
template<typename TInterface , typename TConcreteClass >
void bindType (const QString &tag)
 
template<typename TInterface , typename TConcreteClass >
void bindType ()
 
template<typename TInterface >
TInterface * buildInstance ()
 
template<typename TInterface >
TInterface * buildInstance (const QString &tag)
 
template<typename TService >
TService * locate ()
 
template<typename TService >
TService * locate (const QString &tag)
 
template<typename TService >
void registerInstance (TService *instance)
 
template<typename TService >
void registerInstance (TService *instance, const QString &tag)
 
template<typename TInterface >
void registerType (factoryMethod method)
 
template<typename TInterface >
void registerType (factoryMethod method, const QString &tag)
 
template<typename TService >
TService * unregisterInstance (const QString &tag)
 
template<typename TService >
TService * unregisterInstance ()
 

Protected Member Functions

void * buildInstanceImpl (const QString &className, const QString &tag)
 
void * getService (const QString &className, const QString &tag)
 
void registerInstanceImpl (void *instance, const QString &className, const QString &tag)
 
void registerTypeImpl (const QString &className, factoryMethod method, const QString &tag)
 
void * unregisterInstanceImpl (const QString &className, const QString &tag)
 

Protected Attributes

TypeObjectsMap< factoryMethod > * m_creators
 
TypeObjectsMap< void * > * m_objects
 

Detailed Description

The ServiceLocator class provides default implementation of the central registry of the services.

It is a utility class and you won't use often in trivial - use IServiceLocator interface instead. The ServiceLocator instance created by default by the BootloaderBase::createServiceLocator() member during the loading sequence, and you should to override this member if you want use your own service locator in the application.

Member Function Documentation

QObject* ServiceLocator::buildObject ( const QString className)
virtual

Creates and returns a className pointer using empty tag and registered factory method, if any. Returns nullptr otherwise. This may be usefull for scpipting, where no templates.

Returns
the corresponding service if such found. Null pointer otherwise.
Note
Does not take ownership of the created pointer.

Implements IServiceLocator.

QObject* ServiceLocator::buildObject ( const QString className,
const QString tag 
)
virtual

Creates and returns a className pointer using specified tag and registered factory method, if any. Returns nullptr otherwise. This may be usefull for scpipting, where no templates.

Returns
the corresponding service if such found. Null pointer otherwise.
Note
Does not take ownership of the created pointer.

Implements IServiceLocator.

QObject* ServiceLocator::locateToObject ( const QString className)
virtual

Finds the service registered with className and empty tag and returns a QObject pointer to it. This may be usefull for scpipting, where no templates.

Returns
the corresponding service if such found. Null pointer otherwis

Implements IServiceLocator.

QObject* ServiceLocator::locateToObject ( const QString className,
const QString tag 
)
virtual

Finds the service registered with className and empty tag and returns a QObject pointer to it. This may be usefull for scpipting, where no templates.

Returns
the corresponding service if such found. Null pointer otherwis

Implements IServiceLocator.

QStringList ServiceLocator::services ( ) const
virtual

Gets the services, registered with an empty tag.

Implements IServiceLocator.

QStringList ServiceLocator::services ( const QString tag) const
virtual

Gets the registered with tag services;.

Implements IServiceLocator.

void* ServiceLocator::buildInstanceImpl ( const QString className,
const QString tag 
)
protectedvirtual

When overridden in derived classes finds the factory method associated with specified type id and specified tag in inner objects dictionary and creates instance of the interface using factory method

Returns
The raw pointer corresponded with specified interface id and tag if such found. Null pointer otherwise.

Implements IServiceLocator.

void* ServiceLocator::getService ( const QString className,
const QString tag 
)
protectedvirtual

Finds the pointer associated with specified type id and specified tag in inner objects dictionary.

Returns
The raw pointer corresponded with specified type id and tag if such found. Null pointer otherwise.

Implements IServiceLocator.

void ServiceLocator::registerInstanceImpl ( void *  instance,
const QString className,
const QString tag 
)
protectedvirtual

Registers a raw pointer with specified tag in inner objects dictionary.

Parameters
classNameThe name of type which instance should be associated with.

Implements IServiceLocator.

void ServiceLocator::registerTypeImpl ( const QString className,
factoryMethod  method,
const QString tag 
)
protectedvirtual

Binds an interface type id with specified factory method (that should create instance of interface) and with specified tag in inner objects dictionary.

Parameters
classNameThe name of type which factory method should be associated with.

Implements IServiceLocator.

void* ServiceLocator::unregisterInstanceImpl ( const QString className,
const QString tag 
)
protectedvirtual

When overridden in derived classes unregisters (removes) a service instance with specified type id and tag from the inner objects dictionary (if any).

Parameters
classNameThe name of type which removed instance should be associated with.
Returns
The raw pointer corresponded with specified type id and tag if such found. Null pointer otherwise.

Implements IServiceLocator.