Mantid
|
The dynamic factory is a base dynamic factory for serving up objects in response to requests from other classes. More...
#include <Kernel/DynamicFactory.h>
Classes | |
class | DynamicFactoryNotification |
Base class for dynamic factory notifications. More... | |
class | UpdateNotification |
A notification that the factory has been updated. More... | |
Public Types | |
using | AbstractFactory = AbstractInstantiator< Base > |
A typedef for the instantiator. More... | |
enum | NotificationStatus { Enabled , Disabled } |
Defines the whether notifications are dispatched. More... | |
enum | SubscribeAction { ErrorIfExists , OverwriteCurrent } |
Defines replacement behaviour. More... | |
Public Member Functions | |
virtual std::shared_ptr< Base > | create (const std::string &className) const |
Creates a new instance of the class with the given name. More... | |
virtual Base * | createUnwrapped (const std::string &className) const |
Creates a new instance of the class with the given name, which is not wrapped in a boost shared_ptr. More... | |
void | disableNotifications () |
Disable notifications. More... | |
DynamicFactory (const DynamicFactory &)=delete | |
void | enableNotifications () |
Enable notifications. More... | |
bool | exists (const std::string &className) const |
Returns true if the given class is currently registered. More... | |
virtual const std::vector< std::string > | getKeys () const |
Returns the keys in the map. More... | |
DynamicFactory & | operator= (const DynamicFactory &)=delete |
template<class C > | |
void | subscribe (const std::string &className) |
Registers the instantiator for the given class with the DynamicFactory. More... | |
void | subscribe (const std::string &className, std::unique_ptr< AbstractFactory > pAbstractFactory, SubscribeAction replace=ErrorIfExists) |
Registers the instantiator for the given class with the DynamicFactory. More... | |
void | unsubscribe (const std::string &className) |
Unregisters the given class and deletes the instantiator for the class. More... | |
virtual | ~DynamicFactory ()=default |
Destroys the DynamicFactory and deletes the instantiators for all registered classes. More... | |
Public Attributes | |
Poco::NotificationCenter | notificationCenter |
Sends notifications to observers. More... | |
Protected Member Functions | |
DynamicFactory () | |
Protected constructor for base class. More... | |
Private Types | |
using | FactoryMap = std::map< std::string, std::unique_ptr< AbstractFactory >, Comparator > |
A typedef for the map of registered classes. More... | |
Private Member Functions | |
void | sendUpdateNotification () |
Send an update notification. More... | |
void | sendUpdateNotificationIfEnabled () |
Send an update notification if they are enabled. More... | |
Private Attributes | |
FactoryMap | _map |
The map holding the registered class names and their instantiators. More... | |
NotificationStatus | m_notifyStatus |
Flag marking whether we should dispatch notifications. More... | |
The dynamic factory is a base dynamic factory for serving up objects in response to requests from other classes.
Definition at line 47 of file DynamicFactory.h.
using Mantid::Kernel::DynamicFactory< Base, Comparator >::AbstractFactory = AbstractInstantiator<Base> |
A typedef for the instantiator.
Definition at line 78 of file DynamicFactory.h.
|
private |
A typedef for the map of registered classes.
Definition at line 200 of file DynamicFactory.h.
enum Mantid::Kernel::DynamicFactory::NotificationStatus |
Defines the whether notifications are dispatched.
Enumerator | |
---|---|
Enabled | |
Disabled |
Definition at line 51 of file DynamicFactory.h.
enum Mantid::Kernel::DynamicFactory::SubscribeAction |
Defines replacement behaviour.
Enumerator | |
---|---|
ErrorIfExists | |
OverwriteCurrent |
Definition at line 53 of file DynamicFactory.h.
|
delete |
|
virtualdefault |
Destroys the DynamicFactory and deletes the instantiators for all registered classes.
|
inlineprotected |
Protected constructor for base class.
Definition at line 188 of file DynamicFactory.h.
|
inlinevirtual |
Creates a new instance of the class with the given name.
The class must have been registered with subscribe() (typically done via a macro). If the class name is unknown, a NotFoundException is thrown.
className | :: the name of the class you wish to create |
Reimplemented in Mantid::API::ImplicitFunctionFactoryImpl, Mantid::MDAlgorithms::MDTransfFactoryImpl, Mantid::API::ColumnFactoryImpl, Mantid::API::TransformScaleFactoryImpl, Mantid::API::ImplicitFunctionParameterParserFactoryImpl, and Mantid::API::ImplicitFunctionParserFactoryImpl.
Definition at line 89 of file DynamicFactory.h.
References Mantid::Kernel::DynamicFactory< Base, Comparator >::_map.
Referenced by Mantid::API::LiveListenerFactoryImpl::create(), Mantid::MDAlgorithms::MDTransfFactoryImpl::create(), Mantid::API::ColumnFactoryImpl::create(), Mantid::API::TransformScaleFactoryImpl::create(), and Mantid::API::AlgorithmFactoryImpl::createAlgorithm().
|
inlinevirtual |
Creates a new instance of the class with the given name, which is not wrapped in a boost shared_ptr.
This should be used with extreme care (or, better, not used)! The caller owns the returned instance. The class must have been registered with subscribe() (typically done via a macro). If the class name is unknown, a NotFoundException is thrown.
className | :: the name of the class you wish to create |
Reimplemented in Mantid::API::LiveListenerFactoryImpl, Mantid::API::TransformScaleFactoryImpl, MantidQt::API::UserSubWindowFactoryImpl, and Mantid::API::ImplicitFunctionFactoryImpl.
Definition at line 106 of file DynamicFactory.h.
References Mantid::Kernel::DynamicFactory< Base, Comparator >::_map.
Referenced by MantidQt::API::UserSubWindowFactoryImpl::createUnwrapped().
|
inline |
Disable notifications.
Definition at line 75 of file DynamicFactory.h.
References Mantid::Kernel::DynamicFactory< Base, Comparator >::Disabled, and Mantid::Kernel::DynamicFactory< Base, Comparator >::m_notifyStatus.
|
inline |
Enable notifications.
Definition at line 70 of file DynamicFactory.h.
References Mantid::Kernel::DynamicFactory< Base, Comparator >::Enabled, and Mantid::Kernel::DynamicFactory< Base, Comparator >::m_notifyStatus.
|
inline |
Returns true if the given class is currently registered.
className | :: the name of the class you wish to check |
Definition at line 167 of file DynamicFactory.h.
References Mantid::Kernel::DynamicFactory< Base, Comparator >::_map.
Referenced by Mantid::API::AlgorithmFactoryImpl::exists().
|
inlinevirtual |
Returns the keys in the map.
Reimplemented in Mantid::API::AlgorithmFactoryImpl.
Definition at line 171 of file DynamicFactory.h.
References Mantid::Kernel::DynamicFactory< Base, Comparator >::_map.
Referenced by Mantid::API::AlgorithmFactoryImpl::getKeys().
|
delete |
|
inlineprivate |
Send an update notification.
Definition at line 197 of file DynamicFactory.h.
References Mantid::Kernel::DynamicFactory< Base, Comparator >::notificationCenter.
Referenced by Mantid::Kernel::DynamicFactory< Base, Comparator >::sendUpdateNotificationIfEnabled().
|
inlineprivate |
Send an update notification if they are enabled.
Definition at line 192 of file DynamicFactory.h.
References Mantid::Kernel::DynamicFactory< Base, Comparator >::Enabled, Mantid::Kernel::DynamicFactory< Base, Comparator >::m_notifyStatus, and Mantid::Kernel::DynamicFactory< Base, Comparator >::sendUpdateNotification().
Referenced by Mantid::Kernel::DynamicFactory< Base, Comparator >::subscribe(), and Mantid::Kernel::DynamicFactory< Base, Comparator >::unsubscribe().
|
inline |
Registers the instantiator for the given class with the DynamicFactory.
The DynamicFactory takes ownership of the instantiator and deletes it when it's no longer used. If the class has already been registered, an ExistsException is thrown and the instantiator is deleted.
className | :: the name of the class you wish to subscribe |
Definition at line 120 of file DynamicFactory.h.
References Mantid::Kernel::DynamicFactory< Base, Comparator >::subscribe().
Referenced by Mantid::Kernel::DynamicFactory< Base, Comparator >::subscribe(), and Mantid::API::FunctionFactoryImpl::subscribe().
|
inline |
Registers the instantiator for the given class with the DynamicFactory.
The DynamicFactory takes ownership of the instantiator and deletes it when it's no longer used. If the class has already been registered, an ExistsException is thrown and the instantiator is deleted.
className | :: the name of the class you wish to subscribe |
pAbstractFactory | :: A pointer to an abstractFactory for this class |
replace | :: If ReplaceExisting then the given AbstractFactory replaces any existing factory with the same className, else throws std::runtime_error (default=ThrowOnExisting) |
Definition at line 135 of file DynamicFactory.h.
References Mantid::Kernel::DynamicFactory< Base, Comparator >::_map, Mantid::Kernel::DynamicFactory< Base, Comparator >::OverwriteCurrent, and Mantid::Kernel::DynamicFactory< Base, Comparator >::sendUpdateNotificationIfEnabled().
|
inline |
Unregisters the given class and deletes the instantiator for the class.
Throws a NotFoundException if the class has not been registered.
className | :: the name of the class you wish to unsubscribe |
Definition at line 154 of file DynamicFactory.h.
References Mantid::Kernel::DynamicFactory< Base, Comparator >::_map, and Mantid::Kernel::DynamicFactory< Base, Comparator >::sendUpdateNotificationIfEnabled().
Referenced by Mantid::API::AlgorithmFactoryImpl::unsubscribe(), and Mantid::API::FunctionFactoryImpl::unsubscribe().
|
private |
The map holding the registered class names and their instantiators.
Definition at line 202 of file DynamicFactory.h.
Referenced by Mantid::Kernel::DynamicFactory< Base, Comparator >::create(), Mantid::Kernel::DynamicFactory< Base, Comparator >::createUnwrapped(), Mantid::Kernel::DynamicFactory< Base, Comparator >::exists(), Mantid::Kernel::DynamicFactory< Base, Comparator >::getKeys(), Mantid::Kernel::DynamicFactory< Base, Comparator >::subscribe(), and Mantid::Kernel::DynamicFactory< Base, Comparator >::unsubscribe().
|
private |
Flag marking whether we should dispatch notifications.
Definition at line 204 of file DynamicFactory.h.
Referenced by Mantid::Kernel::DynamicFactory< Base, Comparator >::disableNotifications(), Mantid::Kernel::DynamicFactory< Base, Comparator >::enableNotifications(), and Mantid::Kernel::DynamicFactory< Base, Comparator >::sendUpdateNotificationIfEnabled().
Poco::NotificationCenter Mantid::Kernel::DynamicFactory< Base, Comparator >::notificationCenter |
Sends notifications to observers.
Observers can subscribe to notificationCenter using Poco::NotificationCenter::addObserver(...)
Definition at line 184 of file DynamicFactory.h.
Referenced by Mantid::Kernel::DynamicFactory< Base, Comparator >::sendUpdateNotification().