16 #ifndef dealii_parameter_handler_h 17 #define dealii_parameter_handler_h 20 #include <deal.II/base/config.h> 21 #include <deal.II/base/exceptions.h> 22 #include <deal.II/base/subscriptor.h> 23 #include <deal.II/base/patterns.h> 25 #include <boost/property_tree/ptree_fwd.hpp> 26 #include <boost/serialization/split_member.hpp> 27 #include <boost/archive/basic_archive.hpp> 28 #include <boost/property_tree/ptree_serialization.hpp> 35 DEAL_II_NAMESPACE_OPEN
897 const std::string &filename =
"input file",
898 const std::string &last_line =
"");
943 virtual void parse_input (
const std::string &filename,
944 const std::string &last_line =
"");
955 const std::string &last_line =
"");
1001 const std::string &default_value,
1003 const std::string &documentation = std::string());
1048 const std::function<
void (
const std::string &value)> &action);
1059 template <
class ParameterType>
1061 ParameterType ¶meter,
1062 const std::string &documentation = std::string(),
1110 const std::string &alias_name,
1111 const bool alias_is_deprecated =
false);
1128 std::string
get (
const std::string &entry_string)
const;
1135 long int get_integer (
const std::string &entry_string)
const;
1140 double get_double (
const std::string &entry_name)
const;
1147 bool get_bool (
const std::string &entry_name)
const;
1158 void set (
const std::string &entry_name,
1159 const std::string &new_value);
1171 void set (
const std::string &entry_name,
1172 const char *new_value);
1183 void set (
const std::string &entry_name,
1184 const long int &new_value);
1199 void set (
const std::string &entry_name,
1200 const double &new_value);
1211 void set (
const std::string &entry_name,
1212 const bool &new_value);
1297 const unsigned int indent_level,
1298 const bool include_top_level_elements =
false);
1328 template <
class Archive>
1329 void save (Archive &ar,
const unsigned int version)
const;
1335 template <
class Archive>
1336 void load (Archive &ar,
const unsigned int version);
1338 BOOST_SERIALIZATION_SPLIT_MEMBER()
1355 << "The following entry already exists: " << arg1 << ".");
1360 std::
string,
std::
string,
1361 << "The
string <" << arg1
1362 << "> does not match the given pattern <" << arg2 << ">.");
1367 "You can't leave a subsection if you are already at the top level "
1368 "of the subsection hierarchy.");
1374 << "You can't ask for entry <" << arg1 << "> you have not yet declared.");
1383 std::
string,
std::
string,
1384 << "There are unequal
numbers of 'subsection' and 'end' "
1385 "statements in the parameter file <" << arg1 << ">."
1386 << (arg2.size() > 0 ? "\n" + arg2 : ""));
1393 int,
std::
string,
std::
string,
1394 << "Line <" << arg1 << "> of file <" << arg2 << ": There is "
1395 "no such subsection to be entered: " << arg3);
1403 int,
std::
string,
std::
string, << "Line <" << arg1 <<
1404 "> of file <" << arg2 << ">: " << arg3);
1412 int,
std::
string,
std::
string,
std::
string,
std::
string,
1413 << "Line <" << arg1 << "> of file <" << arg2 << ">:\n"
1414 " The entry value \n" << " " << arg3 << '\n' <<
1415 " for the entry named\n" << " " << arg4 << '\n' <<
1416 " does not match the given pattern:\n" << " " <<
1425 "The provided file could not be parsed as a "
1435 << " The entry value \n" << " " << arg1 << '\n' <<
1436 " for the entry named\n" << " " << arg2 << '\n' <<
1437 " does not match the given pattern:\n" << " " <<
1447 int,
std::
string,
std::
string,
1448 << "Line <" << arg1 << "> of file <" << arg2 << ">: This line "
1449 "contains an 'include' or 'INCLUDE' statement, but the given "
1450 "file to include <" << arg3 << "> cannot be opened.");
1529 const
std::
string &input_filename,
1530 const
unsigned int current_line_n);
1545 const
unsigned int indent_level,
1546 std::ostream &out) const;
1789 virtual void create_new (
const unsigned int run_no) = 0;
1824 const std::string &filename =
"input file",
1825 const std::string &last_line =
"")
override;
1882 Entry (
const std::vector<std::string> &Path,
1883 const std::string &Name,
1884 const std::string &Value);
1889 void split_different_values ();
1938 void init_branches ();
1946 void init_branches_current_section ();
1951 void fill_entry_values (
const unsigned int run_no);
1956 template <
class Archive>
1967 std::vector<std::string> descriptions;
1969 for (
unsigned int j=0; j<
patterns.size(); ++j)
1970 descriptions.push_back (
patterns[j]->description());
1976 template <
class Archive>
1987 std::vector<std::string> descriptions;
1991 for (
unsigned int j=0; j<descriptions.size(); ++j)
1996 template <
class ParameterType>
1998 ParameterType ¶meter,
1999 const std::string &documentation,
2003 static_assert(std::is_const<ParameterType>::value ==
false,
2004 "You tried to add a parameter using a type " 2005 "that is const. Use a non-const type.");
2009 parameter, pattern.
clone()),
2014 const unsigned int pattern_index
2017 auto action = [ &, pattern_index](
const std::string &val)
2025 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)
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)
virtual ~ParameterHandler()=default
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 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)
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
#define DeclException5(Exception5, type1, type2, type3, type4, type5, outsequence)
std::unique_ptr< PatternBase > pattern_factory(const std::string &description)
bool get_bool(const std::string &entry_name) const
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
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())
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 declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string())
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
std::vector< std::function< void(const std::string &)> > actions
void scan_line(std::string line, const std::string &input_filename, const unsigned int current_line_n)
#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)
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
virtual void parse_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="")