eVaf
|
Common registry for interfaces. More...
#include <Common/iregistry.h>
Public Member Functions | |
iRegistry () | |
Interface constructor. More... | |
virtual QObject * | queryInterface (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 iRegistry * | instance () |
Returns the iRegistry interface instance. More... | |
Common registry for interfaces.
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<>():
Or use the evafQueryInterface<>() function:
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.
|
inline |
Interface constructor.
Definition at line 74 of file iregistry.h.
|
inlinevirtual |
Empty virtual destructor.
Definition at line 77 of file iregistry.h.
|
static |
|
pure virtual |
Returns the interface by its name.
name | Name of the interface |
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.
|
pure virtual |
Registers an interface.
name | Name of the interface |
obj | Object implementing the interface |
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.