Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
ParameterMap Class Reference

A class that provides map-like access to parameter files. More...

#include <ParameterMap.h>

Classes

struct  ParamEntry
 

Public Member Functions

 ParameterMap (std::FILE *fp, int argc, char **argv, bool close_fp=false)
 
 ParameterMap (const std::string &fname, int argc, char **argv)
 
std::size_t size ()
 
bool has_param (const std::string &param)
 
template<typename T >
bool param_has_type (const std::string &param)
 
template<typename T >
value (const std::string &param)
 
bool value_or (const std::string &param, bool default_val)
 
int value_or (const std::string &param, int default_val)
 
std::int64_t value_or (const std::string &param, std::int64_t default_val)
 
double value_or (const std::string &param, double default_val)
 
std::string value_or (const std::string &param, const std::string &default_val)
 
std::string value_or (const std::string &param, const char *default_val)
 
int warn_unused_parameters (const std::set< std::string > &ignore_params, bool abort_on_warning=false, bool suppress_warning_msg=false) const
 
bool Contains_Table (std::string table_name) const
 Checks whether the specified table name was specified in the parameter file.
 
void Enforce_Table_Content_Uniform_Access_Status (std::string table_name, bool expect_unused) const
 

Detailed Description

A class that provides map-like access to parameter files.

After construction, the collection of parameters and associated values can not be mutated. However, the class is not entirely immutable; internally it tracks whether parameters have been accessed.

In contrast to formats like TOML, JSON, & YAML, the parameter files don't have syntactic typing (i.e. where the syntax determines formatting). In this sense, the format is more like ini files. As a consequence, we internally store the parameters as strings. The access API explicitly converts them to the user-specified type.

Note
We primarily support 4 datatypes: bool, std::int64_t, double, std::string.
  • For convenience, we provide support for internally casting values to int.
  • We currently do not provide support for internally casting values to float. The reason for this distinction is that within the overlapping interval of values represented by bothint and std::int64_t, values are represented with equal levels of accuracy. In contrast, for the overlapping interval of values represented by both float and double, the latter represents some values with greater accuracy.

Member Function Documentation

◆ Enforce_Table_Content_Uniform_Access_Status()

void ParameterMap::Enforce_Table_Content_Uniform_Access_Status ( std::string  table_name,
bool  expect_unused 
) const

Aborts with an error message if one or more of the parameters in the specified table has been used or has not been used. The precise details depend on the expect_unused argument.

Note
It may be better if this were a function that operated on ParameterMap rather than a method

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