Class to read parameters and HFTs from given instruction file.
More...
#include <insfile_reader.h>
|
| std::shared_ptr< cpptoml::table > | get_group_table (const std::string &group_name) const |
| | Find table with group. More...
|
| |
| template<class T > |
| 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. More...
|
| |
| template<class T > |
| 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. More...
|
| |
| template<class Expected > |
| 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. More...
|
| |
| template<class T > |
| 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. More...
|
| |
| template<class T > |
| 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. More...
|
| |
| std::list< std::string > | get_all_keys (std::shared_ptr< cpptoml::table > table) |
| | Iterate through TOML tree and list all "leaves". More...
|
| |
| void | read_table_forage () |
| | Read the TOML table forage. More...
|
| |
| void | read_table_output () |
| | Read the TOML table output. More...
|
| |
| void | read_table_output_text_tables () |
| | Read the TOML table output.text_tables. More...
|
| |
| void | read_table_simulation () |
| | Read the TOML table simulation. More...
|
| |
| 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). More...
|
| |
| Hft | read_hft (const std::shared_ptr< cpptoml::table > &table) |
| | Construct HFT object from an entry in the array of tables. More...
|
| |
Class to read parameters and HFTs from given instruction file.
◆ GetValueOpt
How to treat a parameter after it has been parsed by get_value().
◆ InsfileReader()
| InsfileReader::InsfileReader |
( |
const std::string |
filename | ) |
|
Constructor.
- Parameters
-
| [in] | filename | Relative or absolute file path to the instruction file. |
- Exceptions
-
| std::runtime_error | If the instruction file cannot be parsed completely, contains logical errors, or has missing parameters. |
◆ check_wrong_type()
template<class Expected >
| void InsfileReader::check_wrong_type |
( |
std::shared_ptr< cpptoml::table > |
table, |
|
|
const std::string & |
key |
|
) |
| const |
|
private |
Throw an exception if parameter is present, but with wrong type.
- Parameters
-
| table | The TOML table to search through. This could be ins or an HFT table for instance. |
| key | The fully qualified TOML key. |
- Template Parameters
-
| Expected | Expected type of the parameter key. |
- Exceptions
-
◆ find_hft_array_parameter()
template<class T >
| std::shared_ptr< std::vector< T > > InsfileReader::find_hft_array_parameter |
( |
const std::shared_ptr< cpptoml::table > & |
hft_table, |
|
|
const std::string & |
key, |
|
|
const bool |
mandatory |
|
) |
| |
|
private |
Like find_hft_parameter(), but for an array of values.
Retrieve HFT parameter from HFT table itself or one of its groups.
If the key is not defined in the HFT itself, the groups are checked in the order they are defined until the value is found.
- Parameters
-
| hft_table | The TOML table of the HFT itself. |
| key | The string identifier of the parameter, e.g. "digestion.limit". |
| mandatory | Whether to throw missing_parameter if the value couldn’t be found. |
- Returns
- A pointer to the value. If the value wasn’t found and is not mandatory, the result is
NULL.
◆ find_hft_parameter()
template<class T >
| std::shared_ptr< T > InsfileReader::find_hft_parameter |
( |
const std::shared_ptr< cpptoml::table > & |
hft_table, |
|
|
const std::string & |
key, |
|
|
const bool |
mandatory |
|
) |
| |
|
private |
Retrieve HFT parameter from HFT table itself or one of its groups.
If the key is not defined in the HFT itself, the groups are checked in the order they are defined until the value is found.
- Parameters
-
| hft_table | The TOML table of the HFT itself. |
| key | The string identifier of the parameter, e.g. "digestion.limit". |
| mandatory | Whether to throw missing_parameter if the value couldn’t be found. |
- Returns
- A pointer to the value. If the value wasn’t found and is not mandatory, the result is
NULL.
◆ get_all_keys()
| std::list< std::string > InsfileReader::get_all_keys |
( |
std::shared_ptr< cpptoml::table > |
table | ) |
|
|
private |
Iterate through TOML tree and list all "leaves".
- Parameters
-
| table | A TOML tree or subtree. |
- Returns
- A list of fully qualified TOML keys.
◆ get_group_table()
| std::shared_ptr< cpptoml::table > InsfileReader::get_group_table |
( |
const std::string & |
group_name | ) |
const |
|
private |
Find table with group.
- Parameters
-
| group_name | The name of the group. |
- Returns
- Pointer to the group. NULL if group was not found.
◆ get_hfts()
| const HftList & Fauna::InsfileReader::get_hfts |
( |
| ) |
const |
|
inline |
Get the HFT list that was read from the instruction file.
◆ get_params()
| const Parameters & Fauna::InsfileReader::get_params |
( |
| ) |
const |
|
inline |
Get the global parameters that were read from the instruction file.
◆ get_value()
template<class T >
| std::shared_ptr< T > InsfileReader::get_value |
( |
const std::shared_ptr< cpptoml::table > & |
table, |
|
|
const std::string & |
key, |
|
|
const GetValueOpt |
opt = GetValueOpt::RemoveKey |
|
) |
| const |
|
private |
Retrieve a single value from the TOML file.
- Parameters
-
| table | The TOML table to read from. Normally this is just the TOML file ins, but for table arrays, this is might be one HFT table for instance. |
| key | The TOML key, qualified as a child of table. |
| opt | Whether to remove with remove_qualified_key() or keep the key. |
- Template Parameters
-
| T | Expected type of the parameter key. |
- Exceptions
-
◆ get_value_array()
template<class T >
| std::shared_ptr< std::vector< T > > InsfileReader::get_value_array |
( |
const std::shared_ptr< cpptoml::table > & |
table, |
|
|
const std::string & |
key, |
|
|
const GetValueOpt |
opt = GetValueOpt::RemoveKey |
|
) |
| const |
|
private |
Retrieve a value array from the TOML file.
- Parameters
-
| table | The TOML table to read from. Normally this is just the TOML file ins, but for table arrays, this is might be one HFT table for instance. |
| key | The TOML key, qualified as a child of table. |
| opt | Whether to remove with remove_qualified_key() or keep the key. |
- Template Parameters
-
| T | Expected type of the parameter key. |
- Exceptions
-
◆ read_hft()
| Hft InsfileReader::read_hft |
( |
const std::shared_ptr< cpptoml::table > & |
table | ) |
|
|
private |
Construct HFT object from an entry in the array of tables.
- Exceptions
-
| std::invalid_argument | If table is NULL. |
◆ read_table_forage()
| void InsfileReader::read_table_forage |
( |
| ) |
|
|
private |
Read the TOML table forage.
◆ read_table_output()
| void InsfileReader::read_table_output |
( |
| ) |
|
|
private |
Read the TOML table output.
◆ read_table_output_text_tables()
| void InsfileReader::read_table_output_text_tables |
( |
| ) |
|
|
private |
Read the TOML table output.text_tables.
◆ read_table_simulation()
| void InsfileReader::read_table_simulation |
( |
| ) |
|
|
private |
Read the TOML table simulation.
◆ remove_qualified_key()
| void InsfileReader::remove_qualified_key |
( |
std::shared_ptr< cpptoml::table > |
table, |
|
|
const std::string |
key |
|
) |
| const |
|
private |
Remove TOML element (in order to indicate it’s been parsed).
- Parameters
-
| table | A TOML (sub)tree. |
| key | A fully qualified TOML key that should exist in table. |
- Exceptions
-
| std::invalid_argument | If table is NULL. |
| std::out_of_range | If key couldn’t be found. |
◆ hft_keys_parsed
| std::set<std::string> Fauna::InsfileReader::hft_keys_parsed |
|
private |
All TOML keys in HFTs and HFT groups that have been parsed.
In general, TOML elements are erased from ins as soon as they have been parsed. Any remaining keys/elements are unknown and issue an error. However, parameters in HFT groups may be read several times. Therefore they need to be erased after all HFTs have been read. This variable keeps track of all valid keys so that they can be removed from the HFT groups in the end.
◆ hfts
◆ ins
| std::shared_ptr<cpptoml::table> Fauna::InsfileReader::ins |
|
private |
The root table of the instruction file from cpptoml::parse_file().
◆ params
The documentation for this class was generated from the following files:
- /home/docs/checkouts/readthedocs.org/user_builds/modular-megafauna-model/checkouts/latest/src/Fauna/insfile_reader.h
- /home/docs/checkouts/readthedocs.org/user_builds/modular-megafauna-model/checkouts/latest/src/Fauna/insfile_reader.cpp