A factory class which can produce class instances through registered factory interfaces.
More...
#include <Factory.h>
List of all members.
Public Member Functions |
QtilitiesCategory | categoryForTag (const QString &tag) const |
| Function which returns the category under which the specified tag was registered.
|
BaseClass * | createInstance (const QString &tag) |
| Creates an instance of the factory interface implementation registered with the specified tag. If an invalid tag is specified, null will be returned.
|
bool | isTagValid (const QString &tag) const |
| Function which verifies the validity of a new tag. If the tag is already present, false is returned.
|
bool | registerFactoryInterface (FactoryInterface< BaseClass > *factory_interface, FactoryItemID iface_data) |
| Registers a new factory interface implementation. The string 'factory_tag' can be used to generate instances of this implementation.
|
QMap< QString, QtilitiesCategory > | tagCategoryMap () const |
| Returns a tag-category map of registered tags.
|
QStringList | tags (const QtilitiesCategory &category_filter=QtilitiesCategory()) const |
| Returns a list of registered tags for a given context. By default all contexts are returned.
|
void | unregisterFactoryInterface (const QString &tag) |
| Unregister a factory interface implementation.
|
Detailed Description
template<class BaseClass>
class Qtilities::Core::Factory< BaseClass >
A factory class which can produce class instances through registered factory interfaces.
The Qtilities::Core::Factory class is a template based Qt implementation of the factory programming pattern. The class allows you to register factory interfaces, defined by the Qtilities::Core::FactoryInterface class. New instances of factory items (defined by Qtilities::Core::FactoryItem) can then be created by only providing the factory with the needed interface ID defined by Qtilities::Core::FactoryItemID.
For more information see the Factories article.
- See also:
- FactoryInterface, FactoryItem, Interfaces::IFactoryProvider
Member Function Documentation
template<class BaseClass >
Function which returns the category under which the specified tag was registered.
This function was added in Qtilities v1.2.
template<class BaseClass >
Registers a new factory interface implementation. The string 'factory_tag' can be used to generate instances of this implementation.
- Parameters:
-
factory_interface | The factory item interface. |
iface_data | A structure providing information about the factory item interface. If another item interface with the same tag already exists, the function call will fail and false will be returned. The tag must also contain a value. |
- Returns:
- True if the interface was registered successfully, false otherwise.
template<class BaseClass >
Returns a list of registered tags for a given context. By default all contexts are returned.
- Parameters:
-
category_filter | When a valid category is provided, only tags in that category are returned. |
- See also:
- tagCategoryMap()