PSCF v1.1
|
#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, bool isRequired=true) |
Read a class name, instantiate an object, and read its parameters. More... | |
Data * | readObjectOptional (std::istream &in, ParamComposite &parent, std::string &className, bool &isEnd) |
Read an optional 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... | |
Factory template.
Util::Factory< Data >::Factory |
|
virtual |
void Util::Factory< Data >::addSubfactory | ( | Factory< Data > & | subfactory | ) |
|
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 Pscf::Fd1d::IteratorFactory, Pscf::Pspc::IteratorFactory< D >, Pscf::Pspg::IteratorFactory< D >, Pscf::Fd1d::SweepFactory, Pscf::Pspc::SweepFactory< D >, and Pscf::Pspg::SweepFactory< D >.
Data * Util::Factory< Data >::readObject | ( | std::istream & | in, |
ParamComposite & | parent, | ||
std::string & | className, | ||
bool & | isEnd, | ||
bool | isRequired = true |
||
) |
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 but is required. |
in | input stream |
parent | parent ParamComposite object |
className | (output) name of subclass of Data |
isEnd | (output) is the input a closing bracket "}" ? |
isRequired | is this object required? Default is true. |
Definition at line 247 of file Factory.h.
References Util::ParamComposite::addParamComposite(), Util::bcast< std::string >(), Util::Label::buffer(), Util::Label::clear(), Util::ParamComponent::echo(), Util::Log::file(), Util::MpiFileIo::hasIoCommunicator(), Util::MpiFileIo::ioCommunicator(), Util::Label::isClear(), Util::Label::read(), Util::ParamComponent::setIndent(), Util::Label::setIsMatched(), UTIL_THROW, and Util::Begin::writeParam().
Referenced by Pscf::Fd1d::System::readParameters().
Data * Util::Factory< Data >::readObjectOptional | ( | std::istream & | in, |
ParamComposite & | parent, | ||
std::string & | className, | ||
bool & | isEnd | ||
) |
Read an optional 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.
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 378 of file Factory.h.
Referenced by Pscf::Fd1d::System::readParameters().
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 387 of file Factory.h.
References Util::bcast< std::string >(), Util::Log::file(), Util::MpiFileIo::hasIoCommunicator(), Util::MpiFileIo::ioCommunicator(), and Util::ParamComposite::loadParamComposite().
|
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 214 of file Factory.h.
References UTIL_THROW.
|
protected |