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
950 const std::string &filename =
"input file",
951 const std::string &last_line =
"",
952 const bool skip_undefined =
false);
999 const std::string &last_line =
"",
1000 const bool skip_undefined =
false);
1012 const std::string &last_line =
"",
1013 const bool skip_undefined =
false);
1063 const std::string & default_value,
1065 const std::string & documentation =
"");
1112 const std::function<
void(
const std::string &value)> &action);
1123 template <
class ParameterType>
1126 ParameterType & parameter,
1127 const std::string & documentation =
"",
1176 const std::string &alias_name,
1177 const bool alias_is_deprecated =
false);
1197 get(
const std::string &entry_string)
const;
1210 get(
const std::vector<std::string> &entry_subsection_path,
1211 const std::string & entry_string)
const;
1219 get_integer(
const std::string &entry_string)
const;
1230 get_integer(
const std::vector<std::string> &entry_subsection_path,
1231 const std::string & entry_string)
const;
1237 get_double(
const std::string &entry_name)
const;
1246 get_double(
const std::vector<std::string> &entry_subsection_path,
1247 const std::string & entry_string)
const;
1254 get_bool(
const std::string &entry_name)
const;
1265 get_bool(
const std::vector<std::string> &entry_subsection_path,
1266 const std::string & entry_string)
const;
1278 set(
const std::string &entry_name,
const std::string &new_value);
1291 set(
const std::string &entry_name,
const char *new_value);
1303 set(
const std::string &entry_name,
const long int new_value);
1319 set(
const std::string &entry_name,
const double new_value);
1331 set(
const std::string &entry_name,
const bool new_value);
1417 const unsigned int indent_level,
1418 const bool include_top_level_elements =
false);
1451 template <
class Archive>
1453 save(Archive &ar,
const unsigned int version)
const;
1459 template <
class Archive>
1461 load(Archive &ar,
const unsigned int version);
1463 BOOST_SERIALIZATION_SPLIT_MEMBER()
1481 << "The following entry already exists: " << arg1 << ".");
1488 << "The
string <" << arg1
1489 << "> does not match the given pattern <" << arg2 << ">.");
1495 "You can't leave a subsection if you are already at the top level "
1496 "of the subsection hierarchy.");
1502 << "You can't ask for entry <" << arg1
1503 << "> you have not yet declared.");
1514 << "There are unequal
numbers of 'subsection' and 'end' "
1515 "statements in the parameter file <"
1516 << arg1 << ">." << (arg2.size() > 0 ? "\n" + arg2 : ""));
1526 << "Line <" << arg1 << "> of file <" << arg2
1528 "no such subsection to be entered: "
1540 << "Line <" << arg1 << "> of file <" << arg2 << ">: " << arg3);
1553 << "Line <" << arg1 << "> of file <" << arg2
1555 " The entry value \n"
1556 << " " << arg3 << '\n'
1557 << " for the entry named\n"
1558 << " " << arg4 << '\n'
1559 << " does not match the given pattern:\n"
1568 "The provided file could not be parsed as a "
1580 << " The entry value \n"
1581 << " " << arg1 << '\n'
1582 << " for the entry named\n"
1583 << " " << arg2 << '\n'
1584 << " does not match the given pattern:\n"
1598 << "Line <" << arg1 << "> of file <" << arg2
1600 "contains an 'include' or 'INCLUDE' statement, but the given "
1602 << arg3 << "> cannot be opened.");
1675 const
std::
string & name) const;
1697 const
std::
string &input_filename,
1698 const
unsigned int current_line_n,
1699 const
bool skip_undefined);
1714 const
std::vector<
std::
string> &target_subsection_path,
1716 const
unsigned int indent_level,
1717 std::ostream & out) const;
1961 create_new(
const unsigned int run_no) = 0;
2004 const std::string &filename =
"input file",
2005 const std::string &last_line =
"",
2006 const bool skip_undefined =
false)
override;
2066 Entry(
const std::vector<std::string> &Path,
2067 const std::string & Name,
2068 const std::string & Value);
2074 split_different_values();
2134 init_branches_current_section();
2140 fill_entry_values(
const unsigned int run_no);
2145 template <
class Archive>
2155 std::vector<std::string> descriptions;
2157 for (
const auto &pattern :
patterns)
2158 descriptions.push_back(pattern->description());
2164 template <
class Archive>
2174 std::vector<std::string> descriptions;
2178 for (
const auto &description : descriptions)
2183 template <
class ParameterType>
2186 ParameterType & parameter,
2187 const std::string & documentation,
2190 static_assert(std::is_const<ParameterType>::value ==
false,
2191 "You tried to add a parameter using a type " 2192 "that is const. Use a non-const type.");
2196 parameter, pattern.
clone()),
2201 const unsigned int pattern_index =
2204 auto action = [&, pattern_index](
const std::string &val) {
2206 val,
patterns[pattern_index]->clone());
2211 DEAL_II_NAMESPACE_CLOSE
std::vector< Entry > multiple_choices
long int get_integer(const std::string &entry_string) const
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)
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation="")
static ::ExceptionBase & ExcEntryAlreadyExists(std::string arg1)
static std::string collate_path_string(const std::vector< std::string > &subsection_path)
static ::ExceptionBase & ExcInvalidEntryForPatternXML(std::string arg1, std::string arg2, std::string arg3)
static ::ExceptionBase & ExcCannotOpenIncludeStatementFile(int arg1, std::string arg2, std::string arg3)
std::string get_current_path() const
static ::ExceptionBase & ExcEntryUndeclared(std::string arg1)
static ::ExceptionBase & ExcUnbalancedSubsections(std::string arg1, std::string arg2)
std::ostream & print_parameters(std::ostream &out, const OutputStyle style) const
void log_parameters(LogStream &out)
virtual void parse_input_from_string(const std::string &s, const std::string &last_line="", const bool skip_undefined=false)
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
#define DeclException5( Exception5, type1, type2, type3, type4, type5, outsequence)
void scan_line(std::string line, const std::string &input_filename, const unsigned int current_line_n, const bool skip_undefined)
static ::ExceptionBase & ExcValueDoesNotMatchPattern(std::string arg1, std::string arg2)
void load(Archive &ar, const unsigned int version)
std::vector< std::string > subsection_path
void add_parameter(const std::string &entry, ParameterType ¶meter, const std::string &documentation="", const Patterns::PatternBase &pattern= *Patterns::Tools::Convert< ParameterType >::to_pattern())
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)
double get_double(const std::string &entry_name) const
#define DeclException1(Exception1, type1, outsequence)
std::string get_current_full_path(const std::string &name) const
#define DeclExceptionMsg(Exception, defaulttext)
std::unique_ptr< boost::property_tree::ptree > entries
virtual void parse_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="", const bool skip_undefined=false)
std::unique_ptr< PatternBase > pattern_factory(const std::string &description)
bool get_bool(const std::string &entry_name) const
static ::ExceptionBase & ExcAlreadyAtTopLevel()
std::vector< std::unique_ptr< const Patterns::PatternBase > > patterns
void add_action(const std::string &entry, const std::function< void(const std::string &value)> &action)
void print_parameters_section(std::ostream &out, const OutputStyle style, const unsigned int indent_level, const bool include_top_level_elements=false)
void save(Archive &ar, const unsigned int version) const
void recursively_print_parameters(const std::vector< std::string > &target_subsection_path, const OutputStyle style, const unsigned int indent_level, std::ostream &out) const
std::vector< std::string > different_values
#define DeclException3(Exception3, type1, type2, type3, outsequence)
std::size_t memory_consumption() const
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
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)
ParameterHandler & operator=(const ParameterHandler &)=delete