|
criptic v1
Cosmic Ray Interstellar Propagation Tool using Itô Calculus
|
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 ¶mFile) |
| 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, keyword > | keywords |
| std::map< const std::string, bool > | accessed |
| std::string | restartFileName |
| bool | restart |
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.
| 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.
| ParmParser::ParmParser | ( | int | argc, |
| char ** | argv | ||
| ) |
Construct the ParmParser from the command line.
| argc | The number of arguments provided on the command line |
| argv | Array of command line arguments |
| void ParmParser::dumpParams | ( | std::ostream & | outFile | ) |
Write out full list of input parameters.
| outFile | File / stream into which to write output |
| void ParmParser::get | ( | const std::string & | name, |
| int & | val | ||
| ) | const |
Return an integer-valued keyword.
| name | Name of keyword whose value should be returned |
| val | Value 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.
| void ParmParser::get | ( | const std::string & | name, |
| Real & | val | ||
| ) | const |
Return an Real-valued keyword.
| name | Name of keyword whose value should be returned |
| val | Value 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.
| void ParmParser::get | ( | const std::string & | name, |
| std::string & | val | ||
| ) | const |
Return an string-valued keyword.
| name | Name of keyword whose value should be returned |
| val | Value of keyword |
If a keyword with the specified name is not available, this invokes MPIUtil::haltRun.
| void ParmParser::get | ( | const std::string & | name, |
| std::vector< int > & | val | ||
| ) | const |
Return an vector-of-integer-valued keyword.
| name | Name of keyword whose value should be returned |
| val | Value 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.
| void ParmParser::get | ( | const std::string & | name, |
| std::vector< Real > & | val | ||
| ) | const |
Return an vector-of-Real-valued keyword.
| name | Name of keyword whose value should be returned |
| val | Value 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.
| void ParmParser::get | ( | const std::string & | name, |
| std::vector< std::string > & | val | ||
| ) | const |
Return an vector-of-string-valued keyword.
| name | Name of keyword whose value should be returned |
| val | Value 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.
| void ParmParser::get | ( | const std::string & | name, |
| Vec3< T > & | val | ||
| ) | const |
Return an Vec3-valued keyword.
| name | Name of keyword whose value should be returned |
| val | Value 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.
|
inline |
Returns whether this run is a restart.
|
private |
Error function invoked if a required keyword is missing.
| key | Keyword 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.
|
private |
Error function invoked if input deck fails to parse.
| line | Line 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.
|
private |
The file parsing function.
| paramFile | Input stream containing criptic input deck |
|
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.
| template bool ParmParser::query | ( | const std::string & | name, |
| T & | val | ||
| ) | const |
Return a keyword, or return false if not available.
| T | Return type of the keyword requested |
| name | Name of keyword whose value should be returned |
| val | Value of keyword |
This function is similar to variant::get_if, with the difference that it automatically attempts type conversions where possible.
|
inline |
Name of restart file.
|
private |
Error function invoked if a keyword has an invalid type.
| key | Keyword 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.
| void ParmParser::warnUnusedKeywords | ( | ) | const |
Issue warning if any keywords have not been accessed.
|
mutableprivate |
List of which keywords have been accessed – used to print warnings
|
private |
Map of keyword-value pairs
|
private |
Is this run a restart?
|
private |
Name of restart file