Simpatico
v1.10
|
Factory template.
#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... | |
Util::Factory< Data >::Factory | ( | ) |
|
virtual |
void Util::Factory< Data >::addSubfactory | ( | Factory< Data > & | subfactory | ) |
Add a new subfactory to the list.
subfactory | New subfactory to be added |
Definition at line 204 of file Factory.h.
Referenced by McMd::SliplinkMcModule::SliplinkMcModule().
|
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.
className | name of subclass |
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().
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:
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.
Exception | if className is not recognized. |
in | input stream |
parent | parent ParamComposite object |
className | (output) name of subclass of Data |
isEnd | (output) is the input a closing bracket "}" ? |
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().
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:
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.
Exception | if className is not recognized. |
ar | input/loading archive |
parent | parent ParamComposite object |
className | (output) name of subclass of Data |
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().
|
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.
className | name of subclass |
|
protected |
Set associated Mpi communicator.
Is not recursive (is not applied to subfactories).
communicator | MPI 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().
|
protected |
Does this factory have a param communicator?
Definition at line 196 of file Factory.h.
References Util::MpiFileIo::hasIoCommunicator().