STORMM Source Documentation
Loading...
Searching...
No Matches
stormm::namelist::NamelistElement Class Reference

One keyword found in a namelist, ready to store the namelist variable moniker, the type, and the value read from the input file. More...

#include <namelist_element.h>

Public Member Functions

const std::string & getLabel () const
 Get the keyword for a namelist element, i.e. nstlim in Amber &ctrl.
 
const std::string & getSubLabel (size_t index) const
 Get a sub-key for this element.
 
void setPolicy (ExceptionResponse policy_in)
 Set the way that this Namelist element will respond if it encounters bad input. The member variable associated with this function is not passed down as part of the constructor argument list, and would be tedious for the developer to enter over and over, so it is passed down based on the NamelistEmulator's own setting by calling this function.
 
void reportNamelistTypeProblem (const std::string &caller, const std::string &data_type) const
 Report an error based on an incorrect namelist element data type request. This is an assertion that debugs a program when a developer makes a mistake, not something that an end user should encounter, but it's helpful to have a more detailed description than assert() can provide. This always ends by throwing a runtime error and so is an acceptable way to fill a switch case.
 
int getEntryCount () const
 Get the depth of the namelist element, the number of values that it stores.
 
InputStatus getEstablishment (const std::string &member_key=std::string(""), int repeat_no=0) const
 Report whether a value has been assigned, read from input, to this namelist element.
 
bool getRepeatableValueState () const
 Report whether an element accepts multiple values.
 
int getTemplateSize () const
 Obtain the size of this namelist element's template (if it is a STRUCT)
 
void badInputResponse (const std::string &errmsg, const char *caller)
 Respond to bad user input at the NamelistElement level, based on a policy handed down from a NamelistEmulator. This does not apply to developer-level mistakes, which always throw runtime errors.
 
void addDefaultValue (const std::string &next_default)
 Include an additional value as a default setting for a particular keyword. This enables a single keyword to have a default series of values. The supplied value will be interpreted according to the type of the element.
 
 NamelistElement (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"))
 Constructor for a non-STRUCT NamelistElement.
 
 NamelistElement (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={})
 
 NamelistElement (const NamelistElement &original)=default
 With no const members and only Standard Template Library components, the default copy and move constructors, as well as the copy and move assignment operators, are valid.
 
 NamelistElement (NamelistElement &&original)=default
 
NamelistElementoperator= (const NamelistElement &original)=default
 
NamelistElementoperator= (NamelistElement &&original)=default
 
NamelistType getKind () const
 Get the kind associated with a namelist element, i.e. nstlim is an INTEGER in Amber &ctrl.
 
NamelistType getKind (const std::string &sub_key_query) const
 
bool getBoolValue (const std::string &member_key, int index) const
 Get the boolean value to which a namelist element has been set (this value is set to TRUE if the keyword was found in the namelist or collection of STRUCT sub-keys, FALSE if not).
 
bool getBoolValue () const
 
std::vector< bool > getBoolValue (const std::string &member_key) const
 
int getIntValue (const std::string &member_key, int index) const
 Get the integer value to which a namelist element has been set (this value is read from the namelist input file, i.e. mdin). Descriptions of input parameters follow from getBoolValue(), above.
 
int getIntValue (int index) const
 
std::vector< int > getIntValue (const std::string &member_key=std::string("")) const
 
double getRealValue (const std::string &member_key, int index) const
 Get the real value to which a namelist element has been set (this value is read from the namelist input file, i.e. mdin). Overloading and descriptions of input parameters follow from getIntegerValue()
 
double getRealValue (int index) const
 
std::vector< double > getRealValue (const std::string &member_key=std::string("")) const
 
const std::string & getStringValue (const std::string &member_key, int index) const
 Get the string value to which a namelist element has been set (this value is read from the namelist input file, i.e. mdin)
 
const std::string & getStringValue (int index) const
 
std::vector< std::string > getStringValue (const std::string &member_key=std::string("")) const
 
KeyRequirement getImperative () const
 Report whether a keyword has been deemed essential, optional, or bogus in a particular context. This enables the same namelist to take on different profiles in different applications, and to report only that data which is relevant in the program output.
 
KeyRequirement getImperative (const std::string &sub_key_query) const
 
void setDefaultValue (const std::string &modified_default, int default_idx=0)
 Set the default value for a particular keyword, overriding anything that might have been set beforehand. This can be useful when applying common keyword loading functions, to adapt the namelist elements for a specific program or context.
 
void setDefaultValue (const std::vector< std::string > &modified_defaults, const std::vector< std::string > &sub_key_specs)
 
void activateBool ()
 Activate a boolean value based on the mere presence of a keyword in the namelist. This function will check to verify that the keyword is a boolean.
 
void activateBool (const std::string &su_key_query)
 
void setIntValue (int value)
 Set an integer value within this namelist element. This function will check to ensure that the element expects an int.
 
void setIntValue (const std::string &member_key, int value)
 
void setRealValue (double value)
 Set a real value within this namelist element. This function will check to ensure that the element expects a real number.
 
void setRealValue (const std::string &member_key, double value)
 
void setStringValue (const std::string &value)
 Set a string value within this namelist element. This function will check to ensure that the element expects a string value.
 
void setStringValue (const std::string &member_key, const std::string &value)
 
void setImperative (const KeyRequirement imperative_in)
 Set the requirement associated with a keyword.
 
void setImperative (const std::string &sub_key_query, const KeyRequirement imperative_in)
 

Friends

struct NamelistEmulator
 

Detailed Description

One keyword found in a namelist, ready to store the namelist variable moniker, the type, and the value read from the input file.

Constructor & Destructor Documentation

◆ NamelistElement() [1/2]

stormm::namelist::NamelistElement::NamelistElement ( 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") )

Constructor for a non-STRUCT NamelistElement.

Overloaded:

  • Constructor for INTEGER, REAL, and STRING keywords (not STRUCTs)
  • Constructor for STRUCT keywords
Parameters
keyword_inThe name of the namelist variable
sub_keys_inThe name of STRUCT members within the namelist variable
kind_inThe kind of the namelist element (it will be checked to ensure that it is not STRUCT)
sub_kinds_inThe kinds of STRUCT members (the namelist variable itself is a STRUCT if this input argument is a vector)
rep_inFlag to indicate whether the namelist input can repeat for additional values
help_inUser documentation for the keyword
sub_help_inUser documentation for sub-keys

◆ NamelistElement() [2/2]

stormm::namelist::NamelistElement::NamelistElement ( const NamelistElement & original)
default

With no const members and only Standard Template Library components, the default copy and move constructors, as well as the copy and move assignment operators, are valid.

Parameters
originalThe pre-existing object to copy or move
otherA pre-existing object to fulfill the right hand side of an assignment statement

Member Function Documentation

◆ activateBool()

void stormm::namelist::NamelistElement::activateBool ( )

Activate a boolean value based on the mere presence of a keyword in the namelist. This function will check to verify that the keyword is a boolean.

Overloaded:

  • Take a the keyword name
  • Take a sub-keyword and a value to fill in a BOOL member of a STRUCT kind element

◆ addDefaultValue()

void stormm::namelist::NamelistElement::addDefaultValue ( const std::string & next_default)

Include an additional value as a default setting for a particular keyword. This enables a single keyword to have a default series of values. The supplied value will be interpreted according to the type of the element.

Parameters
next_defaultThe extra default value to include

◆ getBoolValue()

bool stormm::namelist::NamelistElement::getBoolValue ( const std::string & member_key,
int index ) const

Get the boolean value to which a namelist element has been set (this value is set to TRUE if the keyword was found in the namelist or collection of STRUCT sub-keys, FALSE if not).

Overloaded:

  • Take a STRUCT member variable name and the index of the particular STRUCT entry
  • Return the boolean value of the one and only valid entry of a non-STRUCT keyword
  • Return all BOOL values associated with a boolean member of a STRUCT keyword, which could have multiple entries
Parameters
member_keyThe (optional) name of a STRUCT member to access (an empty string indicates that the keyword is associated with INTEGER, REAL, or STRING data)
indexThe entry to access

◆ getEstablishment()

InputStatus stormm::namelist::NamelistElement::getEstablishment ( const std::string & member_key = std::string(""),
int repeat_no = 0 ) const

Report whether a value has been assigned, read from input, to this namelist element.

Parameters
member_keyName of the sub-key to search if the namelist element is a STRUCT
repeat_noIndex number of the repeated keyword application, if applicable. The establishment of a member keyword in the fourth application of a repeatable STRUCT keyword will be found in element 4 * (template_size) + member_idx of the input status array.

◆ getImperative()

KeyRequirement stormm::namelist::NamelistElement::getImperative ( ) const

Report whether a keyword has been deemed essential, optional, or bogus in a particular context. This enables the same namelist to take on different profiles in different applications, and to report only that data which is relevant in the program output.

Overloaded:

  • Get the criticality of the keyword
  • Get the criticality of a subkey within a STRUCT keyword
Parameters
sub_key_queryName of the sub-key to search if the namelist element is a STRUCT

◆ getIntValue()

int stormm::namelist::NamelistElement::getIntValue ( const std::string & member_key,
int index ) const

Get the integer value to which a namelist element has been set (this value is read from the namelist input file, i.e. mdin). Descriptions of input parameters follow from getBoolValue(), above.

Overloaded:

  • Take a STRUCT member variable name and the index of the particular STRUCT entry
  • Take an index only and return the integer value (the namelist element must be a non-STRUCT)
  • Return all INTEGER values associated with this keyword

◆ getKind()

NamelistType stormm::namelist::NamelistElement::getKind ( ) const

Get the kind associated with a namelist element, i.e. nstlim is an INTEGER in Amber &ctrl.

Overloaded:

  • Get the kind of the element itself
  • Take the name of a sub-key to retrieve the kind of a member variable from a STRUCT

◆ getStringValue()

const std::string & stormm::namelist::NamelistElement::getStringValue ( const std::string & member_key,
int index ) const

Get the string value to which a namelist element has been set (this value is read from the namelist input file, i.e. mdin)

Overloaded:

  • Take a STRUCT member variable name and the index of the particular STRUCT entry
  • Take an index only and return the string value (the namelist element must be a non-STRUCT)
  • Return all STRING values associated with this keyword
Parameters
member_keyThe (optional) name of a STRUCT member to access
indexThe entry to access

◆ reportNamelistTypeProblem()

void stormm::namelist::NamelistElement::reportNamelistTypeProblem ( const std::string & caller,
const std::string & data_type ) const

Report an error based on an incorrect namelist element data type request. This is an assertion that debugs a program when a developer makes a mistake, not something that an end user should encounter, but it's helpful to have a more detailed description than assert() can provide. This always ends by throwing a runtime error and so is an acceptable way to fill a switch case.

Parameters
callerThe name of the member function of NamelistElement calling this error
data_typeThe name of the (erroneously) requested data type

◆ setDefaultValue()

void stormm::namelist::NamelistElement::setDefaultValue ( const std::string & modified_default,
int default_idx = 0 )

Set the default value for a particular keyword, overriding anything that might have been set beforehand. This can be useful when applying common keyword loading functions, to adapt the namelist elements for a specific program or context.

Overloaded:

  • Set the default value for a non-STRUCT keyword
  • Set the default values for various sub-keys of a STRUCT keyword
Parameters
modified_defaultThe new default setting to apply to the keyword
default_idxThe index of the default to set, in the event that there are already multiple default values
modified_defaultsThe list of modified default values
sub_key_specsThe list of sub-keys to which each default corresponds

◆ setImperative()

void stormm::namelist::NamelistElement::setImperative ( const KeyRequirement imperative_in)

Set the requirement associated with a keyword.

Overloaded:

  • Set the criticality of a keyword
  • Set the criticality of a subkey within a STRUCT-type keyword
Parameters
imperative_inThe criticality level of the keyword to set. Is it required, optional, or bogus in some context?

◆ setIntValue()

void stormm::namelist::NamelistElement::setIntValue ( int value)

Set an integer value within this namelist element. This function will check to ensure that the element expects an int.

Overloaded:

  • Take a sub-keyword and a value to fill in an INTEGER member of a STRUCT kind element
  • Take a value only
Parameters
member_keyIf given, implies that the namelist element is a struct, and triggers a search through its members to find a match and finally place the int.
valueThe value of the keyword or sub-key

◆ setPolicy()

void stormm::namelist::NamelistElement::setPolicy ( ExceptionResponse policy_in)

Set the way that this Namelist element will respond if it encounters bad input. The member variable associated with this function is not passed down as part of the constructor argument list, and would be tedious for the developer to enter over and over, so it is passed down based on the NamelistEmulator's own setting by calling this function.

Parameters
policy_inThe policy to set

◆ setRealValue()

void stormm::namelist::NamelistElement::setRealValue ( double value)

Set a real value within this namelist element. This function will check to ensure that the element expects a real number.

Overloaded:

  • Take a sub-keyword and a value to fill in a REAL member of a STRUCT kind element
  • Take a value only
Parameters
member_keyIf given, implies that the namelist element is a struct, and triggers a search through its members to find a match and finally place the real number.
valueThe value of the keyword or sub-key

◆ setStringValue()

void stormm::namelist::NamelistElement::setStringValue ( const std::string & value)

Set a string value within this namelist element. This function will check to ensure that the element expects a string value.

Overloaded:

  • Take a sub-keyword and a value to fill in a STRING member of a STRUCT kind element
  • Take a value only
Parameters
member_keyIf given, implies that the namelist element is a struct, and triggers a search through its members to find a match and finally place the string.
valueThe value of the keyword or sub-key

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