PSCF v1.1
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Util::ArrayParam< Type > Class Template Referenceabstract

An array-valued parameter in a parameter file. More...

#include <ArrayParam.h>

Inheritance diagram for Util::ArrayParam< Type >:
Util::Parameter Util::ParamComponent Util::Serializable Util::MpiFileIo Util::CArrayParam< Type > Util::DArrayParam< Type > Util::FArrayParam< Type, Capacity > Util::FSArrayParam< Type, Capacity >

Public Member Functions

 ArrayParam (const char *label, int n, bool isRequired=true)
 Constructor. More...
 
virtual ~ArrayParam ()
 Destructor. More...
 
void writeParam (std::ostream &out) const
 Write an array-valued parameter to stream. More...
 
int n () const
 Get the logical array dimension. More...
 
std::string indent () const
 Return indent string for this object (string of spaces). More...
 
virtual void load (Serializable::IArchive &ar)
 Load from an archive. More...
 
virtual void save (Serializable::OArchive &ar)
 Save to an archive. More...
 
std::string label () const
 Return label string. More...
 
bool isRequired () const
 Is this an optional parameter? More...
 
bool isActive () const
 Is this parameter active? More...
 
- Public Member Functions inherited from Util::Parameter
 Parameter (const char *label, bool isRequired=true)
 Constructor. More...
 
virtual ~Parameter ()
 Destructor. More...
 
virtual void readParam (std::istream &in)
 Read a label and (if the label matches) a parameter value. More...
 
virtual void load (Serializable::IArchive &ar)
 Load from an archive. More...
 
virtual void save (Serializable::OArchive &ar)
 Save to an archive. More...
 
std::string label () const
 Return label string. More...
 
bool isRequired () const
 Is this an optional parameter? More...
 
bool isActive () const
 Is this parameter active? More...
 
- Public Member Functions inherited from Util::ParamComponent
virtual ~ParamComponent ()
 Destructor. More...
 
virtual void readParam (std::istream &in)=0
 Read parameter(s) from file. More...
 
virtual void writeParam (std::ostream &out) const =0
 Read parameter(s) to file. More...
 
virtual void load (Serializable::IArchive &ar)
 Load internal state from an archive. More...
 
virtual void save (Serializable::OArchive &ar)
 Save internal state to an archive. More...
 
virtual void resetParam ()
 Nontrivial implementation provided by ParamComposite subclass. More...
 
void setIndent (const ParamComponent &parent, bool next=true)
 Set indent level. More...
 
std::string indent () const
 Return indent string for this object (string of spaces). More...
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 Serialize this ParamComponent as a string. More...
 
- Public Member Functions inherited from Util::Serializable
virtual ~Serializable ()
 Destructor. More...
 
virtual void save (OArchive &ar)=0
 Save to an archive. More...
 
virtual void load (IArchive &ar)=0
 Load from an archive. More...
 
- Public Member Functions inherited from Util::MpiFileIo
 MpiFileIo ()
 Constructor. More...
 
 MpiFileIo (const MpiFileIo &other)
 Copy constructor. More...
 
bool isIoProcessor () const
 Can this processor do file I/O ? More...
 
void setIoCommunicator (MPI::Intracomm &communicator)
 Set the communicator. More...
 
void clearCommunicator ()
 Clear (nullify) the communicator. More...
 
bool hasIoCommunicator () const
 Does this object have an associated MPI communicator? More...
 
MPI::Intracomm & ioCommunicator () const
 Get the MPI communicator by reference. More...
 

Protected Member Functions

virtual void readLabel (std::istream &in)
 Read parameter label from an input stream. More...
 
virtual void readValue (std::istream &in)
 Read array of element values from an input stream. More...
 
void readEndBracket (std::istream &in)
 Read a closing bracket, if necessary. More...
 
virtual Type & element (int i)=0
 Return a non-const reference to one element of the array. More...
 
virtual Type const & element (int i) const =0
 Return a non-const reference to one element of the array. More...
 
bool hasBrackets () const
 Are square brackets being used as delimiters? More...
 
- Protected Member Functions inherited from Util::Parameter
virtual void readLabel (std::istream &in)
 Read and attempt to match label string. More...
 
virtual void readValue (std::istream &in)
 Read parameter value from an input stream. More...
 
virtual void loadValue (Serializable::IArchive &ar)
 Load bare parameter value from an archive. More...
 
virtual void saveValue (Serializable::OArchive &ar)
 Save parameter value to an archive. More...
 
virtual void bcastValue ()
 Broadcast parameter value within the ioCommunicator. More...
 
- Protected Member Functions inherited from Util::ParamComponent
 ParamComponent ()
 Constructor. More...
 
 ParamComponent (const ParamComponent &other)
 Copy constructor. More...
 

Protected Attributes

Label label_
 Label object that contains parameter label string. More...
 
- Protected Attributes inherited from Util::Parameter
Label label_
 Label object that contains parameter label string. More...
 
bool isActive_
 Is this parameter active (always true if isRequired). More...
 

Additional Inherited Members

- Public Types inherited from Util::Serializable
typedef BinaryFileOArchive OArchive
 Type of output archive used by save method. More...
 
typedef BinaryFileIArchive IArchive
 Type of input archive used by load method. More...
 
- Static Public Member Functions inherited from Util::Parameter
template<class Type >
static void saveOptional (Serializable::OArchive &ar, Type &value, bool isActive)
 Save an optional parameter value to an output archive. More...
 
template<class Type >
static void saveOptionalCArray (Serializable::OArchive &ar, Type *ptr, int n, bool isActive)
 Save an optional C-array of n values to an output archive. More...
 
template<class Type >
static void saveOptionalCArray2D (Serializable::OArchive &ar, Type *ptr, int m, int n, int np, bool isActive)
 Save an optional two-dimensional C array to an output archive. More...
 
- Static Public Member Functions inherited from Util::ParamComponent
static void initStatic ()
 Initialize static echo member to false. More...
 
static void setEcho (bool echo=true)
 Enable or disable echoing for all subclasses of ParamComponent. More...
 
static bool echo ()
 Get echo parameter. More...
 
- Static Public Attributes inherited from Util::Parameter
static const int Width = 20
 Width of output field for a scalar variable. More...
 
static const int Precision = 12
 Precision for io of floating point data field. More...
 

Detailed Description

template<typename Type>
class Util::ArrayParam< Type >

An array-valued parameter in a parameter file.

ArrayParam is a base class for objects that read and write the value of an array containing a list of parameters of the same type. The parameter file format for a parameter contains a string label followed by values of the elements of the array.

Arrays can be read and written in either of two formats:

The choice of whether to use bracketed or bracket-free format is determined by the value of the global policy returned by the function Util::BracketPolicy::get() :

If the bracket policy is optional, the code determines if brackets are being used on input by looking for an opening bracket at the end of the label. A closing bracket is then required if an opening bracket is found, and forbidden if no opening bracket is found.

Definition at line 55 of file ArrayParam.h.

Constructor & Destructor Documentation

◆ ArrayParam()

template<typename Type >
Util::ArrayParam< Type >::ArrayParam ( const char *  label,
int  n,
bool  isRequired = true 
)

Constructor.

Parameters
labellabel string preceding value in file format
nlogical array dimension
isRequiredIs this a required array-valued parameter?

Definition at line 24 of file ArrayParam.tpp.

References Util::BracketPolicy::get(), Util::ArrayParam< Type >::label_, and Util::Label::setString().

◆ ~ArrayParam()

template<typename Type >
Util::ArrayParam< Type >::~ArrayParam
virtual

Destructor.

Definition at line 43 of file ArrayParam.tpp.

Member Function Documentation

◆ writeParam()

template<class Type >
void Util::ArrayParam< Type >::writeParam ( std::ostream &  out) const
virtual

◆ n()

template<typename Type >
int Util::ArrayParam< Type >::n ( ) const
inline

Get the logical array dimension.

Definition at line 86 of file ArrayParam.h.

◆ readLabel()

template<typename Type >
void Util::ArrayParam< Type >::readLabel ( std::istream &  in)
protectedvirtual

Read parameter label from an input stream.

Parameters
ininput stream from which to read

Reimplemented from Util::Parameter.

Definition at line 50 of file ArrayParam.tpp.

References Util::BracketPolicy::get(), and Util::Label::isMatched().

◆ readValue()

template<class Type >
void Util::ArrayParam< Type >::readValue ( std::istream &  in)
protectedvirtual

Read array of element values from an input stream.

This function should be called after readLabel. It reads all the elements and then calls readEndBracket to read the final bracket, if any.

Parameters
ininput stream from which to read

Reimplemented from Util::Parameter.

Reimplemented in Util::DArrayParam< Type >, Util::FArrayParam< Type, Capacity >, and Util::FSArrayParam< Type, Capacity >.

Definition at line 103 of file ArrayParam.tpp.

Referenced by Util::DArrayParam< Type >::readValue(), and Util::FArrayParam< Type, Capacity >::readValue().

◆ readEndBracket()

template<class Type >
void Util::ArrayParam< Type >::readEndBracket ( std::istream &  in)
protected

Read a closing bracket, if necessary.

This function attempts to read the closing "]" bracket if and only if hasBrackets is true. An Exception is thrown if hasBrackets is true and no bracket is found. Before returning, the format is also reset to the appropriate default format for output.

Parameters
ininput stream from which to read

Definition at line 115 of file ArrayParam.tpp.

References Util::BracketPolicy::get(), and UTIL_CHECK.

Referenced by Util::FSArrayParam< Type, Capacity >::readValue().

◆ element() [1/2]

template<typename Type >
virtual Type & Util::ArrayParam< Type >::element ( int  i)
protectedpure virtual

Return a non-const reference to one element of the array.

This function is used to access individual elements within the readValue function. It must be implemented by subclasses.

Parameters
iarray element index

Implemented in Util::CArrayParam< Type >, Util::DArrayParam< Type >, Util::FArrayParam< Type, Capacity >, and Util::FSArrayParam< Type, Capacity >.

◆ element() [2/2]

template<typename Type >
virtual Type const & Util::ArrayParam< Type >::element ( int  i) const
protectedpure virtual

Return a non-const reference to one element of the array.

This function is used to access individual elements within the readValue function. It must be implemented by subclasses.

Parameters
iarray element index

Implemented in Util::CArrayParam< Type >, Util::DArrayParam< Type >, Util::FArrayParam< Type, Capacity >, and Util::FSArrayParam< Type, Capacity >.

◆ hasBrackets()

template<typename Type >
bool Util::ArrayParam< Type >::hasBrackets ( ) const
inlineprotected

Are square brackets being used as delimiters?

Definition at line 151 of file ArrayParam.h.

◆ indent()

template<typename Type >
std::string Util::ParamComponent::indent ( ) const

Return indent string for this object (string of spaces).

Definition at line 96 of file ParamComponent.cpp.

◆ load()

template<typename Type >
void Util::Parameter::load ( Serializable::IArchive ar)
virtual

Load from an archive.

An optional Parameter loads the value of an isActive flag, and then loads the parameter value only if the isActive is true. A required Parameter simply loads the parameter value. The variable associated with an optional Parameter must be set to its default value before attempting to load the parameter. Optional parameters should be saved either using the save() method of an associated Parameter object or using the appropriate overloaded Parameter::saveOptional() static member function, which both use the required format.

Parameters
arinput archive from which to load

Reimplemented from Util::Parameter.

Definition at line 150 of file Parameter.cpp.

Referenced by Util::ParamComposite::loadCArray(), Util::ParamComposite::loadDArray(), Util::ParamComposite::loadFArray(), and Util::ParamComposite::loadFSArray().

◆ save()

template<typename Type >
void Util::Parameter::save ( Serializable::OArchive ar)
virtual

Save to an archive.

An optional Parameter saves the value of the isActive flag, and then saves a parameter value only if the isActive is true. A required Parameter simply saves its value. The label string is not saved to the archive.

The overloaded static saveOptional functions can also be used to save optional parameter values in this format.

Parameters
aroutput archive to which to save

Reimplemented from Util::Parameter.

Definition at line 165 of file Parameter.cpp.

References Util::Parameter::label_, and Util::Label::string().

◆ label()

template<typename Type >
std::string Util::Parameter::label ( ) const

◆ isRequired()

template<typename Type >
bool Util::Parameter::isRequired ( ) const

Is this an optional parameter?

Definition at line 175 of file Parameter.cpp.

◆ isActive()

template<typename Type >
bool Util::Parameter::isActive ( ) const

Is this parameter active?

Definition at line 180 of file Parameter.cpp.

Member Data Documentation

◆ label_

template<typename Type >
Label Util::Parameter::label_
protected

Label object that contains parameter label string.

Definition at line 185 of file Parameter.h.

Referenced by Util::ArrayParam< Type >::ArrayParam().


The documentation for this class was generated from the following files: