STORMM Source Documentation
|
Collection of variables to transcribe information contained within a namelist. More...
#include <namelist_emulator.h>
Public Member Functions | |
NamelistEmulator (const std::string &title_in, CaseSensitivity casing_in=CaseSensitivity::AUTOMATIC, ExceptionResponse unknown_keyword_policy=ExceptionResponse::WARN, const std::string &help_in=std::string("No description provided"), bool cli_content_in=false) | |
Construct an object to emulate Fortran namelist functionality, with improvements. | |
const std::string & | getTitle () const |
Obtain the title of this namelist (i.e. &cntrl or &dock) | |
bool | isCommandLineContent () const |
Detect whether the namelist emulator serves command-line inputs for a program. | |
int | getKeywordCount () const |
Obtain the number of parameters catalogged within this namelist emulator. | |
CaseSensitivity | getCaseSensitivity () const |
Obtain the case sensitivity setting for this namelist. | |
ExceptionResponse | getPolicy () const |
Relay the exception handling policy for this namelist. | |
const std::string & | getKeyword (size_t index) const |
Get a keyword from this namelist based on an index. This is for retrieving the keyword itself, not a value associated with a keyword. | |
NamelistType | getKeywordKind (const std::string &keyword_query) const |
Get the type of a specific keyword within this namelist. | |
int | getKeywordEntries (const std::string &keyword_query) const |
Get the number of entries associated with a specific keyword. | |
int | getSubKeyCount (const std::string &keyword_query) const |
Get the template size of a keyword, the number of sub-keys it contains. For non-struct keywords the template size is reported as 0. | |
std::vector< bool > | getAllBoolValues (const std::string &keyword_query, const std::string &sub_key) const |
Get all boolen values assigned to a particular keyword. The keyword must have STRUCT type, as the only other option for a BOOL keyword is a single value. | |
std::vector< int > | getAllIntValues (const std::string &keyword_query, const std::string &sub_key=std::string("")) const |
Get all integer values assigned to a particular keyword. | |
std::vector< double > | getAllRealValues (const std::string &keyword_query, const std::string &sub_key=std::string("")) const |
Get all real values assigned to a particular keyword. | |
std::vector< std::string > | getAllStringValues (const std::string &keyword_query, const std::string &sub_key=std::string("")) const |
Get all string values assigned to a particular keyword. | |
const std::string & | getHelp () const |
Report the help message associated with a keyword or sub-key. This can be useful for developers who wish to alert users to erroneous input. | |
const std::string & | getHelp (const std::string &keyword_query) const |
const std::string & | getHelp (const std::string &keyword_query, const std::string &sub_key) const |
const NamelistEmulator * | getSelfPointer () const |
Get a pointer to the object itself. | |
void | setTitle (const std::string &title_in) |
Set the title of the namelist. | |
void | setCommandLineContent (bool cli_content_in=true) |
Set whether the namelist actually serves command line input for a whole program. | |
void | addDefaultValue (const std::string &key, const std::string &next_default) |
Add a value to one keyword's default settings. This enables a single keyword to have a collection of default values. The keyword will be checked to ensure that it permits multiple values. | |
void | triggerResizeBuffer (const std::string &key) |
When loading data for STRUCT-type keywords, the decision to increment the number of entries on file cannot be made with the first sub-key assignment. Instead, the entire struct must be read from input before the number of entries can be incremented. Because a function (readNamelist(), see input.h) that manages a NamelistEmulator loops over the input that can be associated with each list of subk-eys for a given STRUCT, that function must go through the NamelistEmulator in order to increment the keyword's entry count. | |
void | addCategory (const std::string &new_category) |
Add a category to a namelist to group its keywords for user documentation. | |
void | categorizeKeyword (const std::string &key, const std::string &category_label) |
Place a namelist keyword into one of a list of arbitrary categories defined by the developer. This is for organizing the user documentation. | |
void | printKeywordDocumentation (int p_idx, int name_width, int kw_kind_width, const std::string &kw_dflt) const |
Print the documentation for a specific keyword. The format is fixed in the sense that it will have a set indentation, a dash for a bullet point, and the keyword printed in a space large enough for a series of related keywords in a column. | |
std::string | convertDefaultToString (const NamelistElement &tkw) const |
Convert the default value of a keyword to a string for output in a formatted table. | |
void | printHelp () const |
Print a detailed message concerning the user documentation for keywords in this namelist. This function can be called from the main program, for any namelists that accept its inputs, and is itself called by the printProgramDocumentation() function in the docs namespace (see Reporting/custom_help.h) | |
InputStatus | getKeywordStatus (const std::string &keyword_query) const |
Test whether a keyword has been set, be that by default or user input. | |
InputStatus | getKeywordStatus (const std::string &keyword_query, const std::string &sub_key, int repeat_no=0) const |
bool | hasKeyword (const std::string &query) const |
Test whether a namelist contains a particular keyword at all. | |
bool | hasKeyword (const std::string &query, NamelistType query_kind) const |
bool | getBoolValue (const std::string &keyword_query) const |
Get the value of a boolean keyword from the within the namelist. | |
bool | getBoolValue (const std::string &keyword_query, const std::string &sub_key, int index=0) const |
int | getIntValue (const std::string &keyword_query, int index=0) const |
Get a labeled integer value from within the namelist. | |
int | getIntValue (const std::string &keyword_query, const std::string &sub_key, int index=0) const |
double | getRealValue (const std::string &keyword_query, int index=0) const |
Get a labeled real number value from within the namelist. | |
double | getRealValue (const std::string &keyword_query, const std::string &sub_key, int index=0) const |
const std::string & | getStringValue (const std::string &keyword_query, int index=0) const |
Get a labeled string value from within the namelist. | |
const std::string & | getStringValue (const std::string &keyword_query, const std::string &sub_key, int index=0) const |
template<typename T> | |
void | assignVariable (T *var, double mult, const std::string &keyword_query, int index=0) const |
Assign a value, external to the object, based on the content inside of it. This will first check whether the appropriate keyword is not missing (that is has a default value, or has been specified by the user). If the associated keyword is indeed missing, there will be no effect on the external variable. | |
template<typename T> | |
void | assignVariable (T *var, const std::string &keyword_query, int index=0) const |
void | assignVariable (std::string *var, double mult, const std::string &keyword_query, int index=0) const |
void | assignVariable (std::string *var, const std::string &keyword_query, int index=0) const |
template<typename T> | |
void | assignVariable (T *var_x, T *var_y, T *var_z, double mult, const std::string &keyword_query, int index=0) const |
template<typename T> | |
void | assignVariable (T *var_x, T *var_y, T *var_z, const std::string &keyword_query, int index=0) const |
template<typename T> | |
void | assignVariable (T *var, const std::string &keyword_query, const std::string &sub_key, int index=0) const |
template<typename T> | |
void | assignVariable (T *var, double mult, const std::string &keyword_query, const std::string &sub_key, int index=0) const |
void | assignVariable (std::string *var, double mult, const std::string &keyword_query, const std::string &sub_key, int index=0) const |
void | assignVariable (std::string *var, const std::string &keyword_query, const std::string &sub_key, int index=0) const |
template<typename T> | |
void | assignVariable (T *var_x, T *var_y, T *var_z, double mult, const std::string &keyword_query, const std::string &sub_key, int index=0) const |
template<typename T> | |
void | assignVariable (T *var_x, T *var_y, T *var_z, const std::string &keyword_query, const std::string &sub_key, int index=0) const |
void | addKeyword (const std::vector< NamelistElement > &new_keys) |
Add a keyword to the namelist. | |
void | addKeyword (const NamelistElement &new_key) |
void | addKeyword (const std::string &keyword_in, NamelistType kind_in, const std::string &default_in=std::string(""), DefaultIsObligatory obligate=DefaultIsObligatory::NO, InputRepeats rep_in=InputRepeats::NO, const std::string &help_in=std::string("No description provided")) |
void | addKeyword (const std::string keyword_in, const std::vector< std::string > &sub_keys_in, const std::vector< NamelistType > &sub_kinds_in, const std::vector< std::string > &default_list, DefaultIsObligatory obligate_list=DefaultIsObligatory::NO, InputRepeats rep_in=InputRepeats::NO, const std::string &help_in=std::string("No description provided"), const std::vector< std::string > &sub_help_in=std::vector< std::string >(1, "No description provided"), const std::vector< KeyRequirement > &template_requirements_in={}) |
void | addKeyword (const NamelistEmulator *other, const std::string &query) |
void | addKeyword (const NamelistEmulator &other, const std::string &query) |
void | addKeywords (const std::vector< NamelistElement > &new_keys) |
void | setDefaultValue (const std::string &key, const std::string &modified_default, int default_idx=0) |
Set a default value for one of the namelist's keywords. Like addDefaultValue() and other functions below, the effect will be to pass through the NamelistEmulator to. | |
void | setDefaultValue (const std::string &key, const std::vector< std::string > &modified_defaults, const std::vector< std::string > &sub_key_specs) |
void | activateBool (const std::string &key) |
Activate a BOOL-type keyword, or a BOOL-type member of a STRUCT-type keyword. These functions are analogous to assignElement() below, but because BOOL-type keywords do not take distinct values the functions that set BOOL-type variables to ON are named differently. | |
void | activateBool (const std::string &key, const std::string &sub_key) |
int | assignElement (const std::string &key, const std::string &value) |
Assign values to elements of each particular NamelistType. These overloaded functions can be called from anywhere, but constructors making control objects for programs using the STORMM libraries are the ideal place to use them. They in turn call the set(...)Value member functions of the target NamelistElement object in the NamelistEmulator. Returns 1 if the given value was successfully assigned to the label or 0 if not. | |
int | assignElement (const std::string &key, const std::string &sub_key, const std::string &value) |
void | addHelp (const std::string &blurb) |
Attach a help message to the namelist itself, to a keyword within the namelist, or even to a member variable of a STRUCT-associated keyword in the namelist. This is provided so that developers do not have to include help messages at the initialization of each namelist keyword. This will overwrite existing help messages. | |
void | addHelp (const std::string &key, const std::string &blurb) |
void | addHelp (const std::string &key, const std::string &sub_key, const std::string &blurb) |
void | setImperative (const std::string &key, KeyRequirement req) |
Change the requirement associated with a keyword. By default, all keywords are set to "REQUIRED" just as all STRUCT-type keyword subkeys are required unless stated otherwise. Even if required, many keywords, like STRUCT subkeys, will have default values that satisfy the requirements. | |
void | setImperative (const std::vector< std::string > &directives) |
void | setImperative (const std::string &key, const std::vector< std::string > &directives) |
std::string | printContents (int file_width=default_output_file_width, int max_entry_counts=4, NamelistIntroduction print_decor=NamelistIntroduction::HEADER) const |
Print a complete table of the values for all parameters in this namelist, starting including their sources (input statuses, i.e. DEFAULT, MISSING, or USER-SPECIFIED). | |
void | printContents (std::ostream *foutp, int file_width=default_output_file_width, int max_entry_counts=4, NamelistIntroduction print_decor=NamelistIntroduction::HEADER) const |
void | printContents (std::ofstream *foutp, int file_width=default_output_file_width, int max_entry_counts=4, NamelistIntroduction print_decor=NamelistIntroduction::HEADER) const |
void | printContents (const std::string &file_name, PrintSituation expectation, int file_width=default_output_file_width, int max_entry_counts=4, NamelistIntroduction print_decor=NamelistIntroduction::HEADER) const |
Collection of variables to transcribe information contained within a namelist.
stormm::namelist::NamelistEmulator::NamelistEmulator | ( | const std::string & | title_in, |
CaseSensitivity | casing_in = CaseSensitivity::AUTOMATIC, | ||
ExceptionResponse | unknown_keyword_policy = ExceptionResponse::WARN, | ||
const std::string & | help_in = std::string("No description provided"), | ||
bool | cli_content_in = false ) |
Construct an object to emulate Fortran namelist functionality, with improvements.
title_in | The title of the namelist |
casing_in | Case sensitivity to abide (default "AUTOMATIC", which in this context means that namelist titles and keywords are case insensitive but values are case sensitive) |
void stormm::namelist::NamelistEmulator::activateBool | ( | const std::string & | key | ) |
Activate a BOOL-type keyword, or a BOOL-type member of a STRUCT-type keyword. These functions are analogous to assignElement() below, but because BOOL-type keywords do not take distinct values the functions that set BOOL-type variables to ON are named differently.
Overloaded:
key | The keyword of interest |
sub_key | The sub-key of interest |
void stormm::namelist::NamelistEmulator::addCategory | ( | const std::string & | new_category | ) |
Add a category to a namelist to group its keywords for user documentation.
new_category | The name of the new keyword category |
void stormm::namelist::NamelistEmulator::addDefaultValue | ( | const std::string & | key, |
const std::string & | next_default ) |
Add a value to one keyword's default settings. This enables a single keyword to have a collection of default values. The keyword will be checked to ensure that it permits multiple values.
key | The keyword of interest |
next_default | The new value to include, as a string, to be re-interpreted as necessary |
void stormm::namelist::NamelistEmulator::addHelp | ( | const std::string & | blurb | ) |
Attach a help message to the namelist itself, to a keyword within the namelist, or even to a member variable of a STRUCT-associated keyword in the namelist. This is provided so that developers do not have to include help messages at the initialization of each namelist keyword. This will overwrite existing help messages.
Overloaded:
blurb | The help message to attach |
key | Label of the namelist keyword to which the help message gets attached |
sub_key | Label of the member variable of the STRUCT namelist keyword to which the help message gets attached |
void stormm::namelist::NamelistEmulator::addKeyword | ( | const std::vector< NamelistElement > & | new_keys | ) |
Add a keyword to the namelist.
Overloaded:
new_keys | The keywords to add |
new_key | The keyword to add |
other | Another NamelistEmulator from which to import a keyword |
query | Name of the keyword to copy from another NamelistEmulator |
int stormm::namelist::NamelistEmulator::assignElement | ( | const std::string & | key, |
const std::string & | value ) |
Assign values to elements of each particular NamelistType. These overloaded functions can be called from anywhere, but constructors making control objects for programs using the STORMM libraries are the ideal place to use them. They in turn call the set(...)Value member functions of the target NamelistElement object in the NamelistEmulator. Returns 1 if the given value was successfully assigned to the label or 0 if not.
Overloaded:
key | The keyword of interest |
sub_key | The sub-key of interest |
sub_key | The value to assign to the keyword or STRUCT sub-key |
void stormm::namelist::NamelistEmulator::assignVariable | ( | T * | var, |
double | mult, | ||
const std::string & | keyword_query, | ||
int | index = 0 ) const |
Assign a value, external to the object, based on the content inside of it. This will first check whether the appropriate keyword is not missing (that is has a default value, or has been specified by the user). If the associated keyword is indeed missing, there will be no effect on the external variable.
Overloaded:
var | The integer, real, or string ariable to assign |
mult | Multiplication factor to apply to any value extracted from the &namelist. This factor is only available for scalar results (or triplicate input extractions) and will be cast to the data type of var for integral types. |
keyword_query | The keyword associated with the input data of interest |
sub_key | The sub-key within a STRUCT associated with the input data of interest |
index | Index of the keyword repeat to retrieve |
void stormm::namelist::NamelistEmulator::categorizeKeyword | ( | const std::string & | key, |
const std::string & | category_label ) |
Place a namelist keyword into one of a list of arbitrary categories defined by the developer. This is for organizing the user documentation.
key | The namelist keyword to find and categorize |
category_label | The category to put it in |
std::string stormm::namelist::NamelistEmulator::convertDefaultToString | ( | const NamelistElement & | tkw | ) | const |
Convert the default value of a keyword to a string for output in a formatted table.
tkw | The keyword of interest |
std::vector< bool > stormm::namelist::NamelistEmulator::getAllBoolValues | ( | const std::string & | keyword_query, |
const std::string & | sub_key ) const |
Get all boolen values assigned to a particular keyword. The keyword must have STRUCT type, as the only other option for a BOOL keyword is a single value.
keyword_query | Identifier of the keyword of interest |
std::vector< int > stormm::namelist::NamelistEmulator::getAllIntValues | ( | const std::string & | keyword_query, |
const std::string & | sub_key = std::string("") ) const |
Get all integer values assigned to a particular keyword.
keyword_query | Identifier of the keyword of interest |
std::vector< double > stormm::namelist::NamelistEmulator::getAllRealValues | ( | const std::string & | keyword_query, |
const std::string & | sub_key = std::string("") ) const |
Get all real values assigned to a particular keyword.
keyword_query | Identifier of the keyword of interest |
std::vector< std::string > stormm::namelist::NamelistEmulator::getAllStringValues | ( | const std::string & | keyword_query, |
const std::string & | sub_key = std::string("") ) const |
Get all string values assigned to a particular keyword.
keyword_query | Identifier of the keyword of interest |
bool stormm::namelist::NamelistEmulator::getBoolValue | ( | const std::string & | keyword_query | ) | const |
Get the value of a boolean keyword from the within the namelist.
Overloaded:
keyword_query | Identifier of the keyword of interest |
sub_key | Identifier for the member variable within the STRUCT of interest |
index | For keywords that store multiple values, retrieve this value |
const std::string & stormm::namelist::NamelistEmulator::getHelp | ( | ) | const |
Report the help message associated with a keyword or sub-key. This can be useful for developers who wish to alert users to erroneous input.
Overloaded:
keyword_query | Identifier of the keyword of interest |
sub_key | Identifier for the member variable within the STRUCT of interest |
int stormm::namelist::NamelistEmulator::getIntValue | ( | const std::string & | keyword_query, |
int | index = 0 ) const |
Get a labeled integer value from within the namelist.
Overloaded:
keyword_query | Identifier of the keyword of interest |
sub_key | Identifier for the member variable within the STRUCT of interest |
index | For keywords that store multiple values, retrieve this value |
const std::string & stormm::namelist::NamelistEmulator::getKeyword | ( | size_t | index | ) | const |
Get a keyword from this namelist based on an index. This is for retrieving the keyword itself, not a value associated with a keyword.
index | Index of the keyword in the list held by this namelist. In fact, this is best used to step through the list of keywords in the order they were added, not much more. |
int stormm::namelist::NamelistEmulator::getKeywordEntries | ( | const std::string & | keyword_query | ) | const |
Get the number of entries associated with a specific keyword.
keyword_query | The keyword of interest |
NamelistType stormm::namelist::NamelistEmulator::getKeywordKind | ( | const std::string & | keyword_query | ) | const |
Get the type of a specific keyword within this namelist.
keyword_query | The keyword of interest |
InputStatus stormm::namelist::NamelistEmulator::getKeywordStatus | ( | const std::string & | keyword_query | ) | const |
Test whether a keyword has been set, be that by default or user input.
Overloaded:
keyword_query | The keyword of interest |
sub_key | The keyword of interest |
repeat_no | The number of the repetition to check for its status. This is needed only in the case of STRUCT-type keywords, as a plain INTEGER, REAL, or STRING keyword will be "established" if there is but one default or user-specified value given–subsequent applications of such a keyword are, by construction, established (status cannot be missing). In contrast, a STRUCT keyword can be specified many times, but the status of its individual members may still be inquestion if not all components of the STRUCT are given in each application. |
double stormm::namelist::NamelistEmulator::getRealValue | ( | const std::string & | keyword_query, |
int | index = 0 ) const |
Get a labeled real number value from within the namelist.
Overloaded:
keyword_query | Identifier of the keyword of interest |
sub_key | Identifier for the member variable within the STRUCT of interest |
index | For keywords that store multiple values, retrieve this value |
const std::string & stormm::namelist::NamelistEmulator::getStringValue | ( | const std::string & | keyword_query, |
int | index = 0 ) const |
Get a labeled string value from within the namelist.
Overloaded:
keyword_query | Identifier of the keyword of interest |
sub_key | Identifier for the member variable within the STRUCT of interest |
index | For keywords that store multiple values, retrieve this value |
bool stormm::namelist::NamelistEmulator::hasKeyword | ( | const std::string & | query | ) | const |
Test whether a namelist contains a particular keyword at all.
Overloaded:
query | The keyword to search for |
query_kind | The type that the keyword must have if it is present |
std::string stormm::namelist::NamelistEmulator::printContents | ( | int | file_width = default_output_file_width, |
int | max_entry_counts = 4, | ||
NamelistIntroduction | print_decor = NamelistIntroduction::HEADER ) const |
Print a complete table of the values for all parameters in this namelist, starting including their sources (input statuses, i.e. DEFAULT, MISSING, or USER-SPECIFIED).
Overloaded:
foutp | File to which information should be printed, defaulting to the terminal |
file_width | The width at which to print results (this parameter will be ignored and replaced with the terminal width if the output goes to the terminal) |
max_entry_reports | The maximum number of entries to report from any given keyword |
print_decor | Indicate whether to introduce the namelist or rely on some previous iteration writing to the same file |
void stormm::namelist::NamelistEmulator::printKeywordDocumentation | ( | int | p_idx, |
int | name_width, | ||
int | kw_kind_width, | ||
const std::string & | kw_dflt ) const |
Print the documentation for a specific keyword. The format is fixed in the sense that it will have a set indentation, a dash for a bullet point, and the keyword printed in a space large enough for a series of related keywords in a column.
p_idx | Index of the keyword within the namelist emulator |
name_width | Width at which to print keyword names |
kw_kind_width | Width at which to print keyword kinds |
kw_dflt | Default value of the parameter, pre-converted to a string and pre-pended with white space for alignment |
void stormm::namelist::NamelistEmulator::setCommandLineContent | ( | bool | cli_content_in = true | ) |
Set whether the namelist actually serves command line input for a whole program.
cli_content_in | Set to TRUE to indicate that the namelist does command line parsing |
void stormm::namelist::NamelistEmulator::setDefaultValue | ( | const std::string & | key, |
const std::string & | modified_default, | ||
int | default_idx = 0 ) |
Set a default value for one of the namelist's keywords. Like addDefaultValue() and other functions below, the effect will be to pass through the NamelistEmulator to.
key | The name of the keyword within the namelist |
modified_default | The new default setting to apply to the keyword |
default_idx | The index of the default to set, in the event that there are already multiple default values |
modified_defaults | The list of modified default values |
sub_key_specs | The list of sub-keys to which each default corresponds |
void stormm::namelist::NamelistEmulator::setImperative | ( | const std::string & | key, |
KeyRequirement | req ) |
Change the requirement associated with a keyword. By default, all keywords are set to "REQUIRED" just as all STRUCT-type keyword subkeys are required unless stated otherwise. Even if required, many keywords, like STRUCT subkeys, will have default values that satisfy the requirements.
Overloaded:
key | The namelist keyword to find and alter |
sub_key_query | Name of the sub-key to search if the namelist element is a STRUCT |
req | The requirement level to impose |
void stormm::namelist::NamelistEmulator::setTitle | ( | const std::string & | title_in | ) |
Set the title of the namelist.
title_in | The title to set |
void stormm::namelist::NamelistEmulator::triggerResizeBuffer | ( | const std::string & | key | ) |
When loading data for STRUCT-type keywords, the decision to increment the number of entries on file cannot be made with the first sub-key assignment. Instead, the entire struct must be read from input before the number of entries can be incremented. Because a function (readNamelist(), see input.h) that manages a NamelistEmulator loops over the input that can be associated with each list of subk-eys for a given STRUCT, that function must go through the NamelistEmulator in order to increment the keyword's entry count.
key | The STRUCT-type keyword of interest (its membership in the namelist will be verified) |