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>
1027 const std::string &filename =
"input file",
1028 const std::string &last_line =
"",
1029 const bool skip_undefined =
false);
1054 const std::string &last_line =
"",
1055 const bool skip_undefined =
false,
1056 const bool assert_mandatory_entries_are_found =
false);
1068 const std::string &last_line =
"",
1069 const bool skip_undefined =
false);
1125 const std::string &default_value,
1127 const std::string &documentation =
"",
1128 const bool has_to_be_set =
false);
1179 const std::function<
void(
const std::string &value)> &action,
1180 const bool execute_action =
true);
1197 template <
typename ParameterType>
1200 ParameterType ¶meter,
1201 const std::string &documentation =
"",
1204 const bool has_to_be_set =
false);
1251 const std::string &alias_name,
1252 const bool alias_is_deprecated =
false);
1259 const bool create_path_if_needed =
true);
1302 const std::string &name)
const;
1310 get(
const std::string &entry_string)
const;
1323 get(
const std::vector<std::string> &entry_subsection_path,
1324 const std::string &entry_string)
const;
1332 get_integer(
const std::string &entry_string)
const;
1343 get_integer(
const std::vector<std::string> &entry_subsection_path,
1344 const std::string &entry_string)
const;
1350 get_double(
const std::string &entry_name)
const;
1359 get_double(
const std::vector<std::string> &entry_subsection_path,
1360 const std::string &entry_string)
const;
1367 get_bool(
const std::string &entry_name)
const;
1378 get_bool(
const std::vector<std::string> &entry_subsection_path,
1379 const std::string &entry_string)
const;
1391 set(
const std::string &entry_name,
const std::string &new_value);
1404 set(
const std::string &entry_name,
const char *new_value);
1416 set(
const std::string &entry_name,
const long int new_value);
1432 set(
const std::string &entry_name,
const double new_value);
1444 set(
const std::string &entry_name,
const bool new_value);
1598 template <
class Archive>
1600 save(Archive &ar,
const unsigned int version)
const;
1607 template <
class Archive>
1609 load(Archive &ar,
const unsigned int version);
1617 template <
class Archive>
1623 BOOST_SERIALIZATION_SPLIT_MEMBER()
1640 std::set<std::string>
1661 <<
"The following entry already exists: " << arg1 <<
'.');
1668 <<
"The string <" << arg1
1669 <<
"> does not match the given pattern <" << arg2 <<
">.");
1675 "You can't leave a subsection if you are already at the top level "
1676 "of the subsection hierarchy.");
1682 <<
"You can't ask for entry <" << arg1
1683 <<
"> you have not yet declared.");
1694 <<
"There are unequal numbers of 'subsection' and 'end' "
1695 "statements in the parameter file <"
1696 << arg1 <<
">." << (arg2.size() > 0 ?
"\n" + arg2 :
""));
1706 <<
"Line <" << arg1 <<
"> of file <" << arg2
1707 <<
">: You are trying to enter a subsection '" << arg3
1708 <<
"', but the ParameterHandler object does "
1709 <<
"not know of any such subsection.");
1720 <<
"Line <" << arg1 <<
"> of file <" << arg2 <<
">: " << arg3);
1733 <<
"Line <" << arg1 <<
"> of file <" << arg2
1735 " The entry value \n"
1736 <<
" " << arg3 <<
'\n'
1737 <<
" for the entry named\n"
1738 <<
" " << arg4 <<
'\n'
1739 <<
" does not match the given pattern:\n"
1748 "The provided file could not be parsed as a "
1749 "ParameterHandler description.");
1762 <<
"Line <" << arg1 <<
"> of file <" << arg2
1764 "contains an 'include' or 'INCLUDE' statement, but the given "
1766 << arg3 <<
"> cannot be opened.");
1790 std::unique_ptr<boost::property_tree::ptree>
entries;
1807 std::vector<std::unique_ptr<const Patterns::PatternBase>>
patterns;
1815 std::vector<std::function<void(
const std::string &)>>
actions;
1837 const std::string &input_filename,
1838 const unsigned int current_line_n,
1839 const bool skip_undefined);
1854 const boost::property_tree::ptree &tree,
1855 const std::vector<std::string> &target_subsection_path,
1857 const unsigned int indent_level,
1858 std::ostream &out)
const;
1875 static_cast<unsigned int>(f1) |
static_cast<unsigned int>(f2));
2157 const std::string &filename =
"input file",
2158 const std::string &last_line =
"",
2159 const bool skip_undefined =
false)
override;
2219 Entry(
const std::vector<std::string> &Path,
2220 const std::string &Name,
2221 const std::string &Value);
2298template <
class Archive>
2308 std::vector<std::string> descriptions;
2310 descriptions.reserve(
patterns.size());
2311 for (
const auto &pattern :
patterns)
2312 descriptions.push_back(pattern->description());
2318template <
class Archive>
2328 std::vector<std::string> descriptions;
2332 for (
const auto &description : descriptions)
2337template <
typename ParameterType>
2340 ParameterType ¶meter,
2341 const std::string &documentation,
2343 const bool has_to_be_set)
2345 static_assert(std::is_const_v<ParameterType> ==
false,
2346 "You tried to add a parameter using a type "
2347 "that is const. Use a non-const type.");
2357 const unsigned int pattern_index =
2360 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
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 & 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)