5#include <initializer_list>
25 bool is_shooting =
false;
39 void set(
const std::string& name,
const std::string& value);
50 return static_cast<int>(params_.size());
62 std::optional<T>
get(
const std::string& name)
const;
66 T
get_or(
const std::string& name, T fallback)
const {
67 if (
auto v = get<T>(name)) {
73 std::string
get_or(
const std::string& name,
const char* fallback)
const;
77 bool get_yes(
const std::string& name,
bool fallback =
false)
const;
81 std::optional<bool>
get_yes_no(
const std::string& name)
const;
89 std::initializer_list<std::pair<const char*, E>> spellings)
const {
90 const auto value = get<std::string>(name);
95 for (
const auto& [spelling, option] : spellings) {
96 if (*value == spelling) {
100 allowed += (allowed.empty() ?
"'" :
", '") + std::string(spelling) +
"'";
102 class_stop_severe(
"%s = '%s' is not one of %s", name.c_str(), value->c_str(), allowed.c_str());
107 read_params_.clear();
112 return read_params_.count(name) > 0;
126 return legacy_ncdm_transmuted_;
128 void set_legacy_ncdm_transmuted() {
129 legacy_ncdm_transmuted_ =
true;
139 return single_instance_translated_;
141 void set_single_instance_translated() {
142 single_instance_translated_ =
true;
149 std::vector<std::string>
instances_with(
const std::string& field,
const std::string& value)
const;
155 std::string filename_;
156 std::vector<std::string> keys_;
157 std::map<std::string, std::string> params_;
158 mutable std::set<std::string> read_params_;
159 bool legacy_ncdm_transmuted_ =
false;
160 bool single_instance_translated_ =
false;
168 const std::function<
void(
const std::string& name,
const std::string& value,
bool read)>& fn)
173 static bool parse_line(
const std::string& line, std::string& name, std::string& value);
176 static std::vector<std::string>
split_csv(
const std::string& s);
185std::optional<int> FileContent::get<int>(
const std::string& name)
const;
187std::optional<double> FileContent::get<double>(
const std::string& name)
const;
189std::optional<std::string> FileContent::get<std::string>(
const std::string& name)
const;
191std::optional<std::vector<double>> FileContent::get<std::vector<double>>(
192 const std::string& name)
const;
194std::optional<std::vector<int>> FileContent::get<std::vector<int>>(
const std::string& name)
const;
196std::optional<std::vector<std::string>> FileContent::get<std::vector<std::string>>(
197 const std::string& name)
const;
207void parser_read_file(
const char* filename,
FileContent* pfc);
void for_each(const std::function< void(const std::string &name, const std::string &value, bool read)> &fn) const
std::vector< std::string > instances_with(const std::string &field, const std::string &value) const
static std::vector< std::string > split_csv(const std::string &s)
void mark_all_unread() const
Definition parser.h:106
void read_choice(const std::string &name, E &choice, std::initializer_list< std::pair< const char *, E > > spellings) const
Definition parser.h:87
bool was_read(const std::string &name) const
Definition parser.h:111
std::optional< bool > get_yes_no(const std::string &name) const
int size() const
Definition parser.h:49
std::vector< std::string > unread_parameters() const
static FileContent from_file(const std::string &filename)
bool legacy_ncdm_transmuted() const
Definition parser.h:125
const std::string & get_filename() const
Definition parser.h:54
T get_or(const std::string &name, T fallback) const
Definition parser.h:66
void set(const std::string &name, const std::string &value)
bool single_instance_translated() const
Definition parser.h:138
std::optional< T > get(const std::string &name) const
static bool is_instance_name(const std::string &name)
bool get_yes(const std::string &name, bool fallback=false) const
std::string get_or(const std::string &name, const char *fallback) const
static bool parse_line(const std::string &line, std::string &name, std::string &value)
FileContent & operator+=(const FileContent &other)