16 #ifndef dealii_parameter_handler_h 17 #define dealii_parameter_handler_h 20 #include <deal.II/base/config.h> 22 #include <deal.II/base/exceptions.h> 23 #include <deal.II/base/patterns.h> 24 #include <deal.II/base/subscriptor.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> 36 DEAL_II_NAMESPACE_OPEN
918 const std::string &filename =
"input file",
919 const std::string &last_line =
"");
965 parse_input(
const std::string &filename,
const std::string &last_line =
"");
1026 const std::string & default_value,
1028 const std::string & documentation = std::string());
1075 const std::function<
void(
const std::string &value)> &action);
1086 template <
class ParameterType>
1089 ParameterType & parameter,
1090 const std::string & documentation = std::string(),
1139 const std::string &alias_name,
1140 const bool alias_is_deprecated =
false);
1160 get(
const std::string &entry_string)
const;
1168 get_integer(
const std::string &entry_string)
const;
1174 get_double(
const std::string &entry_name)
const;
1182 get_bool(
const std::string &entry_name)
const;
1194 set(
const std::string &entry_name,
const std::string &new_value);
1207 set(
const std::string &entry_name,
const char *new_value);
1219 set(
const std::string &entry_name,
const long int &new_value);
1235 set(
const std::string &entry_name,
const double &new_value);
1247 set(
const std::string &entry_name,
const bool &new_value);
1333 const unsigned int indent_level,
1334 const bool include_top_level_elements =
false);
1367 template <
class Archive>
1369 save(Archive &ar,
const unsigned int version)
const;
1375 template <
class Archive>
1377 load(Archive &ar,
const unsigned int version);
1379 BOOST_SERIALIZATION_SPLIT_MEMBER()
1397 << "The following entry already exists: " << arg1 << ".");
1404 << "The
string <" << arg1
1405 << "> does not match the given pattern <" << arg2 << ">.");
1411 "You can't leave a subsection if you are already at the top level "
1412 "of the subsection hierarchy.");
1418 << "You can't ask for entry <" << arg1
1419 << "> you have not yet declared.");
1430 << "There are unequal
numbers of 'subsection' and 'end' "
1431 "statements in the parameter file <"
1432 << arg1 << ">." << (arg2.size() > 0 ? "\n" + arg2 : ""));
1442 << "Line <" << arg1 << "> of file <" << arg2
1444 "no such subsection to be entered: "
1456 << "Line <" << arg1 << "> of file <" << arg2 << ">: " << arg3);
1469 << "Line <" << arg1 << "> of file <" << arg2
1471 " The entry value \n"
1472 << " " << arg3 << '\n'
1473 << " for the entry named\n"
1474 << " " << arg4 << '\n'
1475 << " does not match the given pattern:\n"
1484 "The provided file could not be parsed as a "
1496 << " The entry value \n"
1497 << " " << arg1 << '\n'
1498 << " for the entry named\n"
1499 << " " << arg2 << '\n'
1500 << " does not match the given pattern:\n"
1514 << "Line <" << arg1 << "> of file <" << arg2
1516 "contains an 'include' or 'INCLUDE' statement, but the given "
1518 << arg3 << "> cannot be opened.");
1599 const
std::
string &input_filename,
1600 const
unsigned int current_line_n);
1615 const
std::vector<
std::
string> &target_subsection_path,
1617 const
unsigned int indent_level,
1618 std::ostream & out) const;
1862 create_new(
const unsigned int run_no) = 0;
1868 run(ParameterHandler &prm) = 0;
1874 MultipleParameterLoop();
1880 virtual ~MultipleParameterLoop()
override =
default;
1899 const std::string &filename =
"input file",
1900 const std::string &last_line =
"")
override;
1960 Entry(
const std::vector<std::string> &Path,
1961 const std::string & Name,
1962 const std::string & Value);
1968 split_different_values();
2028 init_branches_current_section();
2034 fill_entry_values(
const unsigned int run_no);
2039 template <
class Archive>
2049 std::vector<std::string> descriptions;
2051 for (
unsigned int j = 0; j <
patterns.size(); ++j)
2052 descriptions.push_back(
patterns[j]->description());
2058 template <
class Archive>
2068 std::vector<std::string> descriptions;
2072 for (
unsigned int j = 0; j < descriptions.size(); ++j)
2077 template <
class ParameterType>
2080 ParameterType & parameter,
2081 const std::string & documentation,
2084 static_assert(std::is_const<ParameterType>::value ==
false,
2085 "You tried to add a parameter using a type " 2086 "that is const. Use a non-const type.");
2090 parameter, pattern.
clone()),
2095 const unsigned int pattern_index =
2098 auto action = [&, pattern_index](
const std::string &val) {
2100 val,
patterns[pattern_index]->clone());
2105 DEAL_II_NAMESPACE_CLOSE
void add_parameter(const std::string &entry, ParameterType ¶meter, const std::string &documentation=std::string(), const Patterns::PatternBase &pattern=*Patterns::Tools::Convert< ParameterType >::to_pattern())
std::vector< Entry > multiple_choices
void loop(ITERATOR begin, typename identity< ITERATOR >::type end, DOFINFO &dinfo, INFOBOX &info, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &cell_worker, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &boundary_worker, const std::function< void(DOFINFO &, DOFINFO &, typename INFOBOX::CellInfo &, typename INFOBOX::CellInfo &)> &face_worker, ASSEMBLER &assembler, const LoopControl &lctrl=LoopControl())
static const char path_separator
#define DeclException2(Exception2, type1, type2, outsequence)
static::ExceptionBase & ExcEntryAlreadyExists(std::string arg1)
static std::string collate_path_string(const std::vector< std::string > &subsection_path)
std::string get_current_full_path(const std::string &name) const
static::ExceptionBase & ExcInvalidEntryForPatternXML(std::string arg1, std::string arg2, std::string arg3)
static::ExceptionBase & ExcCannotOpenIncludeStatementFile(int arg1, std::string arg2, std::string arg3)
static::ExceptionBase & ExcEntryUndeclared(std::string arg1)
static::ExceptionBase & ExcUnbalancedSubsections(std::string arg1, std::string arg2)
void log_parameters(LogStream &out)
virtual std::unique_ptr< PatternBase > clone() const =0
virtual void parse_input_from_json(std::istream &input)
void log_parameters_section(LogStream &out)
std::vector< std::string > subsection_path
static::ExceptionBase & ExcValueDoesNotMatchPattern(std::string arg1, std::string arg2)
void load(Archive &ar, const unsigned int version)
std::vector< std::string > subsection_path
void enter_subsection(const std::string &subsection)
virtual void parse_input_from_xml(std::istream &input)
static::ExceptionBase & ExcInvalidXMLParameterFile()
static::ExceptionBase & ExcCannotParseLine(int arg1, std::string arg2, std::string arg3)
#define DeclException1(Exception1, type1, outsequence)
std::ostream & print_parameters(std::ostream &out, const OutputStyle style) const
void save(Archive &ar, const unsigned int version) const
#define DeclExceptionMsg(Exception, defaulttext)
std::string get_current_path() const
std::unique_ptr< boost::property_tree::ptree > entries
#define DeclException5(Exception5, type1, type2, type3, type4, type5, outsequence)
std::unique_ptr< PatternBase > pattern_factory(const std::string &description)
virtual void parse_input_from_string(const char *s, const std::string &last_line="")
static::ExceptionBase & ExcAlreadyAtTopLevel()
std::vector< std::unique_ptr< const Patterns::PatternBase > > patterns
bool get_bool(const std::string &entry_name) const
void add_action(const std::string &entry, const std::function< void(const std::string &value)> &action)
double get_double(const std::string &entry_name) const
void print_parameters_section(std::ostream &out, const OutputStyle style, const unsigned int indent_level, const bool include_top_level_elements=false)
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string())
std::vector< std::string > different_values
void scan_line(std::string line, const std::string &input_filename, const unsigned int current_line_n)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
static::ExceptionBase & ExcInvalidEntryForPattern(int arg1, std::string arg2, std::string arg3, std::string arg4, std::string arg5)
std::vector< std::function< void(const std::string &)> > actions
virtual ~ParameterHandler() override=default
void recursively_print_parameters(const std::vector< std::string > &target_subsection_path, const OutputStyle style, const unsigned int indent_level, std::ostream &out) const
static::ExceptionBase & ExcNoSubsection(int arg1, std::string arg2, std::string arg3)
void declare_alias(const std::string &existing_entry_name, const std::string &alias_name, const bool alias_is_deprecated=false)
std::size_t memory_consumption() const
long int get_integer(const std::string &entry_string) const
ParameterHandler & operator=(const ParameterHandler &)=delete
virtual void parse_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="")