eVaf
eVaf::Common::iRegistry Class Referenceabstract

Common registry for interfaces. More...

#include <Common/iregistry.h>

Public Member Functions

 iRegistry ()
 Interface constructor. More...
 
virtual QObjectqueryInterface (QString const &name) const =0
 Returns the interface by its name. More...
 
virtual bool registerInterface (QString const &name, QObject *obj)=0
 Registers an interface. More...
 
virtual ~iRegistry ()
 Empty virtual destructor. More...
 

Static Public Member Functions

static iRegistryinstance ()
 Returns the iRegistry interface instance. More...
 

Detailed Description

Common registry for interfaces.

#include <Common/iRegistry>

Registry is a central collection of all the eVaf interfaces and iRegistry the interface for it. Modules use the iRegistry interface to register new interfaces and query existing ones.

Existing interfaces are queried with the queryInterface() function. The returned pointer to QObject shall be type casted to the requested interface class using qobject_cast<>():

iEnv * env = qobject_cast<iEnv *>(iRegistry::instance()->queryInterface("iEnv"));

Or use the evafQueryInterface<>() function:

iEnv * env = evafQueryInterface<iEnv>("iEnv");

Registering new interfaces is done with the registerInterface() function as shown in the following example:

In general, every interface should have a unique name. If an interface is registered with a name that already exists, then the new interface overwrites the old interface with the same name. To reimplement an interface, query for the old implementation, store it and then register a new interface with the same name.

Any class implementing an interface shall have QObject as their top-most parent.

iRegistry and instance() functions

Most of the interfaces have the instance() function that returns the current instance of the interface. The main difference is that by using the instance() function, modules shall link against the module that implements the interface's instance() function. The iRegistry interface can be used to get the same interface without knowing the module that implements it.

Definition at line 67 of file iregistry.h.

Constructor & Destructor Documentation

eVaf::Common::iRegistry::iRegistry ( )
inline

Interface constructor.

Definition at line 74 of file iregistry.h.

virtual eVaf::Common::iRegistry::~iRegistry ( )
inlinevirtual

Empty virtual destructor.

Definition at line 77 of file iregistry.h.

Member Function Documentation

static iRegistry* eVaf::Common::iRegistry::instance ( )
static

Returns the iRegistry interface instance.

Returns
The iRegistry interface

This function returns the global iRegistry interface instance. All eVaf modules and applications are expected to be linked against the common library and this is the only method of obtaining the iRegistry interface.

virtual QObject* eVaf::Common::iRegistry::queryInterface ( QString const &  name) const
pure virtual

Returns the interface by its name.

Parameters
nameName of the interface
Returns
Interface implementation or NULL if not found.

This function queries the global registry for the interface by its name. It returns a pointer to the implementation of the interface or NULL if no such interface is found.

Use the qobject_cast<>() function to type cast the returned pointer to the required interface class. Always check for NULL in case there is a mismatch in interface versions or no such interface is found.

Implemented in eVaf::Common::Internal::Registry.

virtual bool eVaf::Common::iRegistry::registerInterface ( QString const &  name,
QObject obj 
)
pure virtual

Registers an interface.

Parameters
nameName of the interface
objObject implementing the interface
Returns
True if ok; false if registering failed

This function registers a new interface in the global registry of interfaces.

If an interface with this name already exists, then the new interface implementation overwrites the old implementation.

Implemented in eVaf::Common::Internal::Registry.


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