15#ifndef dealii_parameter_handler_h
16#define dealii_parameter_handler_h
25#include <boost/archive/basic_archive.hpp>
26#include <boost/property_tree/ptree_fwd.hpp>
27#include <boost/property_tree/ptree_serialization.hpp>
28#include <boost/serialization/split_member.hpp>
1016 const std::string &filename =
"input file",
1017 const std::string &last_line =
"",
1018 const bool skip_undefined =
false);
1043 const std::string &last_line =
"",
1044 const bool skip_undefined =
false,
1045 const bool assert_mandatory_entries_are_found =
false);
1057 const std::string &last_line =
"",
1058 const bool skip_undefined =
false);
1114 const std::string &default_value,
1116 const std::string &documentation =
"",
1117 const bool has_to_be_set =
false);
1188 const std::function<
void(
const std::string &value)> &action,
1189 const bool execute_action =
true);
1206 template <
typename ParameterType>
1209 ParameterType ¶meter,
1210 const std::string &documentation =
"",
1213 const bool has_to_be_set =
false);
1260 const std::string &alias_name,
1261 const bool alias_is_deprecated =
false);
1268 const bool create_path_if_needed =
true);
1311 const std::string &name)
const;
1319 get(
const std::string &entry_string)
const;
1332 get(
const std::vector<std::string> &entry_subsection_path,
1333 const std::string &entry_string)
const;
1341 get_integer(
const std::string &entry_string)
const;
1352 get_integer(
const std::vector<std::string> &entry_subsection_path,
1353 const std::string &entry_string)
const;
1359 get_double(
const std::string &entry_name)
const;
1368 get_double(
const std::vector<std::string> &entry_subsection_path,
1369 const std::string &entry_string)
const;
1376 get_bool(
const std::string &entry_name)
const;
1387 get_bool(
const std::vector<std::string> &entry_subsection_path,
1388 const std::string &entry_string)
const;
1400 set(
const std::string &entry_name,
const std::string &new_value);
1413 set(
const std::string &entry_name,
const char *new_value);
1425 set(
const std::string &entry_name,
const long int new_value);
1441 set(
const std::string &entry_name,
const double new_value);
1453 set(
const std::string &entry_name,
const bool new_value);
1607 template <
class Archive>
1609 save(Archive &ar,
const unsigned int version)
const;
1616 template <
class Archive>
1618 load(Archive &ar,
const unsigned int version);
1626 template <
class Archive>
1632 BOOST_SERIALIZATION_SPLIT_MEMBER()
1649 std::set<std::string>
1670 <<
"The following entry already exists: " << arg1 <<
'.');
1679 <<
"Line <" << arg1 <<
"> of file <" << arg2 <<
">: "
1680 <<
"Entry <" << arg3 <<
"> is deprecated.");
1687 <<
"The following deprecated entries were encountered:\n\n"
1696 <<
"The string <" << arg1
1697 <<
"> does not match the given pattern <" << arg2 <<
">.");
1703 "You can't leave a subsection if you are already at the top level "
1704 "of the subsection hierarchy.");
1711 <<
"You can't ask for entry <" << arg1
1712 <<
"> you have not yet declared.");
1723 <<
"There are unequal numbers of 'subsection' and 'end' "
1724 "statements in the parameter file <"
1725 << arg1 <<
">." << (arg2.size() > 0 ?
"\n" + arg2 :
""));
1735 <<
"Line <" << arg1 <<
"> of file <" << arg2
1736 <<
">: You are trying to enter a subsection '" << arg3
1737 <<
"', but the ParameterHandler object does "
1738 <<
"not know of any such subsection.");
1749 <<
"Line <" << arg1 <<
"> of file <" << arg2 <<
">: " << arg3);
1762 <<
"Line <" << arg1 <<
"> of file <" << arg2
1764 " The entry value \n"
1765 <<
" " << arg3 <<
'\n'
1766 <<
" for the entry named\n"
1767 <<
" " << arg4 <<
'\n'
1768 <<
" does not match the given pattern:\n"
1777 "The provided file could not be parsed as a "
1778 "ParameterHandler description.");
1791 <<
"Line <" << arg1 <<
"> of file <" << arg2
1793 "contains an 'include' or 'INCLUDE' statement, but the given "
1795 << arg3 <<
"> cannot be opened.");
1819 std::unique_ptr<boost::property_tree::ptree>
entries;
1836 std::vector<std::unique_ptr<const Patterns::PatternBase>>
patterns;
1844 std::vector<std::function<void(
const std::string &)>>
actions;
1866 const std::string &input_filename,
1867 const unsigned int current_line_n,
1868 const bool skip_undefined);
1883 const boost::property_tree::ptree &tree,
1884 const std::vector<std::string> &target_subsection_path,
1886 const unsigned int indent_level,
1887 std::ostream &out)
const;
1904 static_cast<unsigned int>(f1) |
static_cast<unsigned int>(f2));
2186 const std::string &filename =
"input file",
2187 const std::string &last_line =
"",
2188 const bool skip_undefined =
false)
override;
2248 Entry(
const std::vector<std::string> &Path,
2249 const std::string &Name,
2250 const std::string &Value);
2327template <
class Archive>
2337 std::vector<std::string> descriptions;
2339 descriptions.reserve(
patterns.size());
2340 for (
const auto &pattern :
patterns)
2341 descriptions.push_back(pattern->description());
2347template <
class Archive>
2357 std::vector<std::string> descriptions;
2361 for (
const auto &description : descriptions)
2366template <
typename ParameterType>
2369 ParameterType ¶meter,
2370 const std::string &documentation,
2372 const bool has_to_be_set)
2374 static_assert(std::is_const_v<ParameterType> ==
false,
2375 "You tried to add a parameter using a type "
2376 "that is const. Use a non-const type.");
2386 const unsigned int pattern_index =
2389 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)