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>
1013 const std::string &filename =
"input file",
1014 const std::string &last_line =
"",
1015 const bool skip_undefined =
false);
1040 const std::string &last_line =
"",
1041 const bool skip_undefined =
false,
1042 const bool assert_mandatory_entries_are_found =
false);
1054 const std::string &last_line =
"",
1055 const bool skip_undefined =
false);
1111 const std::string & default_value,
1113 const std::string & documentation =
"",
1114 const bool has_to_be_set =
false);
1161 const std::function<
void(
const std::string &value)> &action);
1178 template <
class ParameterType>
1181 ParameterType & parameter,
1182 const std::string & documentation =
"",
1185 const bool has_to_be_set =
false);
1232 const std::string &alias_name,
1233 const bool alias_is_deprecated =
false);
1261 get(
const std::string &entry_string)
const;
1274 get(
const std::vector<std::string> &entry_subsection_path,
1275 const std::string & entry_string)
const;
1283 get_integer(
const std::string &entry_string)
const;
1294 get_integer(
const std::vector<std::string> &entry_subsection_path,
1295 const std::string & entry_string)
const;
1301 get_double(
const std::string &entry_name)
const;
1310 get_double(
const std::vector<std::string> &entry_subsection_path,
1311 const std::string & entry_string)
const;
1318 get_bool(
const std::string &entry_name)
const;
1329 get_bool(
const std::vector<std::string> &entry_subsection_path,
1330 const std::string & entry_string)
const;
1342 set(
const std::string &entry_name,
const std::string &new_value);
1355 set(
const std::string &entry_name,
const char *new_value);
1367 set(
const std::string &entry_name,
const long int new_value);
1383 set(
const std::string &entry_name,
const double new_value);
1395 set(
const std::string &entry_name,
const bool new_value);
1549 template <
class Archive>
1551 save(Archive &ar,
const unsigned int version)
const;
1558 template <
class Archive>
1560 load(Archive &ar,
const unsigned int version);
1568 template <
class Archive>
1574 BOOST_SERIALIZATION_SPLIT_MEMBER()
1591 std::set<std::string>
1612 <<
"The following entry already exists: " << arg1 <<
'.');
1619 <<
"The string <" << arg1
1620 <<
"> does not match the given pattern <" << arg2 <<
">.");
1626 "You can't leave a subsection if you are already at the top level "
1627 "of the subsection hierarchy.");
1633 <<
"You can't ask for entry <" << arg1
1634 <<
"> you have not yet declared.");
1645 <<
"There are unequal numbers of 'subsection' and 'end' "
1646 "statements in the parameter file <"
1647 << arg1 <<
">." << (arg2.size() > 0 ?
"\n" + arg2 :
""));
1657 <<
"Line <" << arg1 <<
"> of file <" << arg2
1659 "no such subsection to be entered: "
1671 <<
"Line <" << arg1 <<
"> of file <" << arg2 <<
">: " << arg3);
1684 <<
"Line <" << arg1 <<
"> of file <" << arg2
1686 " The entry value \n"
1687 <<
" " << arg3 <<
'\n'
1688 <<
" for the entry named\n"
1689 <<
" " << arg4 <<
'\n'
1690 <<
" does not match the given pattern:\n"
1699 "The provided file could not be parsed as a "
1700 "ParameterHandler description.");
1713 <<
"Line <" << arg1 <<
"> of file <" << arg2
1715 "contains an 'include' or 'INCLUDE' statement, but the given "
1717 << arg3 <<
"> cannot be opened.");
1741 std::unique_ptr<boost::property_tree::ptree>
entries;
1758 std::vector<std::unique_ptr<const Patterns::PatternBase>>
patterns;
1766 std::vector<std::function<void(
const std::string &)>>
actions;
1792 const std::string & name)
const;
1814 const std::string &input_filename,
1815 const unsigned int current_line_n,
1816 const bool skip_undefined);
1831 const boost::property_tree::ptree & tree,
1832 const std::vector<std::string> & target_subsection_path,
1834 const unsigned int indent_level,
1835 std::ostream & out)
const;
1852 static_cast<unsigned int>(f1) |
static_cast<unsigned int>(f2));
2134 const std::string &filename =
"input file",
2135 const std::string &last_line =
"",
2136 const bool skip_undefined =
false)
override;
2196 Entry(
const std::vector<std::string> &Path,
2197 const std::string & Name,
2198 const std::string & Value);
2275template <
class Archive>
2285 std::vector<std::string> descriptions;
2287 for (
const auto &pattern :
patterns)
2288 descriptions.push_back(pattern->description());
2294template <
class Archive>
2304 std::vector<std::string> descriptions;
2308 for (
const auto &description : descriptions)
2313template <
class ParameterType>
2316 ParameterType & parameter,
2317 const std::string & documentation,
2319 const bool has_to_be_set)
2321 static_assert(std::is_const<ParameterType>::value ==
false,
2322 "You tried to add a parameter using a type "
2323 "that is const. Use a non-const type.");
2333 const unsigned int pattern_index =
2336 auto action = [&, pattern_index](
const std::string &val) {
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)
ParameterHandler(const ParameterHandler &)=delete
std::ostream & print_parameters(std::ostream &out, const OutputStyle style) const
void add_action(const std::string &entry, const std::function< void(const std::string &value)> &action)
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)
ParameterHandler & operator=(const ParameterHandler &)=delete
void log_parameters_section(LogStream &out, const OutputStyle style=DefaultStyle)
bool subsection_path_exists(const std::vector< std::string > &sub_path) const
virtual ~ParameterHandler() override=default
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
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 const char path_separator
static ::ExceptionBase & ExcNoSubsection(int arg1, std::string arg2, std::string arg3)
void init_branches_current_section()
static ::ExceptionBase & ExcCannotOpenIncludeStatementFile(int arg1, std::string arg2, std::string arg3)
static ::ExceptionBase & ExcEntryAlreadyExists(std::string arg1)
std::string get_current_path() const
std::vector< std::unique_ptr< const Patterns::PatternBase > > patterns
std::vector< std::string > subsection_path
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 fill_entry_values(const unsigned int run_no)
virtual void create_new(const unsigned int run_no)=0
std::vector< std::string > different_values
static ::ExceptionBase & ExcAlreadyAtTopLevel()
#define DeclException2(Exception2, type1, type2, outsequence)
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
static ::ExceptionBase & ExcInvalidEntryForPattern(int arg1, std::string arg2, std::string arg3, std::string arg4, std::string arg5)
static T to_value(const std::string &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())=delete
std::map< std::string, std::pair< bool, bool > > entries_set_status
std::string get_current_full_path(const std::string &name) const
static ::ExceptionBase & ExcEntryUndeclared(std::string arg1)
#define DeclExceptionMsg(Exception, defaulttext)
virtual void run(ParameterHandler &prm)=0
static ::ExceptionBase & ExcValueDoesNotMatchPattern(std::string arg1, std::string arg2)
virtual ~UserClass()=default
static ::ExceptionBase & ExcUnbalancedSubsections(std::string arg1, std::string arg2)
virtual ~MultipleParameterLoop() override=default
#define DeclException3(Exception3, type1, type2, type3, outsequence)
std::vector< Entry > multiple_choices
#define DeclException1(Exception1, type1, outsequence)
std::vector< std::function< void(const std::string &)> > actions
static ::ExceptionBase & ExcCannotParseLine(int arg1, std::string arg2, std::string arg3)
std::unique_ptr< boost::property_tree::ptree > entries
void scan_line(std::string line, const std::string &input_filename, const unsigned int current_line_n, const bool skip_undefined)
static ::ExceptionBase & ExcInvalidXMLParameterFile()
std::vector< std::string > subsection_path
void split_different_values()
std::size_t memory_consumption() const
#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)