STORMM Source Documentation
Loading...
Searching...
No Matches
namelist_element.h
1// -*-c++-*-
2#ifndef STORMM_NAMELIST_ELEMENT_H
3#define STORMM_NAMELIST_ELEMENT_H
4
5#include <string>
6#include <vector>
7#include "copyright.h"
8#include "Constants/behavior.h"
9#include "namelist_enumerators.h"
10
11namespace stormm {
12namespace namelist {
13
14using constants::ExceptionResponse;
15
19public:
20
38 NamelistElement(const std::string &keyword_in, NamelistType kind_in,
39 const std::string &default_in = std::string(""),
40 DefaultIsObligatory obligate = DefaultIsObligatory::NO,
41 InputRepeats rep_in = InputRepeats::NO,
42 const std::string &help_in = std::string("No description provided"));
43
44 NamelistElement(const std::string keyword_in, const std::vector<std::string> &sub_keys_in,
45 const std::vector<NamelistType> &sub_kinds_in,
46 const std::vector<std::string> &default_list,
47 DefaultIsObligatory obligate_list = DefaultIsObligatory::NO,
48 InputRepeats rep_in = InputRepeats::NO,
49 const std::string &help_in = std::string("No description provided"),
50 const std::vector<std::string> &sub_help_in =
51 std::vector<std::string>(1, "No description provided"),
52 const std::vector<KeyRequirement> &template_requirements_in = {});
54
62 NamelistElement(const NamelistElement &original) = default;
63 NamelistElement(NamelistElement &&original) = default;
64 NamelistElement& operator=(const NamelistElement &original) = default;
65 NamelistElement& operator=(NamelistElement &&original) = default;
67
69 const std::string& getLabel() const;
70
72 const std::string& getSubLabel(size_t index) const;
73
81 NamelistType getKind() const;
82 NamelistType getKind(const std::string &sub_key_query) const;
84
92 void setPolicy(ExceptionResponse policy_in);
93
102 void reportNamelistTypeProblem(const std::string &caller, const std::string &data_type) const;
103
105 int getEntryCount() const;
106
122 bool getBoolValue(const std::string &member_key, int index) const;
123 bool getBoolValue() const;
124 std::vector<bool> getBoolValue(const std::string &member_key) const;
126
137 int getIntValue(const std::string &member_key, int index) const;
138 int getIntValue(int index) const;
139 std::vector<int> getIntValue(const std::string &member_key = std::string("")) const;
141
146 double getRealValue(const std::string &member_key, int index) const;
147 double getRealValue(int index) const;
148 std::vector<double> getRealValue(const std::string &member_key = std::string("")) const;
150
163 const std::string& getStringValue(const std::string &member_key, int index) const;
164 const std::string& getStringValue(int index) const;
165 std::vector<std::string> getStringValue(const std::string &member_key = std::string("")) const;
167
175 InputStatus getEstablishment(const std::string &member_key = std::string(""),
176 int repeat_no = 0) const;
177
188 KeyRequirement getImperative() const;
189 KeyRequirement getImperative(const std::string &sub_key_query) const;
191
193 bool getRepeatableValueState() const;
194
196 int getTemplateSize() const;
197
201 void badInputResponse(const std::string &errmsg, const char* caller);
202
217 void setDefaultValue(const std::string &modified_default, int default_idx = 0);
218 void setDefaultValue(const std::vector<std::string> &modified_defaults,
219 const std::vector<std::string> &sub_key_specs);
221
227 void addDefaultValue(const std::string &next_default);
228
236 void activateBool();
237 void activateBool(const std::string &su_key_query);
239
251 void setIntValue(int value);
252 void setIntValue(const std::string &member_key, int value);
254
267 void setRealValue(double value);
268 void setRealValue(const std::string &member_key, double value);
270
282 void setStringValue(const std::string &value);
283 void setStringValue(const std::string &member_key, const std::string &value);
285
295 void setImperative(const KeyRequirement imperative_in);
296 void setImperative(const std::string &sub_key_query, const KeyRequirement imperative_in);
298
299private:
300 std::string label;
301 NamelistType kind;
302 ExceptionResponse policy;
306 int next_entry_index;
313 int entry_count;
320 std::vector<bool> bool_values;
321 std::vector<int> int_values;
322 std::vector<double> real_values;
323 std::vector<std::string> string_values;
324 bool accept_multiple_values;
326 std::string help_message;
327 std::vector<std::string> sub_keys;
328 std::vector<NamelistType> sub_kinds;
330 std::vector<bool> sub_bool_values;
331 std::vector<int> sub_int_values;
332 std::vector<double> sub_real_values;
333 std::vector<std::string> sub_string_values;
334 std::vector<std::string> sub_help_messages;
336 int template_size;
340 std::vector<int> template_ints;
342 std::vector<double> template_reals;
344 std::vector<std::string> template_strings;
346
347 // Just as STRUCT-type keywords have the template_(...) arrays to store the default values of
348 // their member subkeys, STRING-, INTEGER-, and REAL-type keywords have special storage for their
349 // default(s). The default value for any BOOL member of a struct, and any BOOL keyword in
350 // general, is FALSE.
351 std::vector<int> default_int_values;
353 std::vector<double> default_real_values;
355 std::vector<std::string> default_string_values;
357
360 InputStatus establishment;
361
364 KeyRequirement imperative;
365
369 std::vector<InputStatus> template_establishment;
370
375 std::vector<KeyRequirement> template_requirements;
376
380 std::vector<InputStatus> instance_establishment;
381
384 std::vector<bool> sub_key_found;
385
390 bool defaultIsMissing(const std::string &default_input) const;
391
398 std::vector<InputStatus> setEstablishment(const std::vector<std::string> &list_of_defaults);
399
407 int validateSubKey(const std::string &sub_key_query, NamelistType nmlt,
408 const std::string &caller) const;
409
413 void resizeBuffer();
414
415 // The namelist emulator is a friend, so that excessive copying doesn't have to happen just
416 // to search and access data
417 friend struct NamelistEmulator;
418};
419
420} // namespace namelist
421} // namespace stormm
422
423#endif
void setRealValue(double value)
Set a real value within this namelist element. This function will check to ensure that the element ex...
Definition namelist_element.cpp:818
void addDefaultValue(const std::string &next_default)
Include an additional value as a default setting for a particular keyword. This enables a single keyw...
Definition namelist_element.cpp:696
void setImperative(const KeyRequirement imperative_in)
Set the requirement associated with a keyword.
Definition namelist_element.cpp:896
void setPolicy(ExceptionResponse policy_in)
Set the way that this Namelist element will respond if it encounters bad input. The member variable a...
Definition namelist_element.cpp:286
bool getRepeatableValueState() const
Report whether an element accepts multiple values.
Definition namelist_element.cpp:565
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 keyw...
Definition namelist_element.cpp:317
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.
Definition namelist_element.cpp:21
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.
Definition namelist_element.cpp:525
void activateBool()
Activate a boolean value based on the mere presence of a keyword in the namelist. This function will ...
Definition namelist_element.cpp:752
const std::string & getLabel() const
Get the keyword for a namelist element, i.e. nstlim in Amber &ctrl.
Definition namelist_element.cpp:239
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 d...
Definition namelist_element.cpp:291
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 Namelist...
Definition namelist_element.cpp:575
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 beforeha...
Definition namelist_element.cpp:588
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 i...
Definition namelist_element.cpp:472
void setStringValue(const std::string &value)
Set a string value within this namelist element. This function will check to ensure that the element ...
Definition namelist_element.cpp:858
KeyRequirement getImperative() const
Report whether a keyword has been deemed essential, optional, or bogus in a particular context....
Definition namelist_element.cpp:550
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 ...
Definition namelist_element.cpp:369
int getTemplateSize() const
Obtain the size of this namelist element's template (if it is a STRUCT)
Definition namelist_element.cpp:570
NamelistType getKind() const
Get the kind associated with a namelist element, i.e. nstlim is an INTEGER in Amber &ctrl.
Definition namelist_element.cpp:257
const std::string & getSubLabel(size_t index) const
Get a sub-key for this element.
Definition namelist_element.cpp:244
NamelistElement(const NamelistElement &original)=default
With no const members and only Standard Template Library components, the default copy and move constr...
void setIntValue(int value)
Set an integer value within this namelist element. This function will check to ensure that the elemen...
Definition namelist_element.cpp:778
int getEntryCount() const
Get the depth of the namelist element, the number of values that it stores.
Definition namelist_element.cpp:312
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 inp...
Definition namelist_element.cpp:421