11#include <util/mpi/MpiFileIo.h>
12#include <util/param/ParamComposite.h>
13#include <util/param/Begin.h>
14#include <util/param/Label.h>
15#include <util/param/End.h>
32 template <
typename Data>
71 virtual Data*
factory(
const std::string &className)
const = 0;
101 std::string& className,
bool& isEnd,
102 bool isRequired =
true);
127 std::string& className,
bool& isEnd);
150 std::string& className);
187 std::vector< Factory<Data>* > subfactories_;
197 template <
typename Data>
205 template <
typename Data>
213 template <
typename Data>
216 if (paramFileIo_.hasIoCommunicator()) {
217 if (¶mFileIo_.ioCommunicator() != &communicator) {
218 UTIL_THROW(
"Attempt to modify Factory param communicator");
221 paramFileIo_.setIoCommunicator(communicator);
228 template <
typename Data>
230 {
return paramFileIo_.hasIoCommunicator(); }
236 template <
typename Data>
238 { subfactories_.push_back(&subfactory); }
246 template <
typename Data>
248 std::string& className,
bool& isEnd,
253 bool hasData =
false;
263 if (paramFileIo_.isIoProcessor()) {
268 Log::file() <<
"Empty required label read into Factory"
270 UTIL_THROW(
"Empty required label read into Factory");
279 if (paramFileIo_.hasIoCommunicator()) {
290 className = std::string();
310 if (paramFileIo_.isIoProcessor()) {
311 className = std::string();
318 typePtr = factory(className);
329 beginPtr = &typePtr->addBegin(className.c_str());
342 typePtr->readParameters(in);
348 typePtr->readEnd(in).setIndent(parent);
352 endPtr = &typePtr->addEnd();
364 std::string msg =
"Factory was unable to match line: "
376 template <
typename Data>
380 std::string& className,
bool& isEnd)
381 {
return readObject(in, parent, className, isEnd,
false); }
386 template <
typename Data>
389 std::string& className)
399 if (paramFileIo_.isIoProcessor()) {
405 if (paramFileIo_.hasIoCommunicator()) {
411 Data* typePtr = factory(className);
415 Log::file() <<
"Failed attempt to create instance of "
416 << className << std::endl;
424 template <
typename Data>
429 int n = subfactories_.size();
430 for (
int i = 0; i < n && typePtr == 0; ++i) {
431 typePtr = subfactories_[i]->factory(className);
This file contains templates for global functions send<T>, recv<T> and bcast<T>.
Beginning line of a composite parameter block.
virtual void writeParam(std::ostream &out) const
Write the opening line.
Saving archive for binary istream.
End bracket of a ParamComposite parameter block.
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.
Data * trySubfactories(const std::string &className) const
Search through subfactories for match.
bool hasIoCommunicator() const
Does this factory have a param communicator?
Data * readObjectOptional(std::istream &in, ParamComposite &parent, std::string &className, bool &isEnd)
Read an optional class name, instantiate an object, and read its parameters.
virtual Data * factory(const std::string &className) const =0
Returns a pointer to a new instance of specified subclass.
virtual ~Factory()
Destructor.
void setIoCommunicator(MPI::Intracomm &communicator)
Set associated Mpi communicator.
Data * loadObject(Serializable::IArchive &ar, ParamComposite &parent, std::string &className)
Load a class name, instantiate an object, and load the object.
void addSubfactory(Factory< Data > &subfactory)
Add a new subfactory to the list.
static std::string buffer()
Get the string that is currently in the input buffer.
static void read(std::istream &in)
Read a string without checking its value.
static void clear()
Clear the input buffer.
static void setIsMatched(bool isMatched)
Explicitly set the isMatched flag.
static bool isClear()
Is the input buffer clear?
static std::ostream & file()
Get log ostream by reference.
Identifies whether this processor may do file I/O.
MPI::Intracomm & ioCommunicator() const
Get the MPI communicator by reference.
bool hasIoCommunicator() const
Does this object have an associated MPI communicator?
void setIndent(const ParamComponent &parent, bool next=true)
Set indent level.
static bool echo()
Get echo parameter.
An object that can read multiple parameters from file.
void addParamComposite(ParamComposite &child, bool next=true)
Add a child ParamComposite object to the format array.
void loadParamComposite(Serializable::IArchive &ar, ParamComposite &child, bool next=true)
Add and load a required child ParamComposite.
File containing preprocessor macros for error handling.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Utility classes for scientific computation.
void bcast< std::string >(MPI::Intracomm &comm, std::string &data, int root)
Explicit specialization of bcast for std::string data.