22#define BOOST_BIND_GLOBAL_PLACEHOLDERS
23#include <boost/algorithm/string.hpp>
24#include <boost/io/ios_state.hpp>
25#include <boost/property_tree/json_parser.hpp>
26#include <boost/property_tree/ptree.hpp>
27#include <boost/property_tree/xml_parser.hpp>
28#undef BOOST_BIND_GLOBAL_PLACEHOLDERS
45 : entries(new
boost::property_tree::ptree())
52 mangle(
const std::string &s)
61 const bool mangle_whole_string = (s ==
"value");
64 for (
const char c : s)
66 static const std::string allowed_characters(
67 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
69 if ((!mangle_whole_string) &&
70 (allowed_characters.find(c) != std::string::npos))
75 static const char hex[16] = {
'0',
91 u.push_back(hex[
static_cast<unsigned char>(c) / 16]);
92 u.push_back(hex[
static_cast<unsigned char>(c) % 16]);
102 demangle(
const std::string &s)
107 for (
unsigned int i = 0; i < s.size(); ++i)
113 ExcMessage(
"Trying to demangle an invalid string."));
223 u.push_back(
static_cast<char>(c));
237 is_parameter_node(
const boost::property_tree::ptree &p)
239 return static_cast<bool>(p.get_optional<std::string>(
"value"));
248 is_alias_node(
const boost::property_tree::ptree &p)
250 return static_cast<bool>(p.get_optional<std::string>(
"alias"));
260 collate_path_string(
const char separator,
261 const std::vector<std::string> &subsection_path)
263 if (subsection_path.size() > 0)
265 std::string p = mangle(subsection_path[0]);
266 for (
unsigned int i = 1; i < subsection_path.size(); ++i)
269 p += mangle(subsection_path[i]);
283 recursively_sort_parameters(
284 const char separator,
285 const std::vector<std::string> &target_subsection_path,
286 boost::property_tree::ptree &tree)
288 boost::property_tree::ptree ¤t_section =
289 tree.get_child(collate_path_string(separator, target_subsection_path));
294 static auto compare =
295 [](
const std::pair<std::string, boost::property_tree::ptree> &a,
296 const std::pair<std::string, boost::property_tree::ptree> &
b) {
298 (is_parameter_node(a.second) || is_alias_node(a.second));
301 (is_parameter_node(
b.second) || is_alias_node(
b.second));
305 if (a_is_param && !b_is_param)
308 if (!a_is_param && b_is_param)
312 return a.first <
b.first;
315 current_section.sort(compare);
318 for (
const auto &p : current_section)
320 if ((is_parameter_node(p.second) ==
false) &&
321 (is_alias_node(p.second) ==
false))
323 const std::string subsection = demangle(p.first);
325 std::vector<std::string> subsection_path = target_subsection_path;
326 subsection_path.emplace_back(subsection);
328 recursively_sort_parameters(separator, subsection_path, tree);
341 recursively_mangle_or_demangle(
const boost::property_tree::ptree &tree_in,
342 boost::property_tree::ptree &tree_out,
343 const bool do_mangle,
344 const bool is_parameter_or_alias_node =
false)
346 for (
const auto &p : tree_in)
348 if (is_parameter_or_alias_node)
350 tree_out.put_child(p.first, p.second);
354 boost::property_tree::ptree temp;
356 if (
const auto val = p.second.get_value_optional<std::string>())
357 temp.put_value<std::string>(*val);
359 recursively_mangle_or_demangle(p.second,
362 is_parameter_node(p.second) ||
363 is_alias_node(p.second));
364 tree_out.put_child(do_mangle ? mangle(p.first) : demangle(p.
first),
383 "You have chosen either no or multiple style formats. You can choose "
384 "between: PRM, Description, LaTeX, XML, JSON."));
403 if (path.empty() ==
false)
406 path += mangle(name);
415 const std::vector<std::string> &sub_path,
416 const std::string &name)
const
419 if (path.empty() ==
false)
422 if (sub_path.empty() ==
false)
425 path += mangle(name);
434 const std::string &filename,
435 const std::string &last_line,
436 const bool skip_undefined)
443 std::string input_line;
444 std::string fully_concatenated_line;
445 bool is_concatenated =
false;
449 unsigned int current_line_n = 0;
450 unsigned int current_logical_line_n = 0;
453 std::string deprecation_messages;
467 auto scan_line_or_cleanup =
471 &deprecation_messages](
const std::string &line,
472 const std::string &filename,
473 const unsigned int line_number) {
476 scan_line(line, filename, line_number, skip_undefined);
480 deprecation_messages += e.what();
493 while (std::getline(input, input_line))
496 if (!is_concatenated)
497 current_logical_line_n = current_line_n;
504 if (last_line.size() != 0 && input_line == last_line)
509 if (input_line.size() != 0 &&
510 input_line.find_last_of(
'\\') == input_line.size() - 1)
512 input_line.erase(input_line.size() - 1);
513 is_concatenated =
true;
515 fully_concatenated_line += input_line;
519 else if (is_concatenated)
521 fully_concatenated_line += input_line;
522 is_concatenated =
false;
528 fully_concatenated_line = input_line;
531 if (!is_concatenated)
533 scan_line_or_cleanup(fully_concatenated_line,
535 current_logical_line_n);
537 fully_concatenated_line.clear();
545 scan_line_or_cleanup(fully_concatenated_line, filename, current_line_n);
549 std::stringstream paths_message;
550 if (saved_path.size() > 0)
552 paths_message <<
"Path before loading input:\n";
555 paths_message << std::setw(i * 2 + 4) <<
" "
556 <<
"subsection " << saved_path[i] <<
'\n';
558 paths_message <<
"Current path:\n";
561 paths_message << std::setw(i * 2 + 4) <<
" "
582 const std::string &last_line,
583 const bool skip_undefined,
584 const bool assert_mandatory_entries_are_found)
586 std::ifstream is(filename);
589 std::string file_ending = filename.substr(filename.find_last_of(
'.') + 1);
590 boost::algorithm::to_lower(file_ending);
591 if (file_ending ==
"prm")
592 parse_input(is, filename, last_line, skip_undefined);
593 else if (file_ending ==
"xml")
595 else if (file_ending ==
"json")
599 ExcMessage(
"The given input file <" + filename +
600 "> has a file name extension <" + file_ending +
601 "> that is not recognized. Supported types "
602 "are .prm, .xml, and .json."));
604 if (assert_mandatory_entries_are_found)
612 const std::string &last_line,
613 const bool skip_undefined)
615 std::istringstream input_stream(s);
616 parse_input(input_stream,
"input string", last_line, skip_undefined);
629 read_xml_recursively(
630 const boost::property_tree::ptree &source,
631 const std::string ¤t_path,
632 const char path_separator,
633 const std::vector<std::unique_ptr<const Patterns::PatternBase>> &patterns,
634 const bool skip_undefined,
637 for (
const auto &p : source)
640 if (p.second.empty())
647 prm.
set(demangle(p.first), p.second.data());
655 prm.
set(demangle(p.first), p.second.data());
657 else if (p.second.get_optional<std::string>(
"value"))
664 prm.
set(demangle(p.first),
665 p.second.get<std::string>(
"value"));
673 prm.
set(demangle(p.first), p.second.get<std::string>(
"value"));
680 else if (p.second.get_optional<std::string>(
"alias"))
692 read_xml_recursively(p.second,
693 (current_path.empty() ?
695 current_path + path_separator +
732 recursively_compress_tree(boost::property_tree::ptree &source)
734 for (
auto &p : source)
736 if (p.second.get_optional<std::string>(
"value"))
739 const auto temp = p.second.get<std::string>(
"value");
743 p.second.put_value<std::string>(temp);
745 else if (p.second.get_optional<std::string>(
"alias"))
751 recursively_compress_tree(p.second);
757 recursively_keep_non_default(
const boost::property_tree::ptree &tree_in,
758 boost::property_tree::ptree &tree_out)
760 for (
const auto &p : tree_in)
762 if (is_parameter_node(p.second))
764 const std::string
value = p.second.get<std::string>(
"value");
766 if (value != p.second.get<std::string>(
"default_value"))
767 tree_out.put_child(p.first, p.second);
769 else if (is_alias_node(p.second))
775 boost::property_tree::ptree temp;
777 if (
const auto val = p.second.get_value_optional<std::string>())
778 temp.put_value<std::string>(*val);
780 recursively_keep_non_default(p.second, temp);
783 tree_out.put_child(p.first, temp);
793 const bool skip_undefined)
800 boost::property_tree::ptree single_node_tree;
803 read_xml(in, single_node_tree);
807 AssertThrow(single_node_tree.get_optional<std::string>(
"ParameterHandler"),
809 "called \"ParameterHandler\"."));
811 const std::size_t n_top_level_elements =
812 std::distance(single_node_tree.begin(), single_node_tree.end());
813 if (n_top_level_elements != 1)
815 std::ostringstream top_level_message;
816 top_level_message <<
"The ParameterHandler input parser found "
817 << n_top_level_elements
818 <<
" top level elements while reading\n "
819 <<
" an XML format input file, but there should be"
820 <<
" exactly one top level element.\n"
821 <<
" The top level elements are:\n";
823 unsigned int entry_n = 0;
824 for (boost::property_tree::ptree::iterator it = single_node_tree.begin();
825 it != single_node_tree.end();
830 << (entry_n != n_top_level_elements - 1 ?
"\n" :
"");
839 const boost::property_tree::ptree &my_entries =
840 single_node_tree.get_child(
"ParameterHandler");
842 read_xml_recursively(
849 const bool skip_undefined)
853 boost::property_tree::ptree node_tree;
858 read_json(in, node_tree);
860 catch (
const std::exception &e)
865 "The provided JSON file is not valid. Boost aborted with the "
866 "following assert message: \n\n" +
867 std::string(e.what())));
873 boost::property_tree::ptree node_tree_mangled;
874 recursively_mangle_or_demangle(node_tree,
877 read_xml_recursively(
886 entries = std::make_unique<boost::property_tree::ptree>();
894 const std::string &default_value,
896 const std::string &documentation,
897 const bool has_to_be_set)
907 const std::pair<bool, bool> set_status =
908 std::pair<bool, bool>(has_to_be_set,
false);
916 static_cast<unsigned int>(
patterns.size() - 1));
927 "pattern_description",
940 const std::string &entry,
941 const std::function<
void(
const std::string &)> &action,
942 const bool execute_action)
947 boost::optional<std::string> current_actions =
956 const std::string all_actions =
957 current_actions.get() +
"," +
968 const std::string default_value =
entries->get<std::string>(
970 action(default_value);
978 const std::string &alias_name,
979 const bool alias_is_deprecated)
984 ExcMessage(
"You are trying to declare an alias entry <" + alias_name +
985 "> that references an entry <" + existing_entry_name +
986 ">, but the latter does not exist."));
992 ExcMessage(
"You are trying to declare an alias entry <" + alias_name +
993 "> that references an entry <" + existing_entry_name +
994 ">, but the latter does not seem to be a "
995 "parameter declaration."));
1005 ExcMessage(
"You are trying to declare an alias entry <" +
1007 "> but a non-alias entry already exists in this "
1008 "subsection (i.e., there is either a preexisting "
1009 "further subsection, or a parameter entry, with "
1010 "the same name as the alias)."));
1013 existing_entry_name,
1015 "You are trying to declare an alias entry <" + alias_name +
1016 "> but an alias entry already exists in this "
1017 "subsection and this existing alias references a "
1018 "different parameter entry. Specifically, "
1019 "you are trying to reference the entry <" +
1020 existing_entry_name +
1021 "> whereas the existing alias references "
1029 existing_entry_name);
1031 if (alias_is_deprecated)
1041 const bool is_deprecated)
1046 ExcMessage(
"You are trying to mark the entry <" + existing_entry_name +
1047 "> as deprecated, but the entry does not exist."));
1052 entries->get_optional<std::string>(
1054 entries->get_optional<std::string>(
1056 ExcMessage(
"You are trying to mark the entry <" + existing_entry_name +
1057 "> as deprecated, but the entry does not seem to be a "
1058 "parameter declaration or a parameter alias."));
1061 "deprecation_status",
1062 is_deprecated ?
"true" :
"false");
1069 const bool create_path_if_needed)
1072 const auto path_exists =
1075 if (!create_path_if_needed)
1083 boost::property_tree::ptree());
1106 const std::vector<std::string> &sub_path)
const
1110 full_path.insert(full_path.end(), sub_path.begin(), sub_path.end());
1112 boost::optional<const boost::property_tree::ptree &> subsection(
1119 return !(!subsection || is_parameter_node(subsection.get()) ||
1120 is_alias_node(subsection.get()));
1130 if (boost::optional<std::string> value =
entries->get_optional<std::string>(
1144 const std::string &entry_string)
const
1148 if (boost::optional<std::string> value =
entries->get_optional<std::string>(
1173 ExcMessage(
"Can't convert the parameter value <" +
1174 get(entry_string) +
"> for entry <" +
1175 entry_string +
"> to an integer."));
1184 const std::vector<std::string> &entry_subsection_path,
1185 const std::string &entry_string)
const
1195 "Can't convert the parameter value <" +
1196 get(entry_subsection_path, entry_string) +
"> for entry <" +
1199 "> to an integer."));
1216 ExcMessage(
"Can't convert the parameter value <" +
1217 get(entry_string) +
"> for entry <" +
1219 "> to a double precision variable."));
1228 const std::vector<std::string> &entry_subsection_path,
1229 const std::string &entry_string)
const
1234 get(entry_subsection_path, entry_string));
1240 "Can't convert the parameter value <" +
1241 get(entry_subsection_path, entry_string) +
"> for entry <" +
1244 "> to a double precision variable."));
1254 const std::string s =
get(entry_string);
1256 AssertThrow((s ==
"true") || (s ==
"false") || (s ==
"yes") || (s ==
"no"),
1257 ExcMessage(
"Can't convert the parameter value <" +
1258 get(entry_string) +
"> for entry <" + entry_string +
1259 "> to a boolean."));
1260 if (s ==
"true" || s ==
"yes")
1270 const std::vector<std::string> &entry_subsection_path,
1271 const std::string &entry_string)
const
1273 const std::string s =
get(entry_subsection_path, entry_string);
1275 AssertThrow((s ==
"true") || (s ==
"false") || (s ==
"yes") || (s ==
"no"),
1276 ExcMessage(
"Can't convert the parameter value <" +
1277 get(entry_subsection_path, entry_string) +
1281 "> to a boolean."));
1282 if (s ==
"true" || s ==
"yes")
1292 const std::string &new_value)
1306 const unsigned int pattern_index =
1312 "pattern_description")));
1316 const boost::optional<std::string> action_indices_as_string =
1318 if (action_indices_as_string)
1322 for (
const unsigned int index : action_indices)
1323 if (
actions.size() >= index + 1)
1332 map_iter->second = std::pair<bool, bool>(map_iter->second.first,
true);
1335 ExcMessage(
"Could not find parameter " + path +
1336 " in map entries_set_status."));
1347 set(entry_string, std::string(new_value));
1354 std::ostringstream s;
1355 s << std::setprecision(16);
1360 set(entry_string, s.str());
1368 std::ostringstream s;
1373 set(entry_string, s.str());
1383 set(entry_string, (new_value ?
"true" :
"false"));
1394 assert_validity_of_output_style(style);
1399 boost::property_tree::ptree current_entries = *
entries.get();
1407 std::vector<std::string>(),
1413 boost::property_tree::ptree current_entries_without_default;
1414 recursively_keep_non_default(current_entries,
1415 current_entries_without_default);
1416 current_entries = current_entries_without_default;
1423 boost::io::ios_flags_saver restore_flags(out);
1424 boost::io::basic_ios_fill_saver<char> restore_fill_state(out);
1432 if (((style &
Short) != 0) && ((style & (
XML |
JSON)) != 0))
1435 recursively_compress_tree(current_entries);
1438 if ((style &
XML) != 0)
1449 boost::property_tree::ptree single_node_tree;
1450 single_node_tree.add_child(
"ParameterHandler", current_entries);
1452 write_xml(out, single_node_tree);
1456 if ((style &
JSON) != 0)
1458 boost::property_tree::ptree current_entries_demangled;
1459 recursively_mangle_or_demangle(current_entries,
1460 current_entries_demangled,
1462 write_json(out, current_entries_demangled);
1467 if (((style &
Short) != 0) && ((style &
PRM) != 0))
1471 else if ((style &
PRM) != 0)
1473 out <<
"# Listing of Parameters" << std::endl
1474 <<
"# ---------------------" << std::endl;
1476 else if ((style &
LaTeX) != 0)
1478 out <<
"\\subsection{Global parameters}" << std::endl;
1479 out <<
"\\label{parameters:global}" << std::endl;
1480 out << std::endl << std::endl;
1484 out <<
"Listing of Parameters:" << std::endl << std::endl;
1494 std::vector<std::string>(),
1506 const std::string &filename,
1509 std::string extension = filename.substr(filename.find_last_of(
'.') + 1);
1510 boost::algorithm::to_lower(extension);
1513 if (extension ==
"prm")
1514 output_style = style |
PRM;
1515 else if (extension ==
"xml")
1516 output_style = style |
XML;
1517 else if (extension ==
"json")
1518 output_style = style |
JSON;
1519 else if (extension ==
"tex")
1520 output_style = style |
LaTeX;
1522 std::ofstream out(filename);
1531 const boost::property_tree::ptree &tree,
1532 const std::vector<std::string> &target_subsection_path,
1534 const unsigned int indent_level,
1535 std::ostream &out)
const
1542 const boost::property_tree::ptree ¤t_section =
1543 tree.get_child(collate_path_string(
path_separator, target_subsection_path));
1545 unsigned int overall_indent_level = indent_level;
1547 const bool is_short = (style &
Short) != 0;
1549 if ((style &
PRM) != 0)
1558 std::size_t longest_name = 0;
1559 std::size_t longest_value = 0;
1560 for (
const auto &p : current_section)
1561 if (is_parameter_node(p.second) ==
true)
1563 longest_name =
std::max(longest_name, demangle(p.first).size());
1564 longest_value =
std::max(longest_value,
1565 p.second.get<std::string>(
"value").size());
1569 bool first_entry =
true;
1570 for (
const auto &p : current_section)
1571 if (is_parameter_node(p.second) ==
true)
1573 const std::string value = p.second.get<std::string>(
"value");
1581 !p.second.get<std::string>(
"documentation").empty())
1583 if (first_entry ==
false)
1586 first_entry =
false;
1588 const std::vector<std::string> doc_lines =
1590 p.second.get<std::string>(
"documentation"),
1591 78 - overall_indent_level * 2 - 2);
1593 for (
const auto &doc_line : doc_lines)
1595 out << std::setw(overall_indent_level * 2) <<
'#';
1597 if (!doc_line.empty())
1598 out <<
' ' << doc_line;
1605 out << std::setw(overall_indent_level * 2) <<
"set "
1606 << demangle(p.first)
1607 << std::setw(longest_name - demangle(p.first).size() + 1) <<
' '
1610 out <<
' ' << value;
1615 value != p.second.get<std::string>(
"default_value"))
1617 out << std::setw(longest_value - value.size() + 1) <<
' '
1620 << p.second.get<std::string>(
"default_value");
1626 else if ((style &
LaTeX) != 0)
1628 auto escape = [](
const std::string &input) {
1634 const bool parameters_exist_here =
1635 std::any_of(current_section.begin(),
1636 current_section.end(),
1637 [](
const boost::property_tree::ptree::value_type &p) {
1638 return is_parameter_node(p.second) ||
1639 is_alias_node(p.second);
1641 if (parameters_exist_here)
1643 out <<
"\\begin{itemize}" <<
'\n';
1646 for (
const auto &p : current_section)
1647 if (is_parameter_node(p.second) ==
true)
1649 const std::string value = p.second.get<std::string>(
"value");
1652 out <<
"\\item {\\it Parameter name:} {\\tt "
1653 << escape(demangle(p.first)) <<
"}\n"
1654 <<
"\\phantomsection";
1658 std::string label =
"parameters:";
1659 for (
const auto &path : target_subsection_path)
1661 label.append(mangle(path));
1664 label.append(p.first);
1667 if (label.find(
"_20") != std::string::npos)
1671 out <<
"\\label{" << label <<
"}\n";
1675 out <<
"\\index[prmindex]{" << escape(demangle(p.first))
1677 out <<
"\\index[prmindexfull]{";
1678 for (
const auto &path : target_subsection_path)
1679 out << escape(path) <<
"!";
1680 out << escape(demangle(p.first)) <<
"}\n";
1683 out <<
"{\\it Value:} " << escape(value) <<
"\n\n"
1685 <<
"{\\it Default:} "
1686 << escape(p.second.get<std::string>(
"default_value"))
1693 !p.second.get<std::string>(
"documentation").empty())
1694 out <<
"{\\it Description:} "
1695 << p.second.get<std::string>(
"documentation")
1696 << ((p.second.get_optional<std::string>(
1697 "deprecation_status") &&
1698 p.second.get<std::string>(
"deprecation_status") ==
1700 " This parameter is deprecated.\n\n" :
1707 const unsigned int pattern_index =
1708 p.second.get<
unsigned int>(
"pattern");
1709 const std::string desc_str =
1710 patterns[pattern_index]->description(
1712 out <<
"{\\it Possible values:} " << desc_str <<
'\n';
1715 else if (is_alias_node(p.second) ==
true)
1717 const std::string alias = p.second.get<std::string>(
"alias");
1720 out <<
"\\item {\\it Parameter name:} {\\tt "
1721 << escape(demangle(p.first)) <<
"}\n"
1722 <<
"\\phantomsection";
1726 std::string label =
"parameters:";
1727 for (
const auto &path : target_subsection_path)
1729 label.append(mangle(path));
1732 label.append(p.first);
1735 if (label.find(
"_20") != std::string::npos)
1739 out <<
"\\label{" << label <<
"}\n";
1743 out <<
"\\index[prmindex]{" << escape(demangle(p.first))
1745 out <<
"\\index[prmindexfull]{";
1746 for (
const auto &path : target_subsection_path)
1747 out << escape(path) <<
"!";
1748 out << escape(demangle(p.first)) <<
"}\n";
1752 <<
"This parameter is an alias for the parameter ``\\texttt{"
1753 << escape(alias) <<
"}''."
1754 << (p.second.get<std::string>(
"deprecation_status") ==
1756 " Its use is deprecated." :
1761 out <<
"\\end{itemize}" <<
'\n';
1768 std::size_t longest_name = 0;
1769 for (
const auto &p : current_section)
1770 if (is_parameter_node(p.second) ==
true)
1771 longest_name =
std::max(longest_name, demangle(p.first).size());
1774 for (
const auto &p : current_section)
1775 if (is_parameter_node(p.second) ==
true)
1778 out << std::setw(overall_indent_level * 2) <<
""
1779 <<
"set " << demangle(p.first)
1780 << std::setw(longest_name - demangle(p.first).size() + 1) <<
" "
1784 const unsigned int pattern_index =
1785 p.second.get<
unsigned int>(
"pattern");
1786 const std::string full_desc_str =
1788 const std::vector<std::string> description_str =
1790 full_desc_str, 78 - overall_indent_level * 2 - 2,
'|');
1791 if (description_str.size() > 1)
1794 for (
const auto &description : description_str)
1795 out << std::setw(overall_indent_level * 2 + 6) <<
""
1796 << description <<
'\n';
1798 else if (description_str.empty() ==
false)
1799 out <<
" " << description_str[0] <<
'\n';
1805 p.second.get<std::string>(
"documentation").size() != 0)
1806 out << std::setw(overall_indent_level * 2 + longest_name + 10)
1808 <<
"(" << p.second.get<std::string>(
"documentation") <<
")"
1821 unsigned int n_parameters = 0;
1822 unsigned int n_sections = 0;
1823 for (
const auto &p : current_section)
1824 if (is_parameter_node(p.second) ==
true)
1826 else if (is_alias_node(p.second) ==
false)
1829 if (((style &
Description) == 0) && (!(((style &
PRM) != 0) && is_short)) &&
1830 (n_parameters != 0) && (n_sections != 0))
1835 for (
const auto &p : current_section)
1836 if ((is_parameter_node(p.second) ==
false) &&
1837 (is_alias_node(p.second) ==
false))
1842 out << std::setw(overall_indent_level * 2) <<
""
1843 <<
"subsection " << demangle(p.first) <<
'\n';
1845 else if ((style &
LaTeX) != 0)
1847 auto escape = [](
const std::string &input) {
1852 out <<
'\n' <<
"\\subsection{Parameters in section \\tt ";
1856 for (
const auto &path : target_subsection_path)
1857 out << escape(path) <<
"/";
1858 out << escape(demangle(p.first));
1861 out <<
"\\label{parameters:";
1862 for (
const auto &path : target_subsection_path)
1863 out << mangle(path) <<
"/";
1864 out << p.first <<
"}";
1875 const std::string subsection = demangle(p.first);
1876 std::vector<std::string> directory_path = target_subsection_path;
1877 directory_path.emplace_back(subsection);
1880 tree, directory_path, style, overall_indent_level + 1, out);
1882 if (is_short && ((style &
PRM) != 0))
1885 out << std::setw(overall_indent_level * 2) <<
""
1888 else if ((style &
PRM) != 0)
1892 out << std::setw(overall_indent_level * 2) <<
""
1898 if (overall_indent_level == 0)
1905 else if ((style &
LaTeX) != 0)
1921 out.
push(
"parameters");
1936 boost::property_tree::ptree sorted_entries;
1937 boost::property_tree::ptree *current_entries =
entries.get();
1943 current_entries = &sorted_entries;
1952 const boost::property_tree::ptree ¤t_section =
1956 for (
const auto &p : current_section)
1957 if (is_parameter_node(p.second) ==
true)
1958 out << demangle(p.first) <<
": " << p.second.get<std::string>(
"value")
1962 for (
const auto &p : current_section)
1963 if (is_parameter_node(p.second) ==
false)
1965 out.
push(demangle(p.first));
1977 const std::string &input_filename,
1978 const unsigned int current_line_n,
1979 const bool skip_undefined)
1982 const std::string original_line = line;
1985 if (line.find(
'#') != std::string::npos)
1986 line.erase(line.find(
'#'), std::string::npos);
1989 while (line.find(
'\t') != std::string::npos)
1990 line.replace(line.find(
'\t'), 1,
" ");
2005 line.erase(0, std::string(
"subsection").
size() + 1);
2024 while ((line.size() > 0) && ((std::isspace(line[0])) != 0))
2031 "Invalid content after 'end' or 'END' statement."));
2035 "There is no subsection to leave here."));
2045 std::string::size_type pos = line.find(
'=');
2047 pos != std::string::npos,
2050 "Invalid format of 'set' or 'SET' statement."));
2054 std::string entry_value =
2063 "deprecation_status") ==
"true")
2065 std::cerr <<
"Warning in line <" << current_line_n
2066 <<
"> of file <" << input_filename
2067 <<
">: You are using the deprecated spelling <"
2068 << entry_name <<
"> of the parameter <"
2071 <<
">." << std::endl;
2085 if (entry_value.find(
'{') == std::string::npos)
2088 const unsigned int pattern_index =
2096 patterns[pattern_index]->description()));
2100 const boost::optional<std::string> action_indices_as_string =
2103 if (action_indices_as_string)
2105 std::vector<int> action_indices =
2107 action_indices_as_string.get()));
2108 for (
const unsigned int index : action_indices)
2109 if (
actions.size() >= index + 1)
2121 std::pair<bool, bool>(map_iter->second.first,
true);
2124 ExcMessage(
"Could not find parameter " + path +
2125 " in map entries_set_status."));
2130 "deprecation_status") &&
2132 "deprecation_status") ==
"true")
2146 (
"No entry with name <" + entry_name +
2147 "> was declared in the current subsection.")));
2156 while ((line.size() > 0) && (line[0] ==
' '))
2163 "The current line is an 'include' or "
2164 "'INCLUDE' statement, but it does not "
2165 "name a file for inclusion."));
2167 std::ifstream input(line);
2184 "could not be parsed: please check to "
2185 "make sure that the file is not missing a "
2186 "'set', 'include', 'subsection', or 'end' "
2208 for (
unsigned int j = 0; j <
patterns.size(); ++j)
2219 std::ostringstream o1, o2;
2221 write_json(o2, *prm2.
entries);
2222 return (o1.str() == o2.str());
2227std::set<std::string>
2230 std::set<std::string> entries_wrongly_not_set;
2233 if (it.second.first ==
true && it.second.second ==
false)
2234 entries_wrongly_not_set.insert(it.first);
2236 return entries_wrongly_not_set;
2244 const std::set<std::string> entries_wrongly_not_set =
2247 if (entries_wrongly_not_set.size() > 0)
2249 std::string list_of_missing_parameters =
"\n\n";
2250 for (
const auto &it : entries_wrongly_not_set)
2251 list_of_missing_parameters +=
" " + it +
"\n";
2252 list_of_missing_parameters +=
"\n";
2255 entries_wrongly_not_set.empty(),
2257 "Not all entries of the parameter handler that were declared with "
2258 "`has_to_be_set = true` have been set. The following parameters " +
2259 list_of_missing_parameters +
2260 " have not been set. "
2261 "A possible reason might be that you did not add these parameter to "
2262 "the input file or that their spelling is not correct."));
2276 const std::string &filename,
2277 const std::string &last_line,
2278 const bool skip_undefined)
2294 for (
unsigned int run_no = 0; run_no <
n_branches; ++run_no)
2313 multiple_choice.split_different_values();
2319 n_branches *= multiple_choice.different_values.size();
2325 if (multiple_choice.different_values.size() !=
n_branches)
2326 std::cerr <<
" The entry value" << std::endl
2327 <<
" " << multiple_choice.entry_value << std::endl
2328 <<
" for the entry named" << std::endl
2329 <<
" " << multiple_choice.entry_name << std::endl
2330 <<
" does not have the right number of entries for the "
2333 <<
" variant runs that will be performed." << std::endl;
2340 for (
unsigned int i = 0; i <
n_branches; ++i)
2349 const boost::property_tree::ptree ¤t_section =
2355 for (
const auto &p : current_section)
2356 if (is_parameter_node(p.second) ==
true)
2358 const std::string value = p.second.get<std::string>(
"value");
2359 if (value.find(
'{') != std::string::npos)
2366 for (
const auto &p : current_section)
2367 if (is_parameter_node(p.second) ==
false)
2380 unsigned int possibilities = 1;
2382 std::vector<Entry>::iterator choice;
2386 const unsigned int selection =
2387 (run_no / possibilities) % choice->different_values.size();
2388 std::string entry_value;
2390 entry_value = choice->different_values[selection];
2393 if (run_no >= choice->different_values.size())
2396 <<
"The given array for entry <" << choice->entry_name
2397 <<
"> does not contain enough elements! Taking empty string instead."
2402 entry_value = choice->different_values[run_no];
2414 set(choice->entry_name, entry_value);
2419 possibilities *= choice->different_values.size();
2430 mem += multiple_choice.memory_consumption();
2438 const std::string &Name,
2439 const std::string &Value)
2440 : subsection_path(ssp)
2442 , entry_value(Value)
2443 , type(
Entry::array)
2455 std::string prefix(entry_value, 0, entry_value.find(
'{'));
2456 std::string multiple(entry_value,
2457 entry_value.find(
'{') + 1,
2458 entry_value.rfind(
'}') - entry_value.find(
'{') - 1);
2459 std::string postfix(entry_value,
2460 entry_value.rfind(
'}') + 1,
2464 if (multiple[0] ==
'{')
2465 multiple.erase(0, 1);
2466 if (multiple.back() ==
'}')
2467 multiple.erase(multiple.size() - 1, 1);
2470 while (std::isspace(multiple[0]) != 0)
2471 multiple.erase(0, 1);
2472 while (std::isspace(multiple.back()) != 0)
2473 multiple.erase(multiple.size() - 1, 1);
2476 while (multiple.find(
" |") != std::string::npos)
2477 multiple.replace(multiple.find(
" |"), 2,
"|");
2478 while (multiple.find(
"| ") != std::string::npos)
2479 multiple.replace(multiple.find(
"| "), 2,
"|");
2481 while (multiple.find(
'|') != std::string::npos)
2483 different_values.push_back(
2484 prefix + std::string(multiple, 0, multiple.find(
'|')) + postfix);
2485 multiple.erase(0, multiple.find(
'|') + 1);
2489 different_values.push_back(prefix + multiple + postfix);
2492 if ((entry_value.find(
"{{") != std::string::npos) &&
2493 (entry_value.find(
"}}") != std::string::npos))
void push(const std::string &text)
void split_different_values()
std::size_t memory_consumption() const
virtual void create_new(const unsigned int run_no)=0
virtual void run(ParameterHandler &prm)=0
void init_branches_current_section()
void fill_entry_values(const unsigned int run_no)
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
std::vector< Entry > multiple_choices
static const char path_separator
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::string get_current_path() const
std::vector< std::unique_ptr< const Patterns::PatternBase > > patterns
void enter_subsection(const std::string &subsection, const bool create_path_if_needed=true)
std::ostream & print_parameters(std::ostream &out, const OutputStyle style) const
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
void add_action(const std::string &entry, const std::function< void(const std::string &value)> &action, const bool execute_action=true)
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)
std::map< std::string, std::pair< bool, bool > > entries_set_status
std::string get_current_full_path(const std::string &name) const
void mark_as_deprecated(const std::string &entry, const bool is_deprecated=true)
std::vector< std::function< void(const std::string &)> > actions
void log_parameters_section(LogStream &out, const OutputStyle style=DefaultStyle)
std::unique_ptr< boost::property_tree::ptree > entries
bool subsection_path_exists(const std::vector< std::string > &sub_path) const
void scan_line(std::string line, const std::string &input_filename, const unsigned int current_line_n, const bool skip_undefined)
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
std::vector< std::string > subsection_path
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_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNoSubsection(int arg1, std::string arg2, std::string arg3)
static ::ExceptionBase & ExcCannotOpenIncludeStatementFile(int arg1, std::string arg2, std::string arg3)
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcFileNotOpen(std::string arg1)
static ::ExceptionBase & ExcEntryIsDeprecated(int arg1, std::string arg2, std::string arg3)
static ::ExceptionBase & ExcEncounteredDeprecatedEntries(std::string arg1)
#define Assert(cond, exc)
static ::ExceptionBase & ExcAlreadyAtTopLevel()
static ::ExceptionBase & ExcInvalidEntryForPattern(int arg1, std::string arg2, std::string arg3, std::string arg4, std::string arg5)
static ::ExceptionBase & ExcEntryUndeclared(std::string arg1)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcValueDoesNotMatchPattern(std::string arg1, std::string arg2)
static ::ExceptionBase & ExcUnbalancedSubsections(std::string arg1, std::string arg2)
static ::ExceptionBase & ExcCannotParseLine(int arg1, std::string arg2, std::string arg3)
static ::ExceptionBase & ExcInvalidXMLParameterFile()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
#define DEAL_II_ASSERT_UNREACHABLE()
#define DEAL_II_NOT_IMPLEMENTED()
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
std::string escape(const std::string &input, const PatternBase::OutputStyle style)
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 > &)