criptic v1
Cosmic Ray Interstellar Propagation Tool using Itô Calculus
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
criptic::ParmParser Class Reference

Class to parse the criptic input deck. More...

#include <ParmParser.H>

Public Types

using keyword = std::variant< int, Real, std::string, std::vector< int >, std::vector< Real >, std::vector< std::string > >
 Type corresponding to input deck keywords.
 

Public Member Functions

 ParmParser (int argc, char **argv)
 Construct the ParmParser from the command line.
 
bool isRestart () const
 Returns whether this run is a restart.
 
const std::string & restartFile () const
 Name of restart file.
 
void get (const std::string &name, int &val) const
 Return an integer-valued keyword.
 
void get (const std::string &name, Real &val) const
 Return an Real-valued keyword.
 
void get (const std::string &name, std::string &val) const
 Return an string-valued keyword.
 
void get (const std::string &name, std::vector< int > &val) const
 Return an vector-of-integer-valued keyword.
 
void get (const std::string &name, std::vector< Real > &val) const
 Return an vector-of-Real-valued keyword.
 
void get (const std::string &name, std::vector< std::string > &val) const
 Return an vector-of-string-valued keyword.
 
template<class T >
void get (const std::string &name, Vec3< T > &val) const
 Return an Vec3-valued keyword.
 
template<class T >
bool query (const std::string &name, T &val) const
 Return a keyword, or return false if not available.
 
void dumpParams (std::ostream &outFile)
 Write out full list of input parameters.
 
void warnUnusedKeywords () const
 Issue warning if any keywords have not been accessed.
 

Private Member Functions

void parseFile (std::ifstream &paramFile)
 The file parsing function.
 
void parseError (const std::string &line) const
 Error function invoked if input deck fails to parse.
 
void typeError (const std::string &key) const
 Error function invoked if a keyword has an invalid type.
 
void missingKeyError (const std::string &key) const
 Error function invoked if a required keyword is missing.
 
void printUsage ()
 Print out usage information.
 

Private Attributes

std::map< const std::string, keywordkeywords
 
std::map< const std::string, bool > accessed
 
std::string restartFileName
 
bool restart
 

Detailed Description

Class to parse the criptic input deck.

This class accepts argc and argv from the command line used to invoke criptic, uses the information provided to find and read the input deck, and provides methods to query keywords from that deck to the rest of the code.

Member Typedef Documentation

◆ keyword

using criptic::ParmParser::keyword = std::variant<int, Real, std::string, std::vector<int>, std::vector<Real>, std::vector<std::string> >

Type corresponding to input deck keywords.

Constructor & Destructor Documentation

◆ ParmParser()

ParmParser::ParmParser ( int  argc,
char **  argv 
)

Construct the ParmParser from the command line.

Parameters
argcThe number of arguments provided on the command line
argvArray of command line arguments

Member Function Documentation

◆ dumpParams()

void ParmParser::dumpParams ( std::ostream &  outFile)

Write out full list of input parameters.

Parameters
outFileFile / stream into which to write output

◆ get() [1/7]

void ParmParser::get ( const std::string &  name,
int &  val 
) const

Return an integer-valued keyword.

Parameters
nameName of keyword whose value should be returned
valValue of keyword

If a keyword with the specified name is not available, or is available but not convertible to integer type, this invokes MPIUtil::haltRun.

◆ get() [2/7]

void ParmParser::get ( const std::string &  name,
Real val 
) const

Return an Real-valued keyword.

Parameters
nameName of keyword whose value should be returned
valValue of keyword

If a keyword with the specified name is not available, or is available but is not convertible to a Real, this invokes MPIUtil::haltRun.

◆ get() [3/7]

void ParmParser::get ( const std::string &  name,
std::string &  val 
) const

Return an string-valued keyword.

Parameters
nameName of keyword whose value should be returned
valValue of keyword

If a keyword with the specified name is not available, this invokes MPIUtil::haltRun.

◆ get() [4/7]

void ParmParser::get ( const std::string &  name,
std::vector< int > &  val 
) const

Return an vector-of-integer-valued keyword.

Parameters
nameName of keyword whose value should be returned
valValue of keyword

If a keyword with the specified name is not available, or is not convertible to vector of integer, this invokes MPIUtil::haltRun. Keywords containing only a single integer value will be converted to a vector of length 1.

◆ get() [5/7]

void ParmParser::get ( const std::string &  name,
std::vector< Real > &  val 
) const

Return an vector-of-Real-valued keyword.

Parameters
nameName of keyword whose value should be returned
valValue of keyword

If a keyword with the specified name is not available, or is not convertible to vector of Real, this invokes MPIUtil::haltRun. Keywords containing only a single Real value will be converted to a vector of length 1.

◆ get() [6/7]

void ParmParser::get ( const std::string &  name,
std::vector< std::string > &  val 
) const

Return an vector-of-string-valued keyword.

Parameters
nameName of keyword whose value should be returned
valValue of keyword

If a keyword with the specified name is not available this invokes MPIUtil::haltRun. The keyword is decomposed into different strings in the vector based on whitespace; if no whitespace is present, the returned vector will be of size 1.

◆ get() [7/7]

template<class T >
void ParmParser::get ( const std::string &  name,
Vec3< T > &  val 
) const

Return an Vec3-valued keyword.

Parameters
nameName of keyword whose value should be returned
valValue of keyword

If a keyword with the specified name is not available, or is not convertible to Vec3, this invokes MPIUtil::haltRun. To be convertible to Vec3, the contents of the keyword must be exactly three numbers.

◆ isRestart()

bool criptic::ParmParser::isRestart ( ) const
inline

Returns whether this run is a restart.

Returns
True if this is a restart, false otherwise

◆ missingKeyError()

void ParmParser::missingKeyError ( const std::string &  key) const
private

Error function invoked if a required keyword is missing.

Parameters
keyKeyword with invalid time

This function is called if a required keyword is not found in the input file. It invokes MPIUtil::haltRun with an appropriate error message.

◆ parseError()

void ParmParser::parseError ( const std::string &  line) const
private

Error function invoked if input deck fails to parse.

Parameters
lineLine that failed to parse

This function is called if a line in the input deck cannot be parsed. It invokes MPIUtil::haltRun with an appropriate error message.

◆ parseFile()

void ParmParser::parseFile ( std::ifstream &  paramFile)
private

The file parsing function.

Parameters
paramFileInput stream containing criptic input deck

◆ printUsage()

void ParmParser::printUsage ( )
private

Print out usage information.

This prints out usage information for criptic. It is used if criptic is invoked with –help, or if the command line is invalid.

◆ query()

template<class T >
template bool ParmParser::query ( const std::string &  name,
T &  val 
) const

Return a keyword, or return false if not available.

Template Parameters
TReturn type of the keyword requested
Parameters
nameName of keyword whose value should be returned
valValue of keyword
Returns
True if keyword is found and convertible to requested type, false otherwise

This function is similar to variant::get_if, with the difference that it automatically attempts type conversions where possible.

◆ restartFile()

const std::string & criptic::ParmParser::restartFile ( ) const
inline

Name of restart file.

Returns
Name of the file from which to restart

◆ typeError()

void ParmParser::typeError ( const std::string &  key) const
private

Error function invoked if a keyword has an invalid type.

Parameters
keyKeyword with invalid time

This function is called if the type of a keyword is invalid (e.g., a keyword that must be integer-valued is assigned a non-integer value). It invokes MPIUtil::haltRun with an appropriate error message.

◆ warnUnusedKeywords()

void ParmParser::warnUnusedKeywords ( ) const

Issue warning if any keywords have not been accessed.

Member Data Documentation

◆ accessed

std::map<const std::string, bool> criptic::ParmParser::accessed
mutableprivate

List of which keywords have been accessed – used to print warnings

◆ keywords

std::map<const std::string, keyword> criptic::ParmParser::keywords
private

Map of keyword-value pairs

◆ restart

bool criptic::ParmParser::restart
private

Is this run a restart?

◆ restartFileName

std::string criptic::ParmParser::restartFileName
private

Name of restart file


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