16#ifndef dealii_parameter_handler_h
17#define dealii_parameter_handler_h
26#include <boost/archive/basic_archive.hpp>
27#include <boost/property_tree/ptree_fwd.hpp>
28#include <boost/property_tree/ptree_serialization.hpp>
29#include <boost/serialization/split_member.hpp>
1028 const std::string &filename =
"input file",
1029 const std::string &last_line =
"",
1030 const bool skip_undefined =
false);
1055 const std::string &last_line =
"",
1056 const bool skip_undefined =
false,
1057 const bool assert_mandatory_entries_are_found =
false);
1069 const std::string &last_line =
"",
1070 const bool skip_undefined =
false);
1126 const std::string & default_value,
1128 const std::string & documentation =
"",
1129 const bool has_to_be_set =
false);
1180 const std::function<
void(
const std::string &value)> &action,
1181 const bool execute_action =
true);
1198 template <
class ParameterType>
1201 ParameterType & parameter,
1202 const std::string & documentation =
"",
1205 const bool has_to_be_set =
false);
1252 const std::string &alias_name,
1253 const bool alias_is_deprecated =
false);
1281 get(
const std::string &entry_string)
const;
1294 get(
const std::vector<std::string> &entry_subsection_path,
1295 const std::string & entry_string)
const;
1303 get_integer(
const std::string &entry_string)
const;
1314 get_integer(
const std::vector<std::string> &entry_subsection_path,
1315 const std::string & entry_string)
const;
1321 get_double(
const std::string &entry_name)
const;
1330 get_double(
const std::vector<std::string> &entry_subsection_path,
1331 const std::string & entry_string)
const;
1338 get_bool(
const std::string &entry_name)
const;
1349 get_bool(
const std::vector<std::string> &entry_subsection_path,
1350 const std::string & entry_string)
const;
1362 set(
const std::string &entry_name,
const std::string &new_value);
1375 set(
const std::string &entry_name,
const char *new_value);
1387 set(
const std::string &entry_name,
const long int new_value);
1403 set(
const std::string &entry_name,
const double new_value);
1415 set(
const std::string &entry_name,
const bool new_value);
1569 template <
class Archive>
1571 save(Archive &ar,
const unsigned int version)
const;
1578 template <
class Archive>
1580 load(Archive &ar,
const unsigned int version);
1588 template <
class Archive>
1594 BOOST_SERIALIZATION_SPLIT_MEMBER()
1611 std::set<std::string>
1632 <<
"The following entry already exists: " << arg1 <<
'.');
1639 <<
"The string <" << arg1
1640 <<
"> does not match the given pattern <" << arg2 <<
">.");
1646 "You can't leave a subsection if you are already at the top level "
1647 "of the subsection hierarchy.");
1653 <<
"You can't ask for entry <" << arg1
1654 <<
"> you have not yet declared.");
1665 <<
"There are unequal numbers of 'subsection' and 'end' "
1666 "statements in the parameter file <"
1667 << arg1 <<
">." << (arg2.size() > 0 ?
"\n" + arg2 :
""));
1677 <<
"Line <" << arg1 <<
"> of file <" << arg2
1679 "no such subsection to be entered: "
1691 <<
"Line <" << arg1 <<
"> of file <" << arg2 <<
">: " << arg3);
1704 <<
"Line <" << arg1 <<
"> of file <" << arg2
1706 " The entry value \n"
1707 <<
" " << arg3 <<
'\n'
1708 <<
" for the entry named\n"
1709 <<
" " << arg4 <<
'\n'
1710 <<
" does not match the given pattern:\n"
1719 "The provided file could not be parsed as a "
1720 "ParameterHandler description.");
1733 <<
"Line <" << arg1 <<
"> of file <" << arg2
1735 "contains an 'include' or 'INCLUDE' statement, but the given "
1737 << arg3 <<
"> cannot be opened.");
1761 std::unique_ptr<boost::property_tree::ptree>
entries;
1778 std::vector<std::unique_ptr<const Patterns::PatternBase>>
patterns;
1786 std::vector<std::function<void(
const std::string &)>>
actions;
1812 const std::string & name)
const;
1834 const std::string &input_filename,
1835 const unsigned int current_line_n,
1836 const bool skip_undefined);
1851 const boost::property_tree::ptree & tree,
1852 const std::vector<std::string> & target_subsection_path,
1854 const unsigned int indent_level,
1855 std::ostream & out)
const;
1872 static_cast<unsigned int>(f1) |
static_cast<unsigned int>(f2));
2154 const std::string &filename =
"input file",
2155 const std::string &last_line =
"",
2156 const bool skip_undefined =
false)
override;
2216 Entry(
const std::vector<std::string> &Path,
2217 const std::string & Name,
2218 const std::string & Value);
2295template <
class Archive>
2305 std::vector<std::string> descriptions;
2307 descriptions.reserve(
patterns.size());
2308 for (
const auto &pattern :
patterns)
2309 descriptions.push_back(pattern->description());
2315template <
class Archive>
2325 std::vector<std::string> descriptions;
2329 for (
const auto &description : descriptions)
2334template <
class ParameterType>
2337 ParameterType & parameter,
2338 const std::string & documentation,
2340 const bool has_to_be_set)
2342 static_assert(std::is_const<ParameterType>::value ==
false,
2343 "You tried to add a parameter using a type "
2344 "that is const. Use a non-const type.");
2354 const unsigned int pattern_index =
2357 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
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 enter_subsection(const std::string &subsection)
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)