8#include "ParamComposite.h"
28 className_(
"ParamComposite"),
41 className_(
"ParamComposite"),
46 UTIL_THROW(
"Attempt to reserve capacity <= 0");
48 list_.reserve(capacity);
49 isLeaf_.reserve(capacity);
60 className_(other.className_),
71 for (
int i=0; i < size_; ++i) {
90 assert(className_.size() > 0);
103 assert(className_.size() > 0);
106 Begin* beginPtr = &
readBegin(in, className_.c_str(), isRequired_);
122 for (
int i=0; i < size_; ++i) {
123 list_[i]->writeParam(out);
133 assert(className_.size() > 0);
166 if (!hasIoCommunicator()) {
167 UTIL_THROW(
"Error: not isIoProcessor and not hasIoCommunicator");
170 UTIL_THROW(
"Error: not isIoProcessor and no MPI");
174 if (hasIoCommunicator()) {
175 bcast<bool>(ioCommunicator(), isActive_, 0);
190 for (
int i=0; i < size_; ++i) {
211 for (
int i=0; i < size_; ++i) {
215 list_[i]->resetParam();
230 if (hasIoCommunicator()) {
231 param.setIoCommunicator(ioCommunicator());
241 list_.push_back(¶m);
242 isLeaf_.push_back(isLeaf);
399 UTIL_THROW(
"Error: cannot be required but not active");
Beginning line of a composite parameter block.
bool isActive() const
Is this an active element (has it been read from file)?
virtual void readParam(std::istream &in)
Read the opening line.
virtual void writeParam(std::ostream &out) const
Write the opening line.
An empty line within a parameter file.
virtual void readParam(std::istream &in)
Read a blank line.
End bracket of a ParamComposite parameter block.
virtual void writeParam(std::ostream &out) const
Write the closing bracket.
virtual void readParam(std::istream &in)
Read the closing bracket.
static std::ostream & file()
Get log ostream by reference.
bool isIoProcessor() const
Can this processor do file I/O ?
std::string indent() const
Return indent string for this object (string of spaces).
ParamComponent()
Constructor.
void setIndent(const ParamComponent &parent, bool next=true)
Set indent level.
static bool echo()
Get echo parameter.
virtual void load(Serializable::IArchive &ar)
Load all parameters from an input archive.
virtual void loadOptional(Serializable::IArchive &ar)
Load an optional ParamComposite.
virtual void readParameters(std::istream &in)
Read the body of parameter block, without begin and end lines.
Begin & readBegin(std::istream &in, const char *label, bool isRequired=true)
Add and read a class label and opening bracket.
void addParamComposite(ParamComposite &child, bool next=true)
Add a child ParamComposite object to the format array.
void saveOptional(Serializable::OArchive &ar)
Saves isActive flag, and then calls save() iff isActive is true.
void setClassName(const char *className)
Set class name string.
void setIsRequired(bool isRequired)
Set or unset the isActive flag.
void resetParam()
Resets ParamComposite to its empty state.
virtual ~ParamComposite()
Virtual destructor.
virtual void save(Serializable::OArchive &ar)
Saves all parameters to an archive.
Begin & addBegin(const char *label)
Add a Begin object representing a class name and bracket.
void setIsActive(bool isActive)
Set or unset the isActive flag.
virtual void writeParam(std::ostream &out) const
Write all parameters to an output stream.
void loadParamComposite(Serializable::IArchive &ar, ParamComposite &child, bool next=true)
Add and load a required child ParamComposite.
virtual void readParam(std::istream &in)
Read the parameter file block.
Blank & addBlank()
Create and add a new Blank object, representing a blank line.
bool isActive() const
Is this parameter active?
End & addEnd()
Add a closing bracket.
ParamComposite()
Constructor.
std::string className() const
Get class name string.
void loadParamCompositeOptional(Serializable::IArchive &ar, ParamComposite &child, bool next=true)
Add and load an optional child ParamComposite if isActive.
Blank & readBlank(std::istream &in)
Add and read a new Blank object, representing a blank line.
void readParamComposite(std::istream &in, ParamComposite &child, bool next=true)
Add and read a required child ParamComposite.
virtual void readParamOptional(std::istream &in)
Read optional parameter file block.
void readParamCompositeOptional(std::istream &in, ParamComposite &child, bool next=true)
Add and attempt to read an optional child ParamComposite.
End & readEnd(std::istream &in)
Add and read the closing bracket.
void setParent(ParamComponent ¶m, bool next=true)
Set this to the parent of a child component.
virtual void loadParameters(Serializable::IArchive &ar)
Load state from archive, without adding Begin and End lines.
void addComponent(ParamComponent ¶m, bool isLeaf=true)
Add a new ParamComponent object to the format array.
bool isRequired() const
Is this ParamComposite required in the input file?
BinaryFileIArchive IArchive
Type of input archive used by load method.
BinaryFileOArchive OArchive
Type of output archive used by save method.
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.