17 #include <deal.II/base/parameter_handler.h> 18 #include <deal.II/base/logstream.h> 19 #include <deal.II/base/path_search.h> 20 #include <deal.II/base/memory_consumption.h> 21 #include <deal.II/base/utilities.h> 23 #include <boost/property_tree/ptree.hpp> 24 #include <boost/property_tree/xml_parser.hpp> 25 #include <boost/property_tree/json_parser.hpp> 27 #include <boost/io/ios_state.hpp> 40 DEAL_II_NAMESPACE_OPEN
45 entries (new boost::property_tree::ptree())
52 mangle (
const std::string &s)
61 const bool mangle_whole_string = (s ==
"value");
66 for (
unsigned int i=0; i<s.size(); ++i)
68 static const std::string allowed_characters
69 (
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
71 if ((! mangle_whole_string)
73 (allowed_characters.find (s[i]) != std::string::npos))
78 static const char hex[16]
79 = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'};
80 u.push_back (hex[static_cast<unsigned char>(s[i])/16]);
81 u.push_back (hex[static_cast<unsigned char>(s[i])%16]);
91 demangle (
const std::string &s)
96 for (
unsigned int i=0; i<s.size(); ++i)
102 ExcMessage (
"Trying to demangle an invalid string."));
212 u.push_back (static_cast<char>(c));
226 is_parameter_node (
const boost::property_tree::ptree &p)
228 return static_cast<bool>(p.get_optional<std::string>(
"value"));
237 is_alias_node (
const boost::property_tree::ptree &p)
239 return static_cast<bool>(p.get_optional<std::string>(
"alias"));
275 if (path.empty() ==
false)
278 path += mangle(name);
286 const std::string &filename,
287 const std::string &last_line)
294 std::string input_line;
295 std::string fully_concatenated_line;
296 bool is_concatenated =
false;
300 unsigned int current_line_n = 0;
301 unsigned int current_logical_line_n = 0;
315 auto scan_line_or_cleanup =
316 [
this, &saved_path](
const std::string &line,
317 const std::string &filename,
318 const unsigned int line_number)
336 while (std::getline (input, input_line))
339 if (!is_concatenated)
340 current_logical_line_n = current_line_n;
347 if (last_line.length() != 0 &&
348 input_line == last_line)
353 if (input_line.length() != 0 &&
354 input_line.find_last_of(
'\\') == input_line.length() - 1)
356 input_line.erase (input_line.length() - 1);
357 is_concatenated =
true;
359 fully_concatenated_line += input_line;
363 else if (is_concatenated)
365 fully_concatenated_line += input_line;
366 is_concatenated =
false;
372 fully_concatenated_line = input_line;
375 if (!is_concatenated)
377 scan_line_or_cleanup (fully_concatenated_line,
379 current_logical_line_n);
381 fully_concatenated_line.clear();
389 scan_line_or_cleanup (fully_concatenated_line,
395 std::stringstream paths_message;
396 if (saved_path.size() > 0)
398 paths_message <<
"Path before loading input:\n";
401 paths_message << std::setw(i*2 + 4)
407 paths_message <<
"Current path:\n";
410 paths_message << std::setw(i*2 + 4)
426 const std::string &last_line)
430 std::string openname = search.
find(filename);
431 std::ifstream file_stream (openname.c_str());
439 const std::string &last_line)
441 std::istringstream input_stream (s);
442 parse_input (input_stream,
"input string", last_line);
455 read_xml_recursively (
const boost::property_tree::ptree &source,
456 const std::string ¤t_path,
457 const char path_separator,
458 const std::vector<std::unique_ptr<const Patterns::PatternBase> > &
460 boost::property_tree::ptree &destination)
462 for (boost::property_tree::ptree::const_iterator p = source.begin();
463 p != source.end(); ++p)
466 if (p->second.get_optional<std::string>(
"value"))
470 const std::string full_path
471 = (current_path ==
"" 475 current_path + path_separator + p->first);
477 const std::string new_value
478 = p->second.get<std::string>(
"value");
479 AssertThrow (destination.get_optional<std::string> (full_path)
481 destination.get_optional<std::string>
482 (full_path + path_separator +
"value"),
487 const unsigned int pattern_index
488 = destination.get<
unsigned int> (full_path +
491 AssertThrow (patterns[pattern_index]->match(new_value),
497 patterns[pattern_index]->description()));
500 destination.put (full_path + path_separator +
"value",
508 else if (p->second.get_optional<std::string>(
"alias"))
517 read_xml_recursively (p->second,
518 (current_path ==
"" ?
520 current_path + path_separator + p->first),
538 boost::property_tree::ptree single_node_tree;
541 read_xml (in, single_node_tree);
545 AssertThrow (single_node_tree.get_optional<std::string>(
"ParameterHandler"),
547 "called \"ParameterHandler\"."));
549 const std::size_t n_top_level_elements = std::distance (single_node_tree.begin(),
550 single_node_tree.end());
551 if (n_top_level_elements != 1)
553 std::ostringstream top_level_message;
554 top_level_message <<
"The ParameterHandler input parser found " 555 << n_top_level_elements
556 <<
" top level elements while reading\n " 557 <<
" an XML format input file, but there should be" 558 <<
" exactly one top level element.\n" 559 <<
" The top level elements are:\n";
561 unsigned int entry_n = 0;
562 for (boost::property_tree::ptree::iterator it = single_node_tree.begin();
563 it != single_node_tree.end(); ++it, ++entry_n)
565 top_level_message <<
" " 567 << (entry_n != n_top_level_elements - 1 ?
"\n" :
"");
576 const boost::property_tree::ptree
577 &my_entries = single_node_tree.get_child(
"ParameterHandler");
587 boost::property_tree::ptree node_tree;
590 read_json (in, node_tree);
601 entries = std_cxx14::make_unique<boost::property_tree::ptree> ();
608 const std::string &default_value,
610 const std::string &documentation)
622 static_cast<unsigned int>(
patterns.size()-1));
633 "pattern_description",
645 const std::function<
void (
const std::string &)> &action)
650 boost::optional<std::string>
660 const std::string all_actions = current_actions.get() +
675 action (default_value);
682 const std::string &alias_name,
683 const bool alias_is_deprecated)
687 ExcMessage (
"You are trying to declare an alias entry <" 689 "> that references an entry <" 690 + existing_entry_name +
691 ">, but the latter does not exist."));
695 ExcMessage (
"You are trying to declare an alias entry <" 697 "> that references an entry <" 698 + existing_entry_name +
699 ">, but the latter does not seem to be a " 700 "parameter declaration."));
709 ExcMessage (
"You are trying to declare an alias entry <" 711 "> but a non-alias entry already exists in this " 712 "subsection (i.e., there is either a preexisting " 713 "further subsection, or a parameter entry, with " 714 "the same name as the alias)."));
718 ExcMessage (
"You are trying to declare an alias entry <" 720 "> but an alias entry already exists in this " 721 "subsection and this existing alias references a " 722 "different parameter entry. Specifically, " 723 "you are trying to reference the entry <" 724 + existing_entry_name +
725 "> whereas the existing alias references " 732 existing_entry_name);
734 (alias_is_deprecated ?
"true" :
"false"));
744 boost::property_tree::ptree());
769 if (boost::optional<std::string> value
790 ExcMessage(
"Can't convert the parameter value <" 791 +
get(entry_string) +
810 ExcMessage(
"Can't convert the parameter value <" 811 +
get(entry_string) +
814 " to a double precision variable."));
823 const std::string s =
get(entry_string);
826 (s==
"yes") || (s==
"no"),
827 ExcMessage(
"Can't convert the parameter value <" 828 +
get(entry_string) +
832 if (s==
"true" || s==
"yes")
842 const std::string &new_value)
855 const unsigned int pattern_index
862 "pattern_description")));
866 const boost::optional<std::string> action_indices_as_string
868 if (action_indices_as_string)
870 std::vector<int> action_indices
872 for (
unsigned int index : action_indices)
888 const char *new_value)
891 set (entry_string, std::string(new_value));
897 const double &new_value)
899 std::ostringstream s;
900 s << std::setprecision(16);
905 set (entry_string, s.str());
912 const long int &new_value)
914 std::ostringstream s;
919 set (entry_string, s.str());
926 const bool &new_value)
931 (new_value ?
"true" :
"false"));
946 boost::io::ios_flags_saver restore_flags(out);
947 boost::io::basic_ios_fill_saver<char> restore_fill_state(out);
964 boost::property_tree::ptree single_node_tree;
965 single_node_tree.add_child(
"ParameterHandler",
968 write_xml (out, single_node_tree);
982 out <<
"# Listing of Parameters" << std::endl
983 <<
"# ---------------------" << std::endl;
987 out <<
"\\subsection{Global parameters}" << std::endl;
988 out <<
"\\label{parameters:global}" << std::endl;
989 out << std::endl << std::endl;
993 out <<
"Listing of Parameters:" << std::endl << std::endl;
1017 const unsigned int indent_level,
1018 std::ostream &out)
const 1026 const boost::property_tree::ptree ¤t_section
1029 unsigned int overall_indent_level = indent_level;
1043 std::size_t longest_name = 0;
1044 std::size_t longest_value = 0;
1045 for (boost::property_tree::ptree::const_iterator
1046 p = current_section.begin();
1047 p != current_section.end(); ++p)
1048 if (is_parameter_node (p->second) ==
true)
1050 longest_name = std::max (longest_name,
1051 demangle(p->first).length());
1052 longest_value = std::max (longest_value,
1053 p->second.get<std::string>(
"value").length());
1058 bool first_entry =
true;
1059 for (boost::property_tree::ptree::const_assoc_iterator
1060 p = current_section.ordered_begin();
1061 p != current_section.not_found(); ++p)
1062 if (is_parameter_node (p->second) ==
true)
1064 const std::string value = p->second.get<std::string>(
"value");
1071 if ((style ==
Text) &&
1072 !p->second.get<std::string>(
"documentation").empty())
1074 if (first_entry ==
false)
1077 first_entry =
false;
1079 const std::vector<std::string> doc_lines
1082 78 - overall_indent_level*2 - 2);
1084 for (
unsigned int i=0; i<doc_lines.size(); ++i)
1085 out << std::setw(overall_indent_level*2) <<
"" 1094 out << std::setw(overall_indent_level*2) <<
"" 1096 << demangle(p->first)
1097 << std::setw(longest_name-demangle(p->first).length()+1) <<
" " 1102 if ((style ==
Text) && value != p->second.get<std::string>(
"default_value"))
1104 out << std::setw(longest_value-value.length()+1) <<
' ' 1106 out <<
"default: " << p->second.get<std::string>(
"default_value");
1117 auto escape = [] (
const std::string &input)
1124 bool parameters_exist_here =
false;
1125 for (boost::property_tree::ptree::const_assoc_iterator
1126 p = current_section.ordered_begin();
1127 p != current_section.not_found(); ++p)
1128 if ((is_parameter_node (p->second) ==
true)
1130 (is_alias_node (p->second) ==
true))
1132 parameters_exist_here =
true;
1136 if (parameters_exist_here)
1138 out <<
"\\begin{itemize}" 1143 for (boost::property_tree::ptree::const_assoc_iterator
1144 p = current_section.ordered_begin();
1145 p != current_section.not_found(); ++p)
1146 if (is_parameter_node (p->second) ==
true)
1148 const std::string value = p->second.get<std::string>(
"value");
1151 out <<
"\\item {\\it Parameter name:} {\\tt " 1152 << escape(demangle(p->first)) <<
"}\n" 1153 <<
"\\phantomsection";
1156 std::string label =
"parameters:";
1157 for (
unsigned int i=0; i<target_subsection_path.size(); ++i)
1159 label.append(mangle(target_subsection_path[i]));
1162 label.append(p->first);
1165 if (label.find(
"_20")!=std::string::npos)
1167 out <<
"\\label{" << label <<
"}\n";
1171 out <<
"\\index[prmindex]{" 1172 << escape(demangle(p->first))
1174 out <<
"\\index[prmindexfull]{";
1175 for (
unsigned int i=0; i<target_subsection_path.size(); ++i)
1176 out << escape(target_subsection_path[i]) <<
"!";
1177 out << escape(demangle(p->first))
1181 out <<
"{\\it Value:} " << escape(value) <<
"\n\n" 1183 <<
"{\\it Default:} " 1184 << escape(p->second.get<std::string>(
"default_value"))
1190 if (!p->second.get<std::string>(
"documentation").empty())
1191 out <<
"{\\it Description:} " 1192 << p->second.get<std::string>(
"documentation") <<
"\n\n" 1197 const unsigned int pattern_index = p->second.get<
unsigned int> (
"pattern");
1199 out <<
"{\\it Possible values:} " 1203 else if (is_alias_node (p->second) ==
true)
1205 const std::string alias = p->second.get<std::string>(
"alias");
1208 out <<
"\\item {\\it Parameter name:} {\\tt " 1209 << escape(demangle(p->first)) <<
"}\n" 1210 <<
"\\phantomsection";
1213 std::string label =
"parameters:";
1214 for (
unsigned int i=0; i<target_subsection_path.size(); ++i)
1216 label.append(mangle(target_subsection_path[i]));
1219 label.append(p->first);
1222 if (label.find(
"_20")!=std::string::npos)
1224 out <<
"\\label{" << label <<
"}\n";
1228 out <<
"\\index[prmindex]{" 1229 << escape(demangle(p->first))
1231 out <<
"\\index[prmindexfull]{";
1232 for (
unsigned int i=0; i<target_subsection_path.size(); ++i)
1233 out << escape(target_subsection_path[i]) <<
"!";
1234 out << escape(demangle(p->first))
1238 out <<
"This parameter is an alias for the parameter ``\\texttt{" 1239 << escape(alias) <<
"}''." 1240 << (p->second.get<std::string>(
"deprecation_status") ==
"true" 1242 " Its use is deprecated." 1248 out <<
"\\end{itemize}" 1259 std::size_t longest_name = 0;
1260 for (boost::property_tree::ptree::const_iterator
1261 p = current_section.begin();
1262 p != current_section.end(); ++p)
1263 if (is_parameter_node (p->second) ==
true)
1264 longest_name = std::max (longest_name,
1265 demangle(p->first).length());
1269 for (boost::property_tree::ptree::const_assoc_iterator
1270 p = current_section.ordered_begin();
1271 p != current_section.not_found(); ++p)
1272 if (is_parameter_node (p->second) ==
true)
1275 out << std::setw(overall_indent_level*2) <<
"" 1277 << demangle(p->first)
1278 << std::setw(longest_name-demangle(p->first).length()+1) <<
" " 1282 const unsigned int pattern_index = p->second.get<
unsigned int> (
"pattern");
1284 const std::vector<std::string> description_str
1286 78 - overall_indent_level*2 - 2,
'|');
1287 if (description_str.size() > 1)
1290 for (
unsigned int i=0; i<description_str.size(); ++i)
1291 out << std::setw(overall_indent_level*2+6) <<
"" 1292 << description_str[i] <<
'\n';
1294 else if (description_str.empty() ==
false)
1295 out <<
" " << description_str[0] <<
'\n';
1300 if (p->second.get<std::string>(
"documentation").length() != 0)
1301 out << std::setw(overall_indent_level*2 + longest_name + 10) <<
"" 1302 <<
"(" << p->second.get<std::string>(
"documentation") <<
")" 1317 unsigned int n_parameters = 0;
1318 unsigned int n_sections = 0;
1319 for (boost::property_tree::ptree::const_iterator
1320 p = current_section.begin();
1321 p != current_section.end(); ++p)
1322 if (is_parameter_node (p->second) ==
true)
1324 else if (is_alias_node (p->second) ==
false)
1338 for (boost::property_tree::ptree::const_assoc_iterator
1339 p = current_section.ordered_begin();
1340 p != current_section.not_found(); ++p)
1341 if ((is_parameter_node (p->second) ==
false)
1343 (is_alias_node (p->second) ==
false))
1351 out << std::setw(overall_indent_level*2) <<
"" 1352 <<
"subsection " << demangle(p->first)
1358 auto escape = [] (
const std::string &input)
1364 <<
"\\subsection{Parameters in section \\tt ";
1368 for (
unsigned int i=0; i<target_subsection_path.size(); ++i)
1369 out << escape(target_subsection_path[i]) <<
"/";
1370 out << escape(demangle(p->first));
1373 out <<
"\\label{parameters:";
1374 for (
unsigned int i=0; i<target_subsection_path.size(); ++i)
1375 out << mangle(target_subsection_path[i]) <<
"/";
1376 out << p->first <<
"}";
1388 const std::string subsection = demangle(p->first);
1389 std::vector<std::string> directory_path = target_subsection_path;
1390 directory_path.emplace_back (subsection);
1393 overall_indent_level+1,
1401 out << std::setw(overall_indent_level*2) <<
"" 1407 if (overall_indent_level == 0)
1417 out << std::setw(overall_indent_level*2) <<
"" 1440 const unsigned int indent_level,
1441 const bool include_top_level_elements)
1445 const boost::property_tree::ptree ¤t_section
1448 unsigned int overall_indent_level = indent_level;
1454 if (include_top_level_elements)
1465 boost::property_tree::ptree single_node_tree;
1471 single_node_tree.add_child(
"ParameterHandler",
1476 std::string path (
"ParameterHandler");
1478 single_node_tree.add_child(path,
1479 boost::property_tree::ptree());
1482 single_node_tree.add_child (path, current_section);
1485 write_xml (out, single_node_tree);
1499 out << std::setw(overall_indent_level*2) <<
"" 1501 overall_indent_level += 1;
1508 std::size_t longest_name = 0;
1509 for (boost::property_tree::ptree::const_iterator
1510 p = current_section.begin();
1511 p != current_section.end(); ++p)
1512 if (is_parameter_node (p->second) ==
true)
1513 longest_name = std::max (longest_name,
1514 demangle(p->first).length());
1518 std::size_t longest_value = 0;
1519 for (boost::property_tree::ptree::const_iterator
1520 p = current_section.begin();
1521 p != current_section.end(); ++p)
1522 if (is_parameter_node (p->second) ==
true)
1523 longest_value = std::max (longest_value,
1524 p->second.get<std::string>(
"value").length());
1529 bool first_entry =
true;
1530 for (boost::property_tree::ptree::const_assoc_iterator
1531 p = current_section.ordered_begin();
1532 p != current_section.not_found(); ++p)
1533 if (is_parameter_node (p->second) ==
true)
1535 const std::string value = p->second.get<std::string>(
"value");
1542 if ((!(style & 128)) &&
1543 !p->second.get<std::string>(
"documentation").empty())
1545 if (first_entry ==
false)
1548 first_entry =
false;
1550 const std::vector<std::string> doc_lines
1553 78 - overall_indent_level*2 - 2);
1555 for (
unsigned int i=0; i<doc_lines.size(); ++i)
1556 out << std::setw(overall_indent_level*2) <<
"" 1565 out << std::setw(overall_indent_level*2) <<
"" 1567 << demangle(p->first)
1568 << std::setw(longest_name-demangle(p->first).length()+1) <<
" " 1573 if ((!(style & 64)) && value != p->second.get<std::string>(
"default_value"))
1575 out << std::setw(longest_value-value.length()+1) <<
' ' 1577 out <<
"default: " << p->second.get<std::string>(
"default_value");
1588 auto escape = [] (
const std::string &input)
1595 bool parameters_exist_here =
false;
1596 for (boost::property_tree::ptree::const_assoc_iterator
1597 p = current_section.ordered_begin();
1598 p != current_section.not_found(); ++p)
1599 if ((is_parameter_node (p->second) ==
true)
1601 (is_alias_node (p->second) ==
true))
1603 parameters_exist_here =
true;
1607 if (parameters_exist_here)
1609 out <<
"\\begin{itemize}" 1614 for (boost::property_tree::ptree::const_assoc_iterator
1615 p = current_section.ordered_begin();
1616 p != current_section.not_found(); ++p)
1617 if (is_parameter_node (p->second) ==
true)
1619 const std::string value = p->second.get<std::string>(
"value");
1622 out <<
"\\item {\\it Parameter name:} {\\tt " << escape(demangle(p->first)) <<
"}\n" 1623 <<
"\\phantomsection\\label{parameters:";
1630 out <<
"\\index[prmindex]{" 1631 << escape(demangle(p->first))
1633 out <<
"\\index[prmindexfull]{";
1636 out << escape(demangle(p->first))
1640 out <<
"{\\it Value:} " << escape(value) <<
"\n\n" 1642 <<
"{\\it Default:} " 1643 << escape(p->second.get<std::string>(
"default_value")) <<
"\n\n" 1647 if (!p->second.get<std::string>(
"documentation").empty())
1648 out <<
"{\\it Description:} " 1649 << p->second.get<std::string>(
"documentation") <<
"\n\n" 1653 const unsigned int pattern_index = p->second.get<
unsigned int> (
"pattern");
1655 out <<
"{\\it Possible values:} " 1659 else if (is_alias_node (p->second) ==
true)
1661 const std::string alias = p->second.get<std::string>(
"alias");
1664 out <<
"\\item {\\it Parameter name:} {\\tt " << escape(demangle(p->first)) <<
"}\n" 1665 <<
"\\phantomsection\\label{parameters:";
1672 out <<
"\\index[prmindex]{" 1673 << escape(demangle(p->first))
1675 out <<
"\\index[prmindexfull]{";
1678 out << escape(demangle(p->first))
1682 out <<
"This parameter is an alias for the parameter ``\\texttt{" 1683 << escape(alias) <<
"}''." 1684 << (p->second.get<std::string>(
"deprecation_status") ==
"true" 1686 " Its use is deprecated." 1692 out <<
"\\end{itemize}" << std::endl;
1704 out << std::setw(overall_indent_level*2) <<
"" 1706 overall_indent_level += 1;
1711 std::size_t longest_name = 0;
1712 for (boost::property_tree::ptree::const_iterator
1713 p = current_section.begin();
1714 p != current_section.end(); ++p)
1715 if (is_parameter_node (p->second) ==
true)
1716 longest_name = std::max (longest_name,
1717 demangle(p->first).length());
1721 for (boost::property_tree::ptree::const_assoc_iterator
1722 p = current_section.ordered_begin();
1723 p != current_section.not_found(); ++p)
1724 if (is_parameter_node (p->second) ==
true)
1727 out << std::setw(overall_indent_level*2) <<
"" 1729 << demangle(p->first)
1730 << std::setw(longest_name-demangle(p->first).length()+1) <<
" " 1734 const unsigned int pattern_index = p->second.get<
unsigned int> (
"pattern");
1736 const std::vector<std::string> description_str
1738 78 - overall_indent_level*2 - 2,
'|');
1739 if (description_str.size() > 1)
1742 for (
unsigned int i=0; i<description_str.size(); ++i)
1743 out << std::setw(overall_indent_level*2+6) <<
"" 1744 << description_str[i] << std::endl;
1746 else if (description_str.empty() ==
false)
1747 out <<
" " << description_str[0] << std::endl;
1752 if (p->second.get<std::string>(
"documentation").length() != 0)
1753 out << std::setw(overall_indent_level*2 + longest_name + 10) <<
"" 1754 <<
"(" << p->second.get<std::string>(
"documentation") <<
")" << std::endl;
1769 unsigned int n_parameters = 0;
1770 unsigned int n_sections = 0;
1771 for (boost::property_tree::ptree::const_iterator
1772 p = current_section.begin();
1773 p != current_section.end(); ++p)
1774 if (is_parameter_node (p->second) ==
true)
1776 else if (is_alias_node (p->second) ==
false)
1786 out << std::endl << std::endl;
1789 for (boost::property_tree::ptree::const_assoc_iterator
1790 p = current_section.ordered_begin();
1791 p != current_section.not_found(); ++p)
1792 if ((is_parameter_node (p->second) ==
false)
1794 (is_alias_node (p->second) ==
false))
1802 out << std::setw(overall_indent_level*2) <<
"" 1803 <<
"subsection " << demangle(p->first) << std::endl;
1807 auto escape = [] (
const std::string &input)
1813 <<
"\\subsection{Parameters in section \\tt ";
1819 out << escape(demangle(p->first));
1821 out <<
"}" << std::endl;
1822 out <<
"\\label{parameters:";
1825 out << p->first <<
"}";
1845 out << std::setw(overall_indent_level*2) <<
"" 1846 <<
"end" << std::endl
1851 if (overall_indent_level == 0)
1859 out << std::setw(overall_indent_level*2) <<
"" 1860 <<
"end" << std::endl;
1883 overall_indent_level -= 1;
1884 out << std::setw(overall_indent_level*2) <<
"" 1885 <<
"end" << std::endl;
1902 out.
push(
"parameters");
1914 const boost::property_tree::ptree ¤t_section
1921 for (boost::property_tree::ptree::const_assoc_iterator
1922 p = current_section.ordered_begin();
1923 p != current_section.not_found(); ++p)
1924 if (is_parameter_node (p->second) ==
true)
1925 out << demangle(p->first) <<
": " 1926 << p->second.get<std::string>(
"value") << std::endl;
1931 for (boost::property_tree::ptree::const_assoc_iterator
1932 p = current_section.ordered_begin();
1933 p != current_section.not_found(); ++p)
1934 if (is_parameter_node (p->second) ==
false)
1936 out.
push (demangle(p->first));
1948 const std::string &input_filename,
1949 const unsigned int current_line_n)
1952 const std::string original_line = line;
1955 if (line.find(
'#') != std::string::npos)
1956 line.erase (line.find(
'#'), std::string::npos);
1959 while (line.find(
'\t') != std::string::npos)
1960 line.replace (line.find(
'\t'), 1,
" ");
1966 if (line.length() == 0)
1975 line.erase (0, std::string(
"subsection").length()+1);
1993 while ((line.size() > 0) && (std::isspace(line[0])))
1999 "Invalid content after 'end' or 'END' statement."));
2003 "There is no subsection to leave here."));
2013 std::string::size_type pos = line.find(
'=');
2017 "Invalid format of 'set' or 'SET' statement."));
2021 std::string entry_value =
Utilities::trim(std::string(line, pos+1, std::string::npos));
2030 std::cerr <<
"Warning in line <" << current_line_n
2031 <<
"> of file <" << input_filename
2032 <<
">: You are using the deprecated spelling <" 2034 <<
"> of the parameter <" 2036 <<
">." << std::endl;
2052 if (entry_value.find (
'{') == std::string::npos)
2055 const unsigned int pattern_index
2062 patterns[pattern_index]->description()));
2066 const boost::optional<std::string> action_indices_as_string
2068 if (action_indices_as_string)
2070 std::vector<int> action_indices
2072 for (
unsigned int index : action_indices)
2073 if (
actions.size() >= index+1)
2087 (
"No entry with name <" + entry_name +
2088 "> was declared in the current subsection.")));
2097 while ((line.size() > 0) && (line[0] ==
' '))
2104 "The current line is an 'include' or " 2105 "'INCLUDE' statement, but it does not " 2106 "name a file for inclusion."));
2108 std::ifstream input (line.c_str());
2123 "could not be parsed: please check to " 2124 "make sure that the file is not missing a " 2125 "'set', 'include', 'subsection', or 'end' " 2147 for (
unsigned int j=0; j<
patterns.size(); ++j)
2158 std::ostringstream o1, o2;
2160 write_json (o2, *prm2.
entries);
2161 return (o1.str() == o2.str());
2175 const std::string &filename,
2176 const std::string &last_line)
2191 for (
unsigned int run_no=0; run_no<
n_branches; ++run_no)
2222 std::cerr <<
" The entry value" << std::endl
2224 <<
" for the entry named" << std::endl
2226 <<
" does not have the right number of entries for the " << std::endl
2227 <<
" " <<
n_branches <<
" variant runs that will be performed." 2243 const boost::property_tree::ptree ¤t_section
2254 for (boost::property_tree::ptree::const_assoc_iterator
2255 p = current_section.ordered_begin();
2256 p != current_section.not_found(); ++p)
2257 if (is_parameter_node (p->second) ==
true)
2259 const std::string value = p->second.get<std::string>(
"value");
2260 if (value.find(
'{') != std::string::npos)
2267 for (boost::property_tree::ptree::const_iterator
2268 p = current_section.begin();
2269 p != current_section.end(); ++p)
2270 if (is_parameter_node (p->second) ==
false)
2283 unsigned int possibilities = 1;
2285 std::vector<Entry>::iterator choice;
2290 const unsigned int selection
2291 = (run_no/possibilities) % choice->different_values.size();
2292 std::string entry_value;
2294 entry_value = choice->different_values[selection];
2297 if (run_no>=choice->different_values.size())
2299 std::cerr <<
"The given array for entry <" 2300 << choice->entry_name
2301 <<
"> does not contain enough elements! Taking empty string instead." 2306 entry_value = choice->different_values[run_no];
2318 set (choice->entry_name, entry_value);
2323 possibilities *= choice->different_values.size();
2343 const std::string &Name,
2344 const std::string &Value)
2346 subsection_path (ssp), entry_name(Name), entry_value(Value), type (
Entry::array)
2357 std::string prefix (entry_value, 0, entry_value.find(
'{'));
2358 std::string multiple(entry_value, entry_value.find(
'{')+1,
2359 entry_value.rfind(
'}')-entry_value.find(
'{')-1);
2360 std::string postfix (entry_value, entry_value.rfind(
'}')+1, std::string::npos);
2363 if (multiple[0]==
'{')
2364 multiple.erase (0,1);
2365 if (multiple[multiple.size()-1] ==
'}')
2366 multiple.erase (multiple.size()-1, 1);
2369 while (std::isspace (multiple[0])) multiple.erase (0,1);
2370 while (std::isspace (multiple[multiple.size()-1])) multiple.erase (multiple.size()-1,1);
2373 while (multiple.find(
" |") != std::string::npos)
2374 multiple.replace (multiple.find(
" |"), 2,
"|");
2375 while (multiple.find(
"| ") != std::string::npos)
2376 multiple.replace (multiple.find(
"| "), 2,
"|");
2378 while (multiple.find(
'|') != std::string::npos)
2380 different_values.push_back (prefix +
2381 std::string(multiple, 0, multiple.find(
'|'))+
2383 multiple.erase (0, multiple.find(
'|')+1);
2387 different_values.push_back (prefix+multiple+postfix);
2390 if ((entry_value.find(
"{{") != std::string::npos) &&
2391 (entry_value.find(
"}}") != std::string::npos))
2408 DEAL_II_NAMESPACE_CLOSE
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
std::vector< Entry > multiple_choices
long int get_integer(const std::string &entry_string) const
static const char path_separator
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)
static ::ExceptionBase & ExcIO()
virtual void run(ParameterHandler &prm)=0
std::string get_current_path() const
virtual void parse_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="") override
static ::ExceptionBase & ExcEntryUndeclared(std::string arg1)
std::string trim(const std::string &input)
std::string get(const std::string &entry_string) const
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)
std::vector< std::string > break_text_into_lines(const std::string &original_text, const unsigned int width, const char delimiter=' ')
virtual std::unique_ptr< PatternBase > clone() const =0
void set(const std::string &entry_name, const std::string &new_value)
virtual void parse_input_from_json(std::istream &input)
void log_parameters_section(LogStream &out)
#define AssertThrow(cond, exc)
static ::ExceptionBase & ExcValueDoesNotMatchPattern(std::string arg1, std::string arg2)
std::vector< std::string > subsection_path
double string_to_double(const std::string &s)
void init_branches_current_section()
void enter_subsection(const std::string &subsection)
virtual void parse_input_from_xml(std::istream &input)
static ::ExceptionBase & ExcInvalidXMLParameterFile()
static ::ExceptionBase & ExcMessage(std::string arg1)
virtual void create_new(const unsigned int run_no)=0
static ::ExceptionBase & ExcCannotParseLine(int arg1, std::string arg2, std::string arg3)
double get_double(const std::string &entry_name) const
std::size_t memory_consumption() const
#define Assert(cond, exc)
std::string get_current_full_path(const std::string &name) const
bool match_at_string_start(const std::string &name, const std::string &pattern)
std::unique_ptr< boost::property_tree::ptree > entries
void fill_entry_values(const unsigned int run_no)
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::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
std::string replace_in_string(const std::string &input, const std::string &from, const std::string &to)
std::vector< std::unique_ptr< const Patterns::PatternBase > > patterns
virtual bool match(const std::string &test_string) const =0
bool operator==(const ParameterHandler &prm2) const
std::string find(const std::string &filename, const char *open_mode="r")
std::size_t memory_consumption() const
void push(const std::string &text)
virtual std::string description(const OutputStyle style=Machine) const =0
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 declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string())
int string_to_int(const std::string &s)
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 & ExcNotImplemented()
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)
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 split_different_values()
void declare_alias(const std::string &existing_entry_name, const std::string &alias_name, const bool alias_is_deprecated=false)
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
static ::ExceptionBase & ExcInternalError()
virtual void parse_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="")