Simpatico  v1.10
List of all members | Public Member Functions | Protected Member Functions
Util::Factory< Data > Class Template Referenceabstract

Detailed Description

template<typename Data>
class Util::Factory< Data >

Factory template.

Definition at line 32 of file Factory.h.

#include <Factory.h>

Public Member Functions

 Factory ()
 Constructor. More...
 
virtual ~Factory ()
 Destructor. More...
 
void addSubfactory (Factory< Data > &subfactory)
 Add a new subfactory to the list. More...
 
virtual Data * factory (const std::string &className) const =0
 Returns a pointer to a new instance of specified subclass. More...
 
Data * readObject (std::istream &in, ParamComposite &parent, std::string &className, bool &isEnd)
 Read a class name, instantiate an object, and read its parameters. More...
 
Data * loadObject (Serializable::IArchive &ar, ParamComposite &parent, std::string &className)
 Load a class name, instantiate an object, and load the object. More...
 

Protected Member Functions

Data * trySubfactories (const std::string &className) const
 Search through subfactories for match. More...
 
void setIoCommunicator (MPI::Intracomm &communicator)
 Set associated Mpi communicator. More...
 
bool hasIoCommunicator () const
 Does this factory have a param communicator? More...
 

Constructor & Destructor Documentation

template<typename Data >
Util::Factory< Data >::Factory ( )

Constructor.

Definition at line 165 of file Factory.h.

template<typename Data >
Util::Factory< Data >::~Factory ( )
virtual

Destructor.

Definition at line 173 of file Factory.h.

Member Function Documentation

template<typename Data>
void Util::Factory< Data >::addSubfactory ( Factory< Data > &  subfactory)

Add a new subfactory to the list.

Parameters
subfactoryNew subfactory to be added

Definition at line 204 of file Factory.h.

Referenced by McMd::SliplinkMcModule::SliplinkMcModule().

template<typename Data>
virtual Data* Util::Factory< Data >::factory ( const std::string &  className) const
pure virtual

Returns a pointer to a new instance of specified subclass.

This method takes the name className of a subclass of Data as a parameter, and attempts to instantiate an object of that class. If it recognizes the className, it creates an instance of that class and returns a Data* base class pointer to the new object. If it does not recognize the className, it returns a null pointer.

An implementation should first call "trySubfactories(className)" and immediately return if this returns a non-null pointer, before attempting to match the className against specific strings.

Parameters
classNamename of subclass
Returns
base class pointer to new object, or a null pointer.

Implemented in Tools::ConfigReaderFactory, Tools::TrajectoryReaderFactory, Tools::ConfigWriterFactory, McMd::McMoveFactory, DdMd::ModifierFactory, DdMd::ConfigIoFactory, McMd::McAnalyzerFactory, McMd::MdAnalyzerFactory, McMd::SystemAnalyzerFactory, McMd::McCommandFactory, McMd::MdCommandFactory, McMd::McPerturbationFactory, DdMd::AnalyzerFactory, Tools::ProcessorAnalyzerFactory, DdMd::IntegratorFactory, McMd::AngleFactory, McMd::CoulombFactory, McMd::MdIntegratorFactory, McMd::BondFactory, McMd::DihedralFactory, McMd::ExternalFactory, McMd::LinkFactory, DdMd::PairFactory, McMd::ConfigIoFactory, McMd::TrajectoryReaderFactory, DdMd::AngleFactory, DdMd::BondFactory, DdMd::DihedralFactory, DdMd::ExternalFactory, McMd::SliplinkMcMoveFactory, McMd::SpeciesFactory, McMd::SliplinkMcAnalyzerFactory, and McMd::SliplinkMdAnalyzerFactory.

Referenced by McMd::MdSimulation::analyzeTrajectory(), McMd::McSimulation::analyzeTrajectory(), Util::Factory< Data >::loadObject(), McMd::McSystem::loadParameters(), McMd::MdSystem::loadParameters(), Util::Factory< Data >::readObject(), McMd::McSystem::readParameters(), McMd::MdSystem::readParameters(), and McMd::System::setConfigIo().

template<typename Data >
Data * Util::Factory< Data >::readObject ( std::istream &  in,
ParamComposite parent,
std::string &  className,
bool &  isEnd 
)

Read a class name, instantiate an object, and read its parameters.

This method:

  • reads a comment line of the form className + {
  • invokes the factory method to create an instance of className
  • invokes the readParam() method of the new object

When compiled with MPI, if the parent ParamComposite has a param communicator, this method reads the comment line on the Io processor, broadcasts it to all others, and then lets each processor independently match this string.

Exceptions
Exceptionif className is not recognized.
Parameters
ininput stream
parentparent ParamComposite object
className(output) name of subclass of Data
isEnd(output) is the input a closing bracket "}" ?
Returns
pointer to new instance of className

Definition at line 214 of file Factory.h.

References Util::ParamComposite::addParamComposite(), Util::ParamComponent::echo(), Util::Factory< Data >::factory(), Util::Log::file(), Util::MpiFileIo::hasIoCommunicator(), Util::MpiFileIo::ioCommunicator(), Util::MpiFileIo::isIoProcessor(), Util::ParamComponent::setIndent(), Util::Factory< Data >::setIoCommunicator(), UTIL_THROW, and Util::Begin::writeParam().

Referenced by McMd::MdSystem::readParameters(), and McMd::System::readPerturbation().

template<typename Data >
Data * Util::Factory< Data >::loadObject ( Serializable::IArchive ar,
ParamComposite parent,
std::string &  className 
)

Load a class name, instantiate an object, and load the object.

This method:

  • loads a className from an input archive
  • invokes the factory method to create an instance of className
  • invokes the load() method of the new object

When compiled with MPI, if the parent ParamComposite has a param communicator, this method loads the comment line on the Io processor, broadcasts it to all others, and then lets each processor independently match this string.

Exceptions
Exceptionif className is not recognized.
Parameters
arinput/loading archive
parentparent ParamComposite object
className(output) name of subclass of Data
Returns
pointer to new instance of className

Definition at line 303 of file Factory.h.

References Util::Factory< Data >::factory(), Util::Log::file(), Util::MpiFileIo::hasIoCommunicator(), Util::MpiFileIo::ioCommunicator(), Util::MpiFileIo::isIoProcessor(), Util::ParamComposite::loadParamComposite(), and Util::Factory< Data >::setIoCommunicator().

Referenced by McMd::MdSystem::loadParameters(), and McMd::System::loadPerturbation().

template<typename Data >
Data * Util::Factory< Data >::trySubfactories ( const std::string &  className) const
protected

Search through subfactories for match.

This method iterates through all registered subfactories, calls the factory(const std::string& ) method of each, and immediately returns a pointer to a new object if any of them returns a non-null pointer. If all of them return a null pointer, this method also returns a null pointer.

Parameters
classNamename of subclass
Returns
base class pointer to new object, or a null pointer.

Definition at line 340 of file Factory.h.

template<typename Data >
void Util::Factory< Data >::setIoCommunicator ( MPI::Intracomm &  communicator)
protected

Set associated Mpi communicator.

Is not recursive (is not applied to subfactories).

Parameters
communicatorMPI Intra-communicator to use for input

Definition at line 181 of file Factory.h.

References Util::MpiFileIo::hasIoCommunicator(), Util::MpiFileIo::ioCommunicator(), Util::MpiFileIo::setIoCommunicator(), and UTIL_THROW.

Referenced by Util::Factory< Data >::loadObject(), and Util::Factory< Data >::readObject().

template<typename Data >
bool Util::Factory< Data >::hasIoCommunicator ( ) const
protected

Does this factory have a param communicator?

Definition at line 196 of file Factory.h.

References Util::MpiFileIo::hasIoCommunicator().


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