13#ifndef dealii_parameter_handler_h
14#define dealii_parameter_handler_h
23#include <boost/archive/basic_archive.hpp>
24#include <boost/property_tree/ptree_fwd.hpp>
25#include <boost/property_tree/ptree_serialization.hpp>
26#include <boost/serialization/split_member.hpp>
1015 const std::string &filename =
"input file",
1016 const std::string &last_line =
"",
1017 const bool skip_undefined =
false);
1042 const std::string &last_line =
"",
1043 const bool skip_undefined =
false,
1044 const bool assert_mandatory_entries_are_found =
false);
1056 const std::string &last_line =
"",
1057 const bool skip_undefined =
false);
1113 const std::string &default_value,
1115 const std::string &documentation =
"",
1116 const bool has_to_be_set =
false);
1187 const std::function<
void(
const std::string &value)> &action,
1188 const bool execute_action =
true);
1205 template <
typename ParameterType>
1208 ParameterType ¶meter,
1209 const std::string &documentation =
"",
1212 const bool has_to_be_set =
false);
1259 const std::string &alias_name,
1260 const bool alias_is_deprecated =
false);
1267 const bool create_path_if_needed =
true);
1310 const std::string &name)
const;
1318 get(
const std::string &entry_string)
const;
1331 get(
const std::vector<std::string> &entry_subsection_path,
1332 const std::string &entry_string)
const;
1340 get_integer(
const std::string &entry_string)
const;
1351 get_integer(
const std::vector<std::string> &entry_subsection_path,
1352 const std::string &entry_string)
const;
1358 get_double(
const std::string &entry_name)
const;
1367 get_double(
const std::vector<std::string> &entry_subsection_path,
1368 const std::string &entry_string)
const;
1375 get_bool(
const std::string &entry_name)
const;
1386 get_bool(
const std::vector<std::string> &entry_subsection_path,
1387 const std::string &entry_string)
const;
1399 set(
const std::string &entry_name,
const std::string &new_value);
1412 set(
const std::string &entry_name,
const char *new_value);
1424 set(
const std::string &entry_name,
const long int new_value);
1440 set(
const std::string &entry_name,
const double new_value);
1452 set(
const std::string &entry_name,
const bool new_value);
1606 template <
class Archive>
1608 save(Archive &ar,
const unsigned int version)
const;
1615 template <
class Archive>
1617 load(Archive &ar,
const unsigned int version);
1625 template <
class Archive>
1631 BOOST_SERIALIZATION_SPLIT_MEMBER()
1648 std::set<std::string>
1669 <<
"The following entry already exists: " << arg1 <<
'.');
1678 <<
"Line <" << arg1 <<
"> of file <" << arg2 <<
">: "
1679 <<
"Entry <" << arg3 <<
"> is deprecated.");
1686 <<
"The following deprecated entries were encountered:\n\n"
1695 <<
"The string <" << arg1
1696 <<
"> does not match the given pattern <" << arg2 <<
">.");
1702 "You can't leave a subsection if you are already at the top level "
1703 "of the subsection hierarchy.");
1710 <<
"You can't ask for entry <" << arg1
1711 <<
"> you have not yet declared.");
1722 <<
"There are unequal numbers of 'subsection' and 'end' "
1723 "statements in the parameter file"
1724 << (arg1.empty() ?
"" : (
" <" + arg1 +
">")) <<
"."
1725 << (arg2.empty() ?
"" : (
"\n" + arg2)));
1735 <<
"Line <" << arg1 <<
">"
1736 << (arg2.empty() ?
"" : (
" of file <" + arg2 +
">"))
1737 <<
": You are trying to enter a subsection '" << arg3
1738 <<
"', but the ParameterHandler object does "
1739 <<
"not know of any such subsection.");
1750 <<
"Line <" << arg1 <<
">"
1751 << (arg2.empty() ?
"" : (
" of file <" + arg2 +
">")) <<
": "
1766 <<
"In line <" << arg1 <<
">"
1767 << (arg2.empty() ?
"" : (
" of file <" + arg2 +
">")) <<
": The value <"
1768 << arg3 <<
"> for the parameter entry named <" << arg4
1769 <<
"> does not match the pattern expected for this parameter.\n"
1770 "The expected pattern for this parameter is:\n"
1779 "The provided file could not be parsed as a "
1780 "ParameterHandler description.");
1793 <<
"Line <" << arg1 <<
">"
1794 << (arg2.empty() ?
"" : (
" of file <" + arg2 +
">"))
1796 "contains an 'include' or 'INCLUDE' statement, but the given "
1798 << arg3 <<
"> cannot be opened.");
1822 std::unique_ptr<boost::property_tree::ptree>
entries;
1839 std::vector<std::unique_ptr<const Patterns::PatternBase>>
patterns;
1847 std::vector<std::function<void(
const std::string &)>>
actions;
1869 const std::string &input_filename,
1870 const unsigned int current_line_n,
1871 const bool skip_undefined);
1886 const boost::property_tree::ptree &tree,
1887 const std::vector<std::string> &target_subsection_path,
1889 const unsigned int indent_level,
1890 std::ostream &out)
const;
1907 static_cast<unsigned int>(f1) |
static_cast<unsigned int>(f2));
2189 const std::string &filename =
"input file",
2190 const std::string &last_line =
"",
2191 const bool skip_undefined =
false)
override;
2251 Entry(
const std::vector<std::string> &Path,
2252 const std::string &Name,
2253 const std::string &Value);
2330template <
class Archive>
2340 std::vector<std::string> descriptions;
2342 descriptions.reserve(
patterns.size());
2343 for (
const auto &pattern :
patterns)
2344 descriptions.push_back(pattern->description());
2350template <
class Archive>
2360 std::vector<std::string> descriptions;
2364 for (
const auto &description : descriptions)
2369template <
typename ParameterType>
2372 ParameterType ¶meter,
2373 const std::string &documentation,
2375 const bool has_to_be_set)
2377 static_assert(std::is_const_v<ParameterType> ==
false,
2378 "You tried to add a parameter using a type "
2379 "that is const. Use a non-const type.");
2389 const unsigned int pattern_index =
2392 auto action = [&, pattern_index](
const std::string &val) {
std::vector< std::string > subsection_path
std::vector< std::string > different_values
void split_different_values()
std::size_t memory_consumption() const
virtual void create_new(const unsigned int run_no)=0
virtual void run(ParameterHandler &prm)=0
virtual ~UserClass()=default
void init_branches_current_section()
void fill_entry_values(const unsigned int run_no)
virtual void parse_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="", const bool skip_undefined=false) override
std::size_t memory_consumption() const
virtual ~MultipleParameterLoop() override=default
std::vector< Entry > multiple_choices
static const char path_separator
std::size_t memory_consumption() const
void add_parameter(const std::string &entry, ParameterType ¶meter, const std::string &documentation="", const Patterns::PatternBase &pattern= *Patterns::Tools::Convert< ParameterType >::to_pattern(), const bool has_to_be_set=false)
void load(Archive &ar, const unsigned int version)
virtual void parse_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="", const bool skip_undefined=false)
virtual void parse_input_from_xml(std::istream &input, const bool skip_undefined=false)
std::string get_current_path() const
ParameterHandler(const ParameterHandler &)=delete
std::vector< std::unique_ptr< const Patterns::PatternBase > > patterns
void enter_subsection(const std::string &subsection, const bool create_path_if_needed=true)
std::ostream & print_parameters(std::ostream &out, const OutputStyle style) const
void recursively_print_parameters(const boost::property_tree::ptree &tree, const std::vector< std::string > &target_subsection_path, const ParameterHandler::OutputStyle style, const unsigned int indent_level, std::ostream &out) const
void add_action(const std::string &entry, const std::function< void(const std::string &value)> &action, const bool execute_action=true)
void save(Archive &ar, const unsigned int version) const
long int get_integer(const std::string &entry_string) const
bool get_bool(const std::string &entry_name) const
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation="", const bool has_to_be_set=false)
virtual void parse_input_from_string(const std::string &s, const std::string &last_line="", const bool skip_undefined=false)
std::string get(const std::string &entry_string) const
std::set< std::string > get_entries_wrongly_not_set() const
void set(const std::string &entry_name, const std::string &new_value)
void log_parameters(LogStream &out, const OutputStyle style=DefaultStyle)
void serialize(Archive &archive, const unsigned int version)
std::map< std::string, std::pair< bool, bool > > entries_set_status
std::string get_current_full_path(const std::string &name) const
ParameterHandler & operator=(const ParameterHandler &)=delete
void mark_as_deprecated(const std::string &entry, const bool is_deprecated=true)
std::vector< std::function< void(const std::string &)> > actions
void log_parameters_section(LogStream &out, const OutputStyle style=DefaultStyle)
std::unique_ptr< boost::property_tree::ptree > entries
bool subsection_path_exists(const std::vector< std::string > &sub_path) const
virtual ~ParameterHandler() override=default
void scan_line(std::string line, const std::string &input_filename, const unsigned int current_line_n, const bool skip_undefined)
double get_double(const std::string &entry_name) const
void declare_alias(const std::string &existing_entry_name, const std::string &alias_name, const bool alias_is_deprecated=false)
bool operator==(const ParameterHandler &prm2) const
std::vector< std::string > subsection_path
void assert_that_entries_have_been_set() const
virtual void parse_input_from_json(std::istream &input, const bool skip_undefined=false)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNoSubsection(int arg1, std::string arg2, std::string arg3)
static ::ExceptionBase & ExcCannotOpenIncludeStatementFile(int arg1, std::string arg2, std::string arg3)
static ::ExceptionBase & ExcEntryAlreadyExists(std::string arg1)
static ::ExceptionBase & ExcEntryIsDeprecated(int arg1, std::string arg2, std::string arg3)
static ::ExceptionBase & ExcEncounteredDeprecatedEntries(std::string arg1)
static ::ExceptionBase & ExcAlreadyAtTopLevel()
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcInvalidEntryForPattern(int arg1, std::string arg2, std::string arg3, std::string arg4, std::string arg5)
static ::ExceptionBase & ExcEntryUndeclared(std::string arg1)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcValueDoesNotMatchPattern(std::string arg1, std::string arg2)
static ::ExceptionBase & ExcUnbalancedSubsections(std::string arg1, std::string arg2)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcCannotParseLine(int arg1, std::string arg2, std::string arg3)
static ::ExceptionBase & ExcInvalidXMLParameterFile()
#define DeclException5( Exception5, type1, type2, type3, type4, type5, outsequence)
std::unique_ptr< PatternBase > pattern_factory(const std::string &description)
ParameterHandler::OutputStyle operator|(const ParameterHandler::OutputStyle f1, const ParameterHandler::OutputStyle f2)