Mantid
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Mantid::Kernel::DynamicFactory< Base, Comparator > Class Template Reference

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...
 
DynamicFactoryoperator= (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...
 

Detailed Description

template<class Base, class Comparator = CaseInsensitiveStringComparator>
class Mantid::Kernel::DynamicFactory< Base, Comparator >

The dynamic factory is a base dynamic factory for serving up objects in response to requests from other classes.

Author
Nick Draper, Tessella Support Services plc
Date
10/10/2007

Definition at line 47 of file DynamicFactory.h.

Member Typedef Documentation

◆ AbstractFactory

template<class Base , class Comparator = CaseInsensitiveStringComparator>
using Mantid::Kernel::DynamicFactory< Base, Comparator >::AbstractFactory = AbstractInstantiator<Base>

A typedef for the instantiator.

Definition at line 78 of file DynamicFactory.h.

◆ FactoryMap

template<class Base , class Comparator = CaseInsensitiveStringComparator>
using Mantid::Kernel::DynamicFactory< Base, Comparator >::FactoryMap = std::map<std::string, std::unique_ptr<AbstractFactory>, Comparator>
private

A typedef for the map of registered classes.

Definition at line 200 of file DynamicFactory.h.

Member Enumeration Documentation

◆ NotificationStatus

template<class Base , class Comparator = CaseInsensitiveStringComparator>
enum Mantid::Kernel::DynamicFactory::NotificationStatus

Defines the whether notifications are dispatched.

Enumerator
Enabled 
Disabled 

Definition at line 51 of file DynamicFactory.h.

◆ SubscribeAction

template<class Base , class Comparator = CaseInsensitiveStringComparator>
enum Mantid::Kernel::DynamicFactory::SubscribeAction

Defines replacement behaviour.

Enumerator
ErrorIfExists 
OverwriteCurrent 

Definition at line 53 of file DynamicFactory.h.

Constructor & Destructor Documentation

◆ DynamicFactory() [1/2]

template<class Base , class Comparator = CaseInsensitiveStringComparator>
Mantid::Kernel::DynamicFactory< Base, Comparator >::DynamicFactory ( const DynamicFactory< Base, Comparator > &  )
delete

◆ ~DynamicFactory()

template<class Base , class Comparator = CaseInsensitiveStringComparator>
virtual Mantid::Kernel::DynamicFactory< Base, Comparator >::~DynamicFactory ( )
virtualdefault

Destroys the DynamicFactory and deletes the instantiators for all registered classes.

◆ DynamicFactory() [2/2]

template<class Base , class Comparator = CaseInsensitiveStringComparator>
Mantid::Kernel::DynamicFactory< Base, Comparator >::DynamicFactory ( )
inlineprotected

Protected constructor for base class.

Definition at line 188 of file DynamicFactory.h.

Member Function Documentation

◆ create()

template<class Base , class Comparator = CaseInsensitiveStringComparator>
virtual std::shared_ptr< Base > Mantid::Kernel::DynamicFactory< Base, Comparator >::create ( const std::string &  className) const
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.

Parameters
className:: the name of the class you wish to create
Returns
a shared pointer ot the base class

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().

◆ createUnwrapped()

template<class Base , class Comparator = CaseInsensitiveStringComparator>
virtual Base * Mantid::Kernel::DynamicFactory< Base, Comparator >::createUnwrapped ( const std::string &  className) const
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.

Parameters
className:: the name of the class you wish to create
Returns
a pointer to the base class

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().

◆ disableNotifications()

template<class Base , class Comparator = CaseInsensitiveStringComparator>
void Mantid::Kernel::DynamicFactory< Base, Comparator >::disableNotifications ( )
inline

◆ enableNotifications()

template<class Base , class Comparator = CaseInsensitiveStringComparator>
void Mantid::Kernel::DynamicFactory< Base, Comparator >::enableNotifications ( )
inline

◆ exists()

template<class Base , class Comparator = CaseInsensitiveStringComparator>
bool Mantid::Kernel::DynamicFactory< Base, Comparator >::exists ( const std::string &  className) const
inline

Returns true if the given class is currently registered.

Parameters
className:: the name of the class you wish to check
Returns
true is the class is subscribed

Definition at line 167 of file DynamicFactory.h.

References Mantid::Kernel::DynamicFactory< Base, Comparator >::_map.

Referenced by Mantid::API::AlgorithmFactoryImpl::exists().

◆ getKeys()

template<class Base , class Comparator = CaseInsensitiveStringComparator>
virtual const std::vector< std::string > Mantid::Kernel::DynamicFactory< Base, Comparator >::getKeys ( ) const
inlinevirtual

Returns the keys in the map.

Returns
A string vector of keys

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().

◆ operator=()

template<class Base , class Comparator = CaseInsensitiveStringComparator>
DynamicFactory & Mantid::Kernel::DynamicFactory< Base, Comparator >::operator= ( const DynamicFactory< Base, Comparator > &  )
delete

◆ sendUpdateNotification()

template<class Base , class Comparator = CaseInsensitiveStringComparator>
void Mantid::Kernel::DynamicFactory< Base, Comparator >::sendUpdateNotification ( )
inlineprivate

◆ sendUpdateNotificationIfEnabled()

template<class Base , class Comparator = CaseInsensitiveStringComparator>
void Mantid::Kernel::DynamicFactory< Base, Comparator >::sendUpdateNotificationIfEnabled ( )
inlineprivate

◆ subscribe() [1/2]

template<class Base , class Comparator = CaseInsensitiveStringComparator>
template<class C >
void Mantid::Kernel::DynamicFactory< Base, Comparator >::subscribe ( const std::string &  className)
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.

Parameters
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().

◆ subscribe() [2/2]

template<class Base , class Comparator = CaseInsensitiveStringComparator>
void Mantid::Kernel::DynamicFactory< Base, Comparator >::subscribe ( const std::string &  className,
std::unique_ptr< AbstractFactory pAbstractFactory,
SubscribeAction  replace = ErrorIfExists 
)
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.

Parameters
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().

◆ unsubscribe()

template<class Base , class Comparator = CaseInsensitiveStringComparator>
void Mantid::Kernel::DynamicFactory< Base, Comparator >::unsubscribe ( const std::string &  className)
inline

Unregisters the given class and deletes the instantiator for the class.

Throws a NotFoundException if the class has not been registered.

Parameters
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().

Member Data Documentation

◆ _map

template<class Base , class Comparator = CaseInsensitiveStringComparator>
FactoryMap Mantid::Kernel::DynamicFactory< Base, Comparator >::_map
private

◆ m_notifyStatus

template<class Base , class Comparator = CaseInsensitiveStringComparator>
NotificationStatus Mantid::Kernel::DynamicFactory< Base, Comparator >::m_notifyStatus
private

◆ notificationCenter

template<class Base , class Comparator = CaseInsensitiveStringComparator>
Poco::NotificationCenter Mantid::Kernel::DynamicFactory< Base, Comparator >::notificationCenter

Sends notifications to observers.

Observers can subscribe to notificationCenter using Poco::NotificationCenter::addObserver(...)

Returns
nothing

Definition at line 184 of file DynamicFactory.h.

Referenced by Mantid::Kernel::DynamicFactory< Base, Comparator >::sendUpdateNotification().


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