11 #include <util/mpi/MpiFileIo.h> 12 #include <util/param/ParamComposite.h> 13 #include <util/param/Begin.h> 14 #include <util/param/End.h> 31 template <
typename Data>
70 virtual Data*
factory(
const std::string &className)
const = 0;
94 std::string& className,
bool& isEnd);
117 std::string& className);
154 std::vector< Factory<Data>* > subfactories_;
164 template <
typename Data>
172 template <
typename Data>
180 template <
typename Data>
185 UTIL_THROW(
"Attempt to modify Factory param communicator");
195 template <
typename Data>
203 template <
typename Data>
205 { subfactories_.push_back(&subfactory); }
213 template <
typename Data>
215 std::string& className,
bool& isEnd)
217 std::string commentString;
220 bool hasData =
false;
236 bcast<std::string>(paramFileIo_.
ioCommunicator(), commentString, 0);
240 length = commentString.size();
243 if (length == 1 && commentString[0] ==
'}') {
244 className = std::string();
252 if (commentString[length-1] ==
'{') {
253 className = commentString.substr(0, commentString.size() - 1);
256 if (commentString[length-1] ==
'}') {
257 className = commentString.substr(0, commentString.size() - 2);
261 Log::file() <<
"commentString = " << commentString << std::endl;
262 Log::file() <<
"className = " << className << std::endl;
275 beginPtr = &typePtr->addBegin(className.c_str());
286 typePtr->readParameters(in);
290 typePtr->readEnd(in).setIndent(parent);
302 template <
typename Data>
304 std::string& className)
326 Data* typePtr =
factory(className);
330 Log::file() <<
"Failed attempt to create instance of " 331 << className << std::endl;
339 template <
typename Data>
343 int n = subfactories_.size();
344 for (
int i = 0; i < n && typePtr == 0; ++i) {
345 typePtr = subfactories_[i]->factory(className);
void setIoCommunicator(MPI::Intracomm &communicator)
Set associated Mpi communicator.
void setIoCommunicator(MPI::Intracomm &communicator)
Set the communicator.
Data * readObject(std::istream &in, ParamComposite &parent, std::string &className, bool &isEnd)
Read a class name, instantiate an object, and read its parameters.
void loadParamComposite(Serializable::IArchive &ar, ParamComposite &child, bool next=true)
Add and load a required child ParamComposite.
void addSubfactory(Factory< Data > &subfactory)
Add a new subfactory to the list.
File containing preprocessor macros for error handling.
Identifies whether this processor may do file I/O.
Data * loadObject(Serializable::IArchive &ar, ParamComposite &parent, std::string &className)
Load a class name, instantiate an object, and load the object.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
MPI::Intracomm & ioCommunicator() const
Get the MPI communicator by reference.
Data * trySubfactories(const std::string &className) const
Search through subfactories for match.
Utility classes for scientific computation.
static bool echo()
Get echo parameter.
virtual void writeParam(std::ostream &out)
Write the opening line.
bool isIoProcessor() const
Can this processor do file I/O ?
virtual ~Factory()
Destructor.
void setIndent(const ParamComponent &parent, bool next=true)
Set indent level.
static std::ostream & file()
Get log ostream by reference.
bool hasIoCommunicator() const
Does this object have an associated MPI communicator?
Saving archive for binary istream.
void addParamComposite(ParamComposite &child, bool next=true)
Add a child ParamComposite object to the format array.
This file contains templates for global functions send<T>, recv<T> and bcast<T>.
bool hasIoCommunicator() const
Does this factory have a param communicator?
virtual Data * factory(const std::string &className) const =0
Returns a pointer to a new instance of specified subclass.
An object that can read multiple parameters from file.
Beginning line of a composite parameter block.