24#define BOOST_BIND_GLOBAL_PLACEHOLDERS
25#include <boost/algorithm/string.hpp>
26#include <boost/io/ios_state.hpp>
27#include <boost/property_tree/json_parser.hpp>
28#include <boost/property_tree/ptree.hpp>
29#include <boost/property_tree/xml_parser.hpp>
30#undef BOOST_BIND_GLOBAL_PLACEHOLDERS
48 : entries(new
boost::property_tree::ptree())
55 mangle(
const std::string &s)
64 const bool mangle_whole_string = (s ==
"value");
67 for (
const char c : s)
69 static const std::string allowed_characters(
70 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
72 if ((!mangle_whole_string) &&
73 (allowed_characters.find(c) != std::string::npos))
78 static const char hex[16] = {
'0',
94 u.push_back(hex[
static_cast<unsigned char>(c) / 16]);
95 u.push_back(hex[
static_cast<unsigned char>(c) % 16]);
105 demangle(
const std::string &s)
110 for (
unsigned int i = 0; i < s.size(); ++i)
116 ExcMessage(
"Trying to demangle an invalid string."));
226 u.push_back(
static_cast<char>(c));
240 is_parameter_node(
const boost::property_tree::ptree &p)
242 return static_cast<bool>(p.get_optional<std::string>(
"value"));
251 is_alias_node(
const boost::property_tree::ptree &p)
253 return static_cast<bool>(p.get_optional<std::string>(
"alias"));
263 collate_path_string(
const char separator,
264 const std::vector<std::string> &subsection_path)
266 if (subsection_path.size() > 0)
268 std::string p = mangle(subsection_path[0]);
269 for (
unsigned int i = 1; i < subsection_path.size(); ++i)
272 p += mangle(subsection_path[i]);
286 recursively_sort_parameters(
287 const char separator,
288 const std::vector<std::string> &target_subsection_path,
289 boost::property_tree::ptree & tree)
291 boost::property_tree::ptree ¤t_section =
292 tree.get_child(collate_path_string(separator, target_subsection_path));
297 static auto compare =
298 [](
const std::pair<std::string, boost::property_tree::ptree> &a,
299 const std::pair<std::string, boost::property_tree::ptree> &
b) {
301 (is_parameter_node(a.second) || is_alias_node(a.second));
304 (is_parameter_node(
b.second) || is_alias_node(
b.second));
308 if (a_is_param && !b_is_param)
311 if (!a_is_param && b_is_param)
315 return a.first <
b.first;
318 current_section.sort(compare);
321 for (
auto &p : current_section)
323 if ((is_parameter_node(p.second) ==
false) &&
324 (is_alias_node(p.second) ==
false))
326 const std::string subsection = demangle(p.first);
328 std::vector<std::string> subsection_path = target_subsection_path;
329 subsection_path.emplace_back(subsection);
331 recursively_sort_parameters(separator, subsection_path, tree);
349 "You have chosen either no or multiple style formats. You can choose "
350 "between: PRM, Description, LaTeX, XML, JSON."));
369 if (path.empty() ==
false)
372 path += mangle(name);
381 const std::vector<std::string> &sub_path,
382 const std::string & name)
const
385 if (path.empty() ==
false)
388 if (sub_path.empty() ==
false)
391 path += mangle(name);
400 const std::string &filename,
401 const std::string &last_line,
402 const bool skip_undefined)
409 std::string input_line;
410 std::string fully_concatenated_line;
411 bool is_concatenated =
false;
415 unsigned int current_line_n = 0;
416 unsigned int current_logical_line_n = 0;
430 auto scan_line_or_cleanup = [
this,
432 &saved_path](
const std::string &line,
433 const std::string &filename,
434 const unsigned int line_number) {
437 scan_line(line, filename, line_number, skip_undefined);
449 while (std::getline(input, input_line))
452 if (!is_concatenated)
453 current_logical_line_n = current_line_n;
460 if (last_line.length() != 0 && input_line == last_line)
465 if (input_line.length() != 0 &&
466 input_line.find_last_of(
'\\') == input_line.length() - 1)
468 input_line.erase(input_line.length() - 1);
469 is_concatenated =
true;
471 fully_concatenated_line += input_line;
475 else if (is_concatenated)
477 fully_concatenated_line += input_line;
478 is_concatenated =
false;
484 fully_concatenated_line = input_line;
487 if (!is_concatenated)
489 scan_line_or_cleanup(fully_concatenated_line,
491 current_logical_line_n);
493 fully_concatenated_line.clear();
501 scan_line_or_cleanup(fully_concatenated_line, filename, current_line_n);
505 std::stringstream paths_message;
506 if (saved_path.size() > 0)
508 paths_message <<
"Path before loading input:\n";
511 paths_message << std::setw(i * 2 + 4) <<
" "
512 <<
"subsection " << saved_path[i] <<
'\n';
514 paths_message <<
"Current path:\n";
517 paths_message << std::setw(i * 2 + 4) <<
" "
533 const std::string &last_line,
534 const bool skip_undefined,
535 const bool assert_mandatory_entries_are_found)
537 std::ifstream is(filename);
540 std::string file_ending = filename.substr(filename.find_last_of(
'.') + 1);
541 boost::algorithm::to_lower(file_ending);
542 if (file_ending ==
"prm")
543 parse_input(is, filename, last_line, skip_undefined);
544 else if (file_ending ==
"xml")
546 else if (file_ending ==
"json")
550 ExcMessage(
"Unknown input file name extension. Supported types "
551 "are .prm, .xml, and .json."));
553 if (assert_mandatory_entries_are_found)
561 const std::string &last_line,
562 const bool skip_undefined)
564 std::istringstream input_stream(s);
565 parse_input(input_stream,
"input string", last_line, skip_undefined);
578 read_xml_recursively(
579 const boost::property_tree::ptree &source,
580 const std::string & current_path,
581 const char path_separator,
582 const std::vector<std::unique_ptr<const Patterns::PatternBase>> &patterns,
583 const bool skip_undefined,
586 for (
const auto &p : source)
589 if (p.second.empty())
596 prm.
set(demangle(p.first), p.second.data());
604 prm.
set(demangle(p.first), p.second.data());
606 else if (p.second.get_optional<std::string>(
"value"))
613 prm.
set(demangle(p.first),
614 p.second.get<std::string>(
"value"));
622 prm.
set(demangle(p.first), p.second.get<std::string>(
"value"));
629 else if (p.second.get_optional<std::string>(
"alias"))
639 read_xml_recursively(p.second,
640 (current_path.empty() ?
642 current_path + path_separator + p.first),
673 recursively_compress_tree(boost::property_tree::ptree &source)
675 for (
auto &p : source)
677 if (p.second.get_optional<std::string>(
"value"))
680 const auto temp = p.second.get<std::string>(
"value");
684 p.second.put_value<std::string>(temp);
686 else if (p.second.get_optional<std::string>(
"alias"))
691 recursively_compress_tree(p.second);
701 const bool skip_undefined)
708 boost::property_tree::ptree single_node_tree;
711 read_xml(in, single_node_tree);
715 AssertThrow(single_node_tree.get_optional<std::string>(
"ParameterHandler"),
717 "called \"ParameterHandler\"."));
719 const std::size_t n_top_level_elements =
720 std::distance(single_node_tree.begin(), single_node_tree.end());
721 if (n_top_level_elements != 1)
723 std::ostringstream top_level_message;
724 top_level_message <<
"The ParameterHandler input parser found "
725 << n_top_level_elements
726 <<
" top level elements while reading\n "
727 <<
" an XML format input file, but there should be"
728 <<
" exactly one top level element.\n"
729 <<
" The top level elements are:\n";
731 unsigned int entry_n = 0;
732 for (boost::property_tree::ptree::iterator it = single_node_tree.begin();
733 it != single_node_tree.end();
738 << (entry_n != n_top_level_elements - 1 ?
"\n" :
"");
747 const boost::property_tree::ptree &my_entries =
748 single_node_tree.get_child(
"ParameterHandler");
750 read_xml_recursively(
757 const bool skip_undefined)
761 boost::property_tree::ptree node_tree;
766 read_json(in, node_tree);
768 catch (
const std::exception &
e)
773 "The provided JSON file is not valid. Boost aborted with the "
774 "following assert message: \n\n" +
775 std::string(
e.what())));
780 read_xml_recursively(
789 entries = std::make_unique<boost::property_tree::ptree>();
797 const std::string & default_value,
799 const std::string & documentation,
800 const bool has_to_be_set)
810 const std::pair<bool, bool> set_status =
811 std::pair<bool, bool>(has_to_be_set,
false);
819 static_cast<unsigned int>(
patterns.size() - 1));
830 "pattern_description",
843 const std::string & entry,
844 const std::function<
void(
const std::string &)> &action)
849 boost::optional<std::string> current_actions =
858 const std::string all_actions =
859 current_actions.get() +
"," +
870 const std::string default_value =
entries->get<std::string>(
872 action(default_value);
879 const std::string &alias_name,
880 const bool alias_is_deprecated)
885 ExcMessage(
"You are trying to declare an alias entry <" + alias_name +
886 "> that references an entry <" + existing_entry_name +
887 ">, but the latter does not exist."));
893 ExcMessage(
"You are trying to declare an alias entry <" + alias_name +
894 "> that references an entry <" + existing_entry_name +
895 ">, but the latter does not seem to be a "
896 "parameter declaration."));
906 ExcMessage(
"You are trying to declare an alias entry <" +
908 "> but a non-alias entry already exists in this "
909 "subsection (i.e., there is either a preexisting "
910 "further subsection, or a parameter entry, with "
911 "the same name as the alias)."));
916 "You are trying to declare an alias entry <" + alias_name +
917 "> but an alias entry already exists in this "
918 "subsection and this existing alias references a "
919 "different parameter entry. Specifically, "
920 "you are trying to reference the entry <" +
921 existing_entry_name +
922 "> whereas the existing alias references "
930 existing_entry_name);
932 "deprecation_status",
933 (alias_is_deprecated ?
"true" :
"false"));
944 boost::property_tree::ptree());
967 const std::vector<std::string> &sub_path)
const
971 full_path.insert(full_path.end(), sub_path.begin(), sub_path.end());
973 boost::optional<const boost::property_tree::ptree &> subsection(
980 return !(!subsection || is_parameter_node(subsection.get()) ||
981 is_alias_node(subsection.get()));
991 if (boost::optional<std::string> value =
entries->get_optional<std::string>(
1005 const std::string & entry_string)
const
1009 if (boost::optional<std::string> value =
entries->get_optional<std::string>(
1034 ExcMessage(
"Can't convert the parameter value <" +
1035 get(entry_string) +
"> for entry <" +
1036 entry_string +
"> to an integer."));
1045 const std::vector<std::string> &entry_subsection_path,
1046 const std::string & entry_string)
const
1056 "Can't convert the parameter value <" +
1057 get(entry_subsection_path, entry_string) +
"> for entry <" +
1060 "> to an integer."));
1077 ExcMessage(
"Can't convert the parameter value <" +
1078 get(entry_string) +
"> for entry <" +
1080 "> to a double precision variable."));
1089 const std::vector<std::string> &entry_subsection_path,
1090 const std::string & entry_string)
const
1095 get(entry_subsection_path, entry_string));
1101 "Can't convert the parameter value <" +
1102 get(entry_subsection_path, entry_string) +
"> for entry <" +
1105 "> to a double precision variable."));
1115 const std::string s =
get(entry_string);
1117 AssertThrow((s ==
"true") || (s ==
"false") || (s ==
"yes") || (s ==
"no"),
1118 ExcMessage(
"Can't convert the parameter value <" +
1119 get(entry_string) +
"> for entry <" + entry_string +
1120 "> to a boolean."));
1121 if (s ==
"true" || s ==
"yes")
1131 const std::vector<std::string> &entry_subsection_path,
1132 const std::string & entry_string)
const
1134 const std::string s =
get(entry_subsection_path, entry_string);
1136 AssertThrow((s ==
"true") || (s ==
"false") || (s ==
"yes") || (s ==
"no"),
1137 ExcMessage(
"Can't convert the parameter value <" +
1138 get(entry_subsection_path, entry_string) +
1142 "> to a boolean."));
1143 if (s ==
"true" || s ==
"yes")
1153 const std::string &new_value)
1167 const unsigned int pattern_index =
1173 "pattern_description")));
1177 const boost::optional<std::string> action_indices_as_string =
1179 if (action_indices_as_string)
1183 for (
const unsigned int index : action_indices)
1184 if (
actions.size() >= index + 1)
1193 map_iter->second = std::pair<bool, bool>(map_iter->second.first,
true);
1196 ExcMessage(
"Could not find parameter " + path +
1197 " in map entries_set_status."));
1208 set(entry_string, std::string(new_value));
1215 std::ostringstream s;
1216 s << std::setprecision(16);
1221 set(entry_string, s.str());
1229 std::ostringstream s;
1234 set(entry_string, s.str());
1244 set(entry_string, (new_value ?
"true" :
"false"));
1255 assert_validity_of_output_style(style);
1260 boost::property_tree::ptree current_entries = *
entries.get();
1268 std::vector<std::string>(),
1276 boost::io::ios_flags_saver restore_flags(out);
1277 boost::io::basic_ios_fill_saver<char> restore_fill_state(out);
1288 recursively_compress_tree(current_entries);
1302 boost::property_tree::ptree single_node_tree;
1303 single_node_tree.add_child(
"ParameterHandler", current_entries);
1305 write_xml(out, single_node_tree);
1311 write_json(out, current_entries);
1320 else if (style &
Text)
1322 out <<
"# Listing of Parameters" << std::endl
1323 <<
"# ---------------------" << std::endl;
1325 else if (style &
LaTeX)
1327 out <<
"\\subsection{Global parameters}" << std::endl;
1328 out <<
"\\label{parameters:global}" << std::endl;
1329 out << std::endl << std::endl;
1333 out <<
"Listing of Parameters:" << std::endl << std::endl;
1343 std::vector<std::string>(),
1355 const std::string & filename,
1358 std::string extension = filename.substr(filename.find_last_of(
'.') + 1);
1359 boost::algorithm::to_lower(extension);
1362 if (extension ==
"prm")
1363 output_style = style |
PRM;
1364 else if (extension ==
"xml")
1365 output_style = style |
XML;
1366 else if (extension ==
"json")
1367 output_style = style |
JSON;
1368 else if (extension ==
"tex")
1369 output_style = style |
LaTeX;
1371 std::ofstream out(filename);
1380 const boost::property_tree::ptree &tree,
1381 const std::vector<std::string> & target_subsection_path,
1383 const unsigned int indent_level,
1384 std::ostream & out)
const
1391 const boost::property_tree::ptree ¤t_section =
1392 tree.get_child(collate_path_string(
path_separator, target_subsection_path));
1394 unsigned int overall_indent_level = indent_level;
1396 const bool is_short = style &
Short;
1407 std::size_t longest_name = 0;
1408 std::size_t longest_value = 0;
1409 for (
const auto &p : current_section)
1410 if (is_parameter_node(p.second) ==
true)
1412 longest_name =
std::max(longest_name, demangle(p.first).length());
1415 p.second.get<std::string>(
"value").length());
1419 bool first_entry =
true;
1420 for (
const auto &p : current_section)
1421 if (is_parameter_node(p.second) ==
true)
1423 const std::string value = p.second.get<std::string>(
"value");
1431 !p.second.get<std::string>(
"documentation").empty())
1433 if (first_entry ==
false)
1436 first_entry =
false;
1438 const std::vector<std::string> doc_lines =
1440 p.second.get<std::string>(
"documentation"),
1441 78 - overall_indent_level * 2 - 2);
1443 for (
const auto &doc_line : doc_lines)
1444 out << std::setw(overall_indent_level * 2) <<
""
1445 <<
"# " << doc_line <<
'\n';
1449 out << std::setw(overall_indent_level * 2) <<
""
1450 <<
"set " << demangle(p.first)
1451 << std::setw(longest_name - demangle(p.first).length() + 1)
1458 value != p.second.get<std::string>(
"default_value"))
1460 out << std::setw(longest_value - value.length() + 1) <<
' '
1463 << p.second.get<std::string>(
"default_value");
1469 else if (style &
LaTeX)
1471 auto escape = [](
const std::string &input) {
1477 const bool parameters_exist_here =
1478 std::any_of(current_section.begin(),
1479 current_section.end(),
1480 [](
const boost::property_tree::ptree::value_type &p) {
1481 return is_parameter_node(p.second) ||
1482 is_alias_node(p.second);
1484 if (parameters_exist_here)
1486 out <<
"\\begin{itemize}" <<
'\n';
1489 for (
const auto &p : current_section)
1490 if (is_parameter_node(p.second) ==
true)
1492 const std::string value = p.second.get<std::string>(
"value");
1495 out <<
"\\item {\\it Parameter name:} {\\tt "
1496 <<
escape(demangle(p.first)) <<
"}\n"
1497 <<
"\\phantomsection";
1501 std::string label =
"parameters:";
1502 for (
const auto &path : target_subsection_path)
1504 label.append(mangle(path));
1507 label.append(p.first);
1510 if (label.find(
"_20") != std::string::npos)
1514 out <<
"\\label{" << label <<
"}\n";
1518 out <<
"\\index[prmindex]{" <<
escape(demangle(p.first))
1520 out <<
"\\index[prmindexfull]{";
1521 for (
const auto &path : target_subsection_path)
1522 out <<
escape(path) <<
"!";
1523 out <<
escape(demangle(p.first)) <<
"}\n";
1526 out <<
"{\\it Value:} " <<
escape(value) <<
"\n\n"
1528 <<
"{\\it Default:} "
1529 <<
escape(p.second.get<std::string>(
"default_value"))
1536 !p.second.get<std::string>(
"documentation").empty())
1537 out <<
"{\\it Description:} "
1538 << p.second.get<std::string>(
"documentation") <<
"\n\n"
1544 const unsigned int pattern_index =
1545 p.second.get<
unsigned int>(
"pattern");
1546 const std::string desc_str =
1547 patterns[pattern_index]->description(
1549 out <<
"{\\it Possible values:} " << desc_str <<
'\n';
1552 else if (is_alias_node(p.second) ==
true)
1554 const std::string alias = p.second.get<std::string>(
"alias");
1557 out <<
"\\item {\\it Parameter name:} {\\tt "
1558 <<
escape(demangle(p.first)) <<
"}\n"
1559 <<
"\\phantomsection";
1563 std::string label =
"parameters:";
1564 for (
const auto &path : target_subsection_path)
1566 label.append(mangle(path));
1569 label.append(p.first);
1572 if (label.find(
"_20") != std::string::npos)
1576 out <<
"\\label{" << label <<
"}\n";
1580 out <<
"\\index[prmindex]{" <<
escape(demangle(p.first))
1582 out <<
"\\index[prmindexfull]{";
1583 for (
const auto &path : target_subsection_path)
1584 out <<
escape(path) <<
"!";
1585 out <<
escape(demangle(p.first)) <<
"}\n";
1589 <<
"This parameter is an alias for the parameter ``\\texttt{"
1590 <<
escape(alias) <<
"}''."
1591 << (p.second.get<std::string>(
"deprecation_status") ==
1593 " Its use is deprecated." :
1598 out <<
"\\end{itemize}" <<
'\n';
1605 std::size_t longest_name = 0;
1606 for (
const auto &p : current_section)
1607 if (is_parameter_node(p.second) ==
true)
1608 longest_name =
std::max(longest_name, demangle(p.first).length());
1611 for (
const auto &p : current_section)
1612 if (is_parameter_node(p.second) ==
true)
1615 out << std::setw(overall_indent_level * 2) <<
""
1616 <<
"set " << demangle(p.first)
1617 << std::setw(longest_name - demangle(p.first).length() + 1)
1622 const unsigned int pattern_index =
1623 p.second.get<
unsigned int>(
"pattern");
1624 const std::string full_desc_str =
1626 const std::vector<std::string> description_str =
1628 full_desc_str, 78 - overall_indent_level * 2 - 2,
'|');
1629 if (description_str.size() > 1)
1632 for (
const auto &description : description_str)
1633 out << std::setw(overall_indent_level * 2 + 6) <<
""
1634 << description <<
'\n';
1636 else if (description_str.empty() ==
false)
1637 out <<
" " << description_str[0] <<
'\n';
1643 p.second.get<std::string>(
"documentation").length() != 0)
1644 out << std::setw(overall_indent_level * 2 + longest_name + 10)
1646 <<
"(" << p.second.get<std::string>(
"documentation") <<
")"
1659 unsigned int n_parameters = 0;
1660 unsigned int n_sections = 0;
1661 for (
const auto &p : current_section)
1662 if (is_parameter_node(p.second) ==
true)
1664 else if (is_alias_node(p.second) ==
false)
1668 (n_parameters != 0) && (n_sections != 0))
1673 for (
const auto &p : current_section)
1674 if ((is_parameter_node(p.second) ==
false) &&
1675 (is_alias_node(p.second) ==
false))
1680 out << std::setw(overall_indent_level * 2) <<
""
1681 <<
"subsection " << demangle(p.first) <<
'\n';
1683 else if (style &
LaTeX)
1685 auto escape = [](
const std::string &input) {
1690 out <<
'\n' <<
"\\subsection{Parameters in section \\tt ";
1694 for (
const auto &path : target_subsection_path)
1695 out <<
escape(path) <<
"/";
1696 out <<
escape(demangle(p.first));
1699 out <<
"\\label{parameters:";
1700 for (
const auto &path : target_subsection_path)
1701 out << mangle(path) <<
"/";
1702 out << p.first <<
"}";
1713 const std::string subsection = demangle(p.first);
1714 std::vector<std::string> directory_path = target_subsection_path;
1715 directory_path.emplace_back(subsection);
1718 tree, directory_path, style, overall_indent_level + 1, out);
1720 if (is_short && (style &
Text))
1723 out << std::setw(overall_indent_level * 2) <<
""
1726 else if (style &
Text)
1730 out << std::setw(overall_indent_level * 2) <<
""
1736 if (overall_indent_level == 0)
1743 else if (style &
LaTeX)
1759 out.
push(
"parameters");
1774 boost::property_tree::ptree sorted_entries;
1775 boost::property_tree::ptree *current_entries =
entries.get();
1781 current_entries = &sorted_entries;
1790 const boost::property_tree::ptree ¤t_section =
1794 for (
const auto &p : current_section)
1795 if (is_parameter_node(p.second) ==
true)
1796 out << demangle(p.first) <<
": " << p.second.get<std::string>(
"value")
1800 for (
const auto &p : current_section)
1801 if (is_parameter_node(p.second) ==
false)
1803 out.
push(demangle(p.first));
1815 const std::string &input_filename,
1816 const unsigned int current_line_n,
1817 const bool skip_undefined)
1820 const std::string original_line = line;
1823 if (line.find(
'#') != std::string::npos)
1824 line.erase(line.find(
'#'), std::string::npos);
1827 while (line.find(
'\t') != std::string::npos)
1828 line.replace(line.find(
'\t'), 1,
" ");
1834 if (line.length() == 0)
1843 line.erase(0, std::string(
"subsection").length() + 1);
1862 while ((line.size() > 0) && (std::isspace(line[0])))
1869 "Invalid content after 'end' or 'END' statement."));
1873 "There is no subsection to leave here."));
1885 pos != std::string::npos,
1888 "Invalid format of 'set' or 'SET' statement."));
1892 std::string entry_value =
1901 "deprecation_status") ==
"true")
1903 std::cerr <<
"Warning in line <" << current_line_n
1904 <<
"> of file <" << input_filename
1905 <<
">: You are using the deprecated spelling <"
1906 << entry_name <<
"> of the parameter <"
1909 <<
">." << std::endl;
1923 if (entry_value.find(
'{') == std::string::npos)
1926 const unsigned int pattern_index =
1934 patterns[pattern_index]->description()));
1938 const boost::optional<std::string> action_indices_as_string =
1941 if (action_indices_as_string)
1943 std::vector<int> action_indices =
1945 action_indices_as_string.get()));
1946 for (
const unsigned int index : action_indices)
1947 if (
actions.size() >= index + 1)
1961 (
"No entry with name <" + entry_name +
1962 "> was declared in the current subsection.")));
1971 while ((line.size() > 0) && (line[0] ==
' '))
1978 "The current line is an 'include' or "
1979 "'INCLUDE' statement, but it does not "
1980 "name a file for inclusion."));
1982 std::ifstream input(line.c_str());
1999 "could not be parsed: please check to "
2000 "make sure that the file is not missing a "
2001 "'set', 'include', 'subsection', or 'end' "
2023 for (
unsigned int j = 0; j <
patterns.size(); ++j)
2034 std::ostringstream o1, o2;
2036 write_json(o2, *prm2.
entries);
2037 return (o1.str() == o2.str());
2042std::set<std::string>
2045 std::set<std::string> entries_wrongly_not_set;
2048 if (it.second.first ==
true && it.second.second ==
false)
2049 entries_wrongly_not_set.insert(it.first);
2051 return entries_wrongly_not_set;
2059 const std::set<std::string> entries_wrongly_not_set =
2062 if (entries_wrongly_not_set.size() > 0)
2064 std::string list_of_missing_parameters =
"\n\n";
2065 for (
const auto &it : entries_wrongly_not_set)
2066 list_of_missing_parameters +=
" " + it +
"\n";
2067 list_of_missing_parameters +=
"\n";
2070 entries_wrongly_not_set.size() == 0,
2072 "Not all entries of the parameter handler that were declared with "
2073 "`has_to_be_set = true` have been set. The following parameters " +
2074 list_of_missing_parameters +
2075 " have not been set. "
2076 "A possible reason might be that you did not add these parameter to "
2077 "the input file or that their spelling is not correct."));
2091 const std::string &filename,
2092 const std::string &last_line,
2093 const bool skip_undefined)
2109 for (
unsigned int run_no = 0; run_no <
n_branches; ++run_no)
2128 multiple_choice.split_different_values();
2134 n_branches *= multiple_choice.different_values.size();
2140 if (multiple_choice.different_values.size() !=
n_branches)
2141 std::cerr <<
" The entry value" << std::endl
2142 <<
" " << multiple_choice.entry_value << std::endl
2143 <<
" for the entry named" << std::endl
2144 <<
" " << multiple_choice.entry_name << std::endl
2145 <<
" does not have the right number of entries for the "
2148 <<
" variant runs that will be performed." << std::endl;
2155 for (
unsigned int i = 0; i <
n_branches; ++i)
2164 const boost::property_tree::ptree ¤t_section =
2170 for (
const auto &p : current_section)
2171 if (is_parameter_node(p.second) ==
true)
2173 const std::string value = p.second.get<std::string>(
"value");
2174 if (value.find(
'{') != std::string::npos)
2181 for (
const auto &p : current_section)
2182 if (is_parameter_node(p.second) ==
false)
2195 unsigned int possibilities = 1;
2197 std::vector<Entry>::iterator choice;
2201 const unsigned int selection =
2202 (run_no / possibilities) % choice->different_values.size();
2203 std::string entry_value;
2205 entry_value = choice->different_values[selection];
2208 if (run_no >= choice->different_values.size())
2211 <<
"The given array for entry <" << choice->entry_name
2212 <<
"> does not contain enough elements! Taking empty string instead."
2217 entry_value = choice->different_values[run_no];
2229 set(choice->entry_name, entry_value);
2234 possibilities *= choice->different_values.size();
2245 mem += multiple_choice.memory_consumption();
2253 const std::string & Name,
2254 const std::string & Value)
2255 : subsection_path(ssp)
2257 , entry_value(Value)
2258 , type(
Entry::array)
2270 std::string prefix(entry_value, 0, entry_value.find(
'{'));
2271 std::string multiple(entry_value,
2272 entry_value.find(
'{') + 1,
2273 entry_value.rfind(
'}') - entry_value.find(
'{') - 1);
2274 std::string postfix(entry_value,
2275 entry_value.rfind(
'}') + 1,
2279 if (multiple[0] ==
'{')
2280 multiple.erase(0, 1);
2281 if (multiple[multiple.size() - 1] ==
'}')
2282 multiple.erase(multiple.size() - 1, 1);
2285 while (std::isspace(multiple[0]))
2286 multiple.erase(0, 1);
2287 while (std::isspace(multiple[multiple.size() - 1]))
2288 multiple.erase(multiple.size() - 1, 1);
2291 while (multiple.find(
" |") != std::string::npos)
2292 multiple.replace(multiple.find(
" |"), 2,
"|");
2293 while (multiple.find(
"| ") != std::string::npos)
2294 multiple.replace(multiple.find(
"| "), 2,
"|");
2296 while (multiple.find(
'|') != std::string::npos)
2298 different_values.push_back(
2299 prefix + std::string(multiple, 0, multiple.find(
'|')) + postfix);
2300 multiple.erase(0, multiple.find(
'|') + 1);
2304 different_values.push_back(prefix + multiple + postfix);
2307 if ((entry_value.find(
"{{") != std::string::npos) &&
2308 (entry_value.find(
"}}") != std::string::npos))
void push(const std::string &text)
std::size_t memory_consumption() const
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)
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)
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 log_parameters_section(LogStream &out, const OutputStyle style=DefaultStyle)
bool subsection_path_exists(const std::vector< std::string > &sub_path) const
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)
virtual std::unique_ptr< PatternBase > clone() const =0
virtual std::string description(const OutputStyle style=Machine) const =0
virtual bool match(const std::string &test_string) const =0
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
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 & ExcFileNotFound(std::string arg1, std::string arg2)
static ::ExceptionBase & ExcIO()
std::string get_current_path() const
std::vector< std::unique_ptr< const Patterns::PatternBase > > patterns
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
static ::ExceptionBase & ExcNotImplemented()
void fill_entry_values(const unsigned int run_no)
virtual void create_new(const unsigned int run_no)=0
#define Assert(cond, exc)
static ::ExceptionBase & ExcAlreadyAtTopLevel()
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)
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)
virtual void run(ParameterHandler &prm)=0
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcValueDoesNotMatchPattern(std::string arg1, std::string arg2)
static ::ExceptionBase & ExcUnbalancedSubsections(std::string arg1, std::string arg2)
std::vector< Entry > multiple_choices
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()
static ::ExceptionBase & ExcMessage(std::string arg1)
std::vector< std::string > subsection_path
void split_different_values()
std::size_t memory_consumption() const
#define AssertThrow(cond, exc)
types::global_dof_index size_type
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
std::string escape(const std::string &input, const PatternBase::OutputStyle style)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
std::string replace_in_string(const std::string &input, const std::string &from, const std::string &to)
std::vector< std::string > break_text_into_lines(const std::string &original_text, const unsigned int width, const char delimiter=' ')
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
bool match_at_string_start(const std::string &name, const std::string &pattern)
double string_to_double(const std::string &s)
std::string trim(const std::string &input)
int string_to_int(const std::string &s)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)