11#ifndef FAUNA_INSFILE_READER_H
12#define FAUNA_INSFILE_READER_H
23typedef std::vector<std::shared_ptr<const Hft>>
HftList;
36 const std::string& value1,
const std::string& value2)
38 "Parameter '" + key + +
"' " +
39 (hft ==
"" ?
"of HFT '" + hft +
"' " :
"") +
40 "is ambiguous: there is '" + value1 +
"' or '" + value2 +
"'. " +
41 "The reason might be that the parameter can take two different "
42 "types and has then been defined twice."){};
55 const std::string& expected_size)
56 : std::runtime_error(
"Array parameter '" + key +
"' has " +
57 std::to_string(given_size) +
"'elements," +
58 " but required are: " + expected_size){};
72 const std::set<std::string>& valid_options)
84 const std::string& value,
85 const std::set<std::string>& valid_options)
90 const std::string& value,
91 const std::set<std::string>& valid_options);
101 : runtime_error(
"Missing mandatory parameter: \"" + key +
'"'){};
112 : runtime_error(
"Missing mandatory parameter \"" + key +
"\" in HFT \"" +
124 : std::runtime_error(
"Cannot find group with name \"" + group_name +
125 "\". " +
"Required by HFT \"" + hft_name +
"\"."){};
147 const std::string& allowed_interval)
148 : std::runtime_error(
"The parameter \"" + key +
"\" " +
149 "is out of range. The specified value is " + value +
150 ", which lies outside of the interval " +
151 allowed_interval +
"."){};
163 : runtime_error(
"Unknown parameters encountered:\n" +
168 const std::list<std::string> elements) {
169 std::ostringstream str;
170 for (
const auto& i : elements) str << i <<
"\n";
184 const std::string& type_found)
185 : std::runtime_error(
"The parameter \"" + key +
"\" " +
186 "is of a wrong type. I found type " + type_found +
187 ", but expected " + type_expected +
"."){};
215 const std::string& group_name)
const;
240 const std::shared_ptr<cpptoml::table>& table,
const std::string& key,
258 const std::shared_ptr<cpptoml::table>& table,
const std::string& key,
269 template <
class Expected>
271 const std::string& key)
const;
286 const std::shared_ptr<cpptoml::table>& hft_table,
const std::string& key,
287 const bool mandatory);
295 const std::shared_ptr<cpptoml::table>& hft_table,
const std::string& key,
296 const bool mandatory);
303 std::list<std::string>
get_all_keys(std::shared_ptr<cpptoml::table> table);
325 const std::string key)
const;
331 Hft read_hft(
const std::shared_ptr<cpptoml::table>& table);
334 std::shared_ptr<cpptoml::table>
ins;
One herbivore functional type (i.e. one species).
Definition: hft.h:310
Class to read parameters and HFTs from given instruction file.
Definition: insfile_reader.h:191
std::shared_ptr< T > get_value(const std::shared_ptr< cpptoml::table > &table, const std::string &key, const GetValueOpt opt=GetValueOpt::RemoveKey) const
Retrieve a single value from the TOML file.
Definition: insfile_reader.cpp:214
std::shared_ptr< cpptoml::table > get_group_table(const std::string &group_name) const
Find table with group.
Definition: insfile_reader.cpp:188
Parameters params
Definition: insfile_reader.h:347
std::shared_ptr< cpptoml::table > ins
The root table of the instruction file from cpptoml::parse_file().
Definition: insfile_reader.h:334
GetValueOpt
How to treat a parameter after it has been parsed by get_value().
Definition: insfile_reader.h:218
@ RemoveKey
Remove the parameter with remove_qualified_key().
@ KeepKey
Re-use parameter.
std::shared_ptr< T > find_hft_parameter(const std::shared_ptr< cpptoml::table > &hft_table, const std::string &key, const bool mandatory)
Retrieve HFT parameter from HFT table itself or one of its groups.
Definition: insfile_reader.cpp:257
void remove_qualified_key(std::shared_ptr< cpptoml::table > table, const std::string key) const
Remove TOML element (in order to indicate it’s been parsed).
Definition: insfile_reader.cpp:961
std::list< std::string > get_all_keys(std::shared_ptr< cpptoml::table > table)
Iterate through TOML tree and list all "leaves".
Definition: insfile_reader.cpp:328
void check_wrong_type(std::shared_ptr< cpptoml::table > table, const std::string &key) const
Throw an exception if parameter is present, but with wrong type.
Definition: insfile_reader.cpp:121
const Parameters & get_params() const
Get the global parameters that were read from the instruction file.
Definition: insfile_reader.h:206
void read_table_forage()
Read the TOML table forage.
Definition: insfile_reader.cpp:822
void read_table_output_text_tables()
Read the TOML table output.text_tables.
Definition: insfile_reader.cpp:874
Hft read_hft(const std::shared_ptr< cpptoml::table > &table)
Construct HFT object from an entry in the array of tables.
Definition: insfile_reader.cpp:349
HftList hfts
Definition: insfile_reader.h:348
void read_table_simulation()
Read the TOML table simulation.
Definition: insfile_reader.cpp:923
std::shared_ptr< std::vector< T > > get_value_array(const std::shared_ptr< cpptoml::table > &table, const std::string &key, const GetValueOpt opt=GetValueOpt::RemoveKey) const
Retrieve a value array from the TOML file.
Definition: insfile_reader.cpp:232
void read_table_output()
Read the TOML table output.
Definition: insfile_reader.cpp:838
std::shared_ptr< std::vector< T > > find_hft_array_parameter(const std::shared_ptr< cpptoml::table > &hft_table, const std::string &key, const bool mandatory)
Like find_hft_parameter(), but for an array of values.
Definition: insfile_reader.cpp:291
const HftList & get_hfts() const
Get the HFT list that was read from the instruction file.
Definition: insfile_reader.h:203
std::set< std::string > hft_keys_parsed
All TOML keys in HFTs and HFT groups that have been parsed.
Definition: insfile_reader.h:345
Exception that a parameter can be interpreted in multiple ways.
Definition: insfile_reader.h:26
ambiguous_param_type(const std::string &key, const std::string &hft, const std::string &value1, const std::string &value2)
Constructor.
Definition: insfile_reader.h:35
Exception that an array parameter does not have the correct length.
Definition: insfile_reader.h:46
bad_array_size(const std::string &key, const unsigned int given_size, const std::string &expected_size)
Constructor.
Definition: insfile_reader.h:54
Exception that a string parameter does not match possible options.
Definition: insfile_reader.h:62
std::string construct_message(const std::string &key, const std::string &value, const std::set< std::string > &valid_options)
Definition: insfile_reader.cpp:34
invalid_option(const std::string &key, const std::string &value, const std::set< std::string > &valid_options)
Constructor for global parameter.
Definition: insfile_reader.h:71
invalid_option(const Hft &hft, const std::string &key, const std::string &value, const std::set< std::string > &valid_options)
Constructor for HFT parameter.
Definition: insfile_reader.h:83
std::vector< std::shared_ptr< const Hft > > HftList
List of pointers to Hft objects.
Definition: world.h:28
Global parameters for the megafauna library.
Parameters for the herbivory module.
Definition: parameters.h:65
Exception if a group listed in hft.groups cannot be found.
Definition: insfile_reader.h:117
missing_group(const std::string &hft_name, const std::string &group_name)
Constructor.
Definition: insfile_reader.h:123
Exception that an HFT parameter is missing in the instruction file.
Definition: insfile_reader.h:105
missing_hft_parameter(const std::string &hft_name, const std::string &key)
Constructor for missing HFT parameter.
Definition: insfile_reader.h:111
Exception that a parameter is missing in the instruction file.
Definition: insfile_reader.h:95
Exception if an integer or double parameter is out of range.
Definition: insfile_reader.h:136
param_out_of_range(const std::string &key, const std::string &value, const std::string &allowed_interval)
Constructor for a double value.
Definition: insfile_reader.h:146
Exception that parameters couldn’t be parsed in the TOML file.
Definition: insfile_reader.h:155
static std::string concatenate_elements(const std::list< std::string > elements)
Concatenate list of strings with line breaks.
Definition: insfile_reader.h:167
unknown_parameters(const std::list< std::string > elements)
Constructor.
Definition: insfile_reader.h:162
Exception that a parameter is not of an expected data type.
Definition: insfile_reader.h:176
wrong_param_type(const std::string &key, const std::string &type_expected, const std::string &type_found)
Constructor.
Definition: insfile_reader.h:183