23 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
24 #include <boost/algorithm/string.hpp>
25 #include <boost/io/ios_state.hpp>
26 #include <boost/property_tree/json_parser.hpp>
27 #include <boost/property_tree/ptree.hpp>
28 #include <boost/property_tree/xml_parser.hpp>
29 #undef BOOST_BIND_GLOBAL_PLACEHOLDERS
46 : entries(new
boost::property_tree::ptree())
53 mangle(
const std::string &s)
62 const bool mangle_whole_string = (s ==
"value");
65 for (
const char c : s)
67 static const std::string allowed_characters(
68 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
70 if ((!mangle_whole_string) &&
71 (allowed_characters.find(c) != std::string::npos))
76 static const char hex[16] = {
'0',
92 u.push_back(hex[
static_cast<unsigned char>(c) / 16]);
93 u.push_back(hex[
static_cast<unsigned char>(c) % 16]);
103 demangle(
const std::string &s)
108 for (
unsigned int i = 0; i < s.size(); ++i)
114 ExcMessage(
"Trying to demangle an invalid string."));
224 u.push_back(
static_cast<char>(c));
238 is_parameter_node(
const boost::property_tree::ptree &p)
240 return static_cast<bool>(p.get_optional<std::string>(
"value"));
249 is_alias_node(
const boost::property_tree::ptree &p)
251 return static_cast<bool>(p.get_optional<std::string>(
"alias"));
261 collate_path_string(
const char separator,
262 const std::vector<std::string> &subsection_path)
264 if (subsection_path.size() > 0)
266 std::string p = mangle(subsection_path[0]);
267 for (
unsigned int i = 1; i < subsection_path.size(); ++i)
270 p += mangle(subsection_path[i]);
284 recursively_sort_parameters(
285 const char separator,
286 const std::vector<std::string> &target_subsection_path,
287 boost::property_tree::ptree &tree)
289 boost::property_tree::ptree ¤t_section =
290 tree.get_child(collate_path_string(separator, target_subsection_path));
295 static auto compare =
296 [](
const std::pair<std::string, boost::property_tree::ptree> &a,
297 const std::pair<std::string, boost::property_tree::ptree> &
b) {
299 (is_parameter_node(a.second) || is_alias_node(a.second));
302 (is_parameter_node(
b.second) || is_alias_node(
b.second));
306 if (a_is_param && !b_is_param)
309 if (!a_is_param && b_is_param)
313 return a.first <
b.first;
316 current_section.sort(compare);
319 for (
auto &p : current_section)
321 if ((is_parameter_node(p.second) ==
false) &&
322 (is_alias_node(p.second) ==
false))
324 const std::string subsection = demangle(p.first);
326 std::vector<std::string> subsection_path = target_subsection_path;
327 subsection_path.emplace_back(subsection);
329 recursively_sort_parameters(separator, subsection_path, tree);
341 recursively_demangle(
const boost::property_tree::ptree &tree_in,
342 boost::property_tree::ptree &tree_out,
343 const bool is_parameter_or_alias_node =
false)
345 for (
const auto &p : tree_in)
347 if (is_parameter_or_alias_node)
349 tree_out.put_child(p.first, p.second);
353 boost::property_tree::ptree temp;
355 if (
const auto val = p.second.get_value_optional<std::string>())
356 temp.put_value<std::string>(*val);
358 recursively_demangle(p.second,
360 is_parameter_node(p.second) ||
361 is_alias_node(p.second));
362 tree_out.put_child(demangle(p.first), temp);
380 "You have chosen either no or multiple style formats. You can choose "
381 "between: PRM, Description, LaTeX, XML, JSON."));
400 if (path.empty() ==
false)
403 path += mangle(name);
412 const std::vector<std::string> &sub_path,
413 const std::string &name)
const
416 if (path.empty() ==
false)
419 if (sub_path.empty() ==
false)
422 path += mangle(name);
431 const std::string &filename,
432 const std::string &last_line,
433 const bool skip_undefined)
440 std::string input_line;
441 std::string fully_concatenated_line;
442 bool is_concatenated =
false;
446 unsigned int current_line_n = 0;
447 unsigned int current_logical_line_n = 0;
461 auto scan_line_or_cleanup = [
this,
463 &saved_path](
const std::string &line,
464 const std::string &filename,
465 const unsigned int line_number) {
468 scan_line(line, filename, line_number, skip_undefined);
480 while (std::getline(input, input_line))
483 if (!is_concatenated)
484 current_logical_line_n = current_line_n;
491 if (last_line.size() != 0 && input_line == last_line)
496 if (input_line.size() != 0 &&
497 input_line.find_last_of(
'\\') == input_line.size() - 1)
499 input_line.erase(input_line.size() - 1);
500 is_concatenated =
true;
502 fully_concatenated_line += input_line;
506 else if (is_concatenated)
508 fully_concatenated_line += input_line;
509 is_concatenated =
false;
515 fully_concatenated_line = input_line;
518 if (!is_concatenated)
520 scan_line_or_cleanup(fully_concatenated_line,
522 current_logical_line_n);
524 fully_concatenated_line.clear();
532 scan_line_or_cleanup(fully_concatenated_line, filename, current_line_n);
536 std::stringstream paths_message;
537 if (saved_path.size() > 0)
539 paths_message <<
"Path before loading input:\n";
542 paths_message << std::setw(i * 2 + 4) <<
" "
543 <<
"subsection " << saved_path[i] <<
'\n';
545 paths_message <<
"Current path:\n";
548 paths_message << std::setw(i * 2 + 4) <<
" "
564 const std::string &last_line,
565 const bool skip_undefined,
566 const bool assert_mandatory_entries_are_found)
568 std::ifstream is(filename);
571 std::string file_ending = filename.substr(filename.find_last_of(
'.') + 1);
572 boost::algorithm::to_lower(file_ending);
573 if (file_ending ==
"prm")
574 parse_input(is, filename, last_line, skip_undefined);
575 else if (file_ending ==
"xml")
577 else if (file_ending ==
"json")
581 ExcMessage(
"Unknown input file name extension. Supported types "
582 "are .prm, .xml, and .json."));
584 if (assert_mandatory_entries_are_found)
592 const std::string &last_line,
593 const bool skip_undefined)
595 std::istringstream input_stream(s);
596 parse_input(input_stream,
"input string", last_line, skip_undefined);
609 read_xml_recursively(
610 const boost::property_tree::ptree &source,
611 const std::string ¤t_path,
612 const char path_separator,
613 const std::vector<std::unique_ptr<const Patterns::PatternBase>> &patterns,
614 const bool skip_undefined,
617 for (
const auto &p : source)
620 if (p.second.empty())
627 prm.
set(demangle(p.first), p.second.data());
635 prm.
set(demangle(p.first), p.second.data());
637 else if (p.second.get_optional<std::string>(
"value"))
644 prm.
set(demangle(p.first),
645 p.second.get<std::string>(
"value"));
653 prm.
set(demangle(p.first), p.second.get<std::string>(
"value"));
660 else if (p.second.get_optional<std::string>(
"alias"))
670 read_xml_recursively(p.second,
671 (current_path.empty() ?
673 current_path + path_separator + p.first),
704 recursively_compress_tree(boost::property_tree::ptree &source)
706 for (
auto &p : source)
708 if (p.second.get_optional<std::string>(
"value"))
711 const auto temp = p.second.get<std::string>(
"value");
715 p.second.put_value<std::string>(temp);
717 else if (p.second.get_optional<std::string>(
"alias"))
723 recursively_compress_tree(p.second);
733 const bool skip_undefined)
740 boost::property_tree::ptree single_node_tree;
743 read_xml(in, single_node_tree);
747 AssertThrow(single_node_tree.get_optional<std::string>(
"ParameterHandler"),
749 "called \"ParameterHandler\"."));
751 const std::size_t n_top_level_elements =
752 std::distance(single_node_tree.begin(), single_node_tree.end());
753 if (n_top_level_elements != 1)
755 std::ostringstream top_level_message;
756 top_level_message <<
"The ParameterHandler input parser found "
757 << n_top_level_elements
758 <<
" top level elements while reading\n "
759 <<
" an XML format input file, but there should be"
760 <<
" exactly one top level element.\n"
761 <<
" The top level elements are:\n";
763 unsigned int entry_n = 0;
764 for (boost::property_tree::ptree::iterator it = single_node_tree.begin();
765 it != single_node_tree.end();
770 << (entry_n != n_top_level_elements - 1 ?
"\n" :
"");
779 const boost::property_tree::ptree &my_entries =
780 single_node_tree.get_child(
"ParameterHandler");
782 read_xml_recursively(
789 const bool skip_undefined)
793 boost::property_tree::ptree node_tree;
798 read_json(in, node_tree);
800 catch (
const std::exception &
e)
805 "The provided JSON file is not valid. Boost aborted with the "
806 "following assert message: \n\n" +
807 std::string(
e.what())));
812 read_xml_recursively(
821 entries = std::make_unique<boost::property_tree::ptree>();
829 const std::string &default_value,
831 const std::string &documentation,
832 const bool has_to_be_set)
842 const std::pair<bool, bool> set_status =
843 std::pair<bool, bool>(has_to_be_set,
false);
851 static_cast<unsigned int>(
patterns.size() - 1));
862 "pattern_description",
875 const std::string &entry,
876 const std::function<
void(
const std::string &)> &action,
877 const bool execute_action)
882 boost::optional<std::string> current_actions =
891 const std::string all_actions =
892 current_actions.get() +
"," +
903 const std::string default_value =
entries->get<std::string>(
905 action(default_value);
913 const std::string &alias_name,
914 const bool alias_is_deprecated)
919 ExcMessage(
"You are trying to declare an alias entry <" + alias_name +
920 "> that references an entry <" + existing_entry_name +
921 ">, but the latter does not exist."));
927 ExcMessage(
"You are trying to declare an alias entry <" + alias_name +
928 "> that references an entry <" + existing_entry_name +
929 ">, but the latter does not seem to be a "
930 "parameter declaration."));
940 ExcMessage(
"You are trying to declare an alias entry <" +
942 "> but a non-alias entry already exists in this "
943 "subsection (i.e., there is either a preexisting "
944 "further subsection, or a parameter entry, with "
945 "the same name as the alias)."));
950 "You are trying to declare an alias entry <" + alias_name +
951 "> but an alias entry already exists in this "
952 "subsection and this existing alias references a "
953 "different parameter entry. Specifically, "
954 "you are trying to reference the entry <" +
955 existing_entry_name +
956 "> whereas the existing alias references "
964 existing_entry_name);
966 "deprecation_status",
967 (alias_is_deprecated ?
"true" :
"false"));
978 boost::property_tree::ptree());
1001 const std::vector<std::string> &sub_path)
const
1005 full_path.insert(full_path.end(), sub_path.begin(), sub_path.end());
1007 boost::optional<const boost::property_tree::ptree &> subsection(
1014 return !(!subsection || is_parameter_node(subsection.get()) ||
1015 is_alias_node(subsection.get()));
1025 if (boost::optional<std::string> value =
entries->get_optional<std::string>(
1039 const std::string &entry_string)
const
1043 if (boost::optional<std::string> value =
entries->get_optional<std::string>(
1068 ExcMessage(
"Can't convert the parameter value <" +
1069 get(entry_string) +
"> for entry <" +
1070 entry_string +
"> to an integer."));
1079 const std::vector<std::string> &entry_subsection_path,
1080 const std::string &entry_string)
const
1090 "Can't convert the parameter value <" +
1091 get(entry_subsection_path, entry_string) +
"> for entry <" +
1094 "> to an integer."));
1111 ExcMessage(
"Can't convert the parameter value <" +
1112 get(entry_string) +
"> for entry <" +
1114 "> to a double precision variable."));
1123 const std::vector<std::string> &entry_subsection_path,
1124 const std::string &entry_string)
const
1129 get(entry_subsection_path, entry_string));
1135 "Can't convert the parameter value <" +
1136 get(entry_subsection_path, entry_string) +
"> for entry <" +
1139 "> to a double precision variable."));
1149 const std::string s =
get(entry_string);
1151 AssertThrow((s ==
"true") || (s ==
"false") || (s ==
"yes") || (s ==
"no"),
1152 ExcMessage(
"Can't convert the parameter value <" +
1153 get(entry_string) +
"> for entry <" + entry_string +
1154 "> to a boolean."));
1155 if (s ==
"true" || s ==
"yes")
1165 const std::vector<std::string> &entry_subsection_path,
1166 const std::string &entry_string)
const
1168 const std::string s =
get(entry_subsection_path, entry_string);
1170 AssertThrow((s ==
"true") || (s ==
"false") || (s ==
"yes") || (s ==
"no"),
1171 ExcMessage(
"Can't convert the parameter value <" +
1172 get(entry_subsection_path, entry_string) +
1176 "> to a boolean."));
1177 if (s ==
"true" || s ==
"yes")
1187 const std::string &new_value)
1201 const unsigned int pattern_index =
1207 "pattern_description")));
1211 const boost::optional<std::string> action_indices_as_string =
1213 if (action_indices_as_string)
1217 for (
const unsigned int index : action_indices)
1218 if (
actions.size() >= index + 1)
1227 map_iter->second = std::pair<bool, bool>(map_iter->second.first,
true);
1230 ExcMessage(
"Could not find parameter " + path +
1231 " in map entries_set_status."));
1242 set(entry_string, std::string(new_value));
1249 std::ostringstream s;
1250 s << std::setprecision(16);
1255 set(entry_string, s.str());
1263 std::ostringstream s;
1268 set(entry_string, s.str());
1278 set(entry_string, (new_value ?
"true" :
"false"));
1289 assert_validity_of_output_style(style);
1294 boost::property_tree::ptree current_entries = *
entries.get();
1302 std::vector<std::string>(),
1310 boost::io::ios_flags_saver restore_flags(out);
1311 boost::io::basic_ios_fill_saver<char> restore_fill_state(out);
1319 if (((style &
Short) != 0) && ((style & (
XML |
JSON)) != 0))
1322 recursively_compress_tree(current_entries);
1325 if ((style &
XML) != 0)
1336 boost::property_tree::ptree single_node_tree;
1337 single_node_tree.add_child(
"ParameterHandler", current_entries);
1339 write_xml(out, single_node_tree);
1343 if ((style &
JSON) != 0)
1345 boost::property_tree::ptree current_entries_damangled;
1346 recursively_demangle(current_entries, current_entries_damangled);
1347 write_json(out, current_entries_damangled);
1352 if (((style &
Short) != 0) && ((style &
Text) != 0))
1356 else if ((style &
Text) != 0)
1358 out <<
"# Listing of Parameters" << std::endl
1359 <<
"# ---------------------" << std::endl;
1361 else if ((style &
LaTeX) != 0)
1363 out <<
"\\subsection{Global parameters}" << std::endl;
1364 out <<
"\\label{parameters:global}" << std::endl;
1365 out << std::endl << std::endl;
1369 out <<
"Listing of Parameters:" << std::endl << std::endl;
1379 std::vector<std::string>(),
1391 const std::string &filename,
1394 std::string extension = filename.substr(filename.find_last_of(
'.') + 1);
1395 boost::algorithm::to_lower(extension);
1398 if (extension ==
"prm")
1399 output_style = style |
PRM;
1400 else if (extension ==
"xml")
1401 output_style = style |
XML;
1402 else if (extension ==
"json")
1403 output_style = style |
JSON;
1404 else if (extension ==
"tex")
1405 output_style = style |
LaTeX;
1407 std::ofstream out(filename);
1416 const boost::property_tree::ptree &tree,
1417 const std::vector<std::string> &target_subsection_path,
1419 const unsigned int indent_level,
1420 std::ostream &out)
const
1427 const boost::property_tree::ptree ¤t_section =
1428 tree.get_child(collate_path_string(
path_separator, target_subsection_path));
1430 unsigned int overall_indent_level = indent_level;
1432 const bool is_short = (style &
Short) != 0;
1434 if ((style &
Text) != 0)
1443 std::size_t longest_name = 0;
1444 std::size_t longest_value = 0;
1445 for (
const auto &p : current_section)
1446 if (is_parameter_node(p.second) ==
true)
1448 longest_name =
std::max(longest_name, demangle(p.first).size());
1449 longest_value =
std::max(longest_value,
1450 p.second.get<std::string>(
"value").size());
1454 bool first_entry =
true;
1455 for (
const auto &p : current_section)
1456 if (is_parameter_node(p.second) ==
true)
1458 const std::string value = p.second.get<std::string>(
"value");
1466 !p.second.get<std::string>(
"documentation").empty())
1468 if (first_entry ==
false)
1471 first_entry =
false;
1473 const std::vector<std::string> doc_lines =
1475 p.second.get<std::string>(
"documentation"),
1476 78 - overall_indent_level * 2 - 2);
1478 for (
const auto &doc_line : doc_lines)
1479 out << std::setw(overall_indent_level * 2) <<
""
1480 <<
"# " << doc_line <<
'\n';
1484 out << std::setw(overall_indent_level * 2) <<
""
1485 <<
"set " << demangle(p.first)
1486 << std::setw(longest_name - demangle(p.first).size() + 1) <<
" "
1492 value != p.second.get<std::string>(
"default_value"))
1494 out << std::setw(longest_value - value.size() + 1) <<
' '
1497 << p.second.get<std::string>(
"default_value");
1503 else if ((style &
LaTeX) != 0)
1505 auto escape = [](
const std::string &input) {
1511 const bool parameters_exist_here =
1512 std::any_of(current_section.begin(),
1513 current_section.end(),
1514 [](
const boost::property_tree::ptree::value_type &p) {
1515 return is_parameter_node(p.second) ||
1516 is_alias_node(p.second);
1518 if (parameters_exist_here)
1520 out <<
"\\begin{itemize}" <<
'\n';
1523 for (
const auto &p : current_section)
1524 if (is_parameter_node(p.second) ==
true)
1526 const std::string value = p.second.get<std::string>(
"value");
1529 out <<
"\\item {\\it Parameter name:} {\\tt "
1530 <<
escape(demangle(p.first)) <<
"}\n"
1531 <<
"\\phantomsection";
1535 std::string label =
"parameters:";
1536 for (
const auto &path : target_subsection_path)
1538 label.append(mangle(path));
1541 label.append(p.first);
1544 if (label.find(
"_20") != std::string::npos)
1548 out <<
"\\label{" << label <<
"}\n";
1552 out <<
"\\index[prmindex]{" <<
escape(demangle(p.first))
1554 out <<
"\\index[prmindexfull]{";
1555 for (
const auto &path : target_subsection_path)
1556 out <<
escape(path) <<
"!";
1557 out <<
escape(demangle(p.first)) <<
"}\n";
1560 out <<
"{\\it Value:} " <<
escape(value) <<
"\n\n"
1562 <<
"{\\it Default:} "
1563 <<
escape(p.second.get<std::string>(
"default_value"))
1570 !p.second.get<std::string>(
"documentation").empty())
1571 out <<
"{\\it Description:} "
1572 << p.second.get<std::string>(
"documentation") <<
"\n\n"
1578 const unsigned int pattern_index =
1579 p.second.get<
unsigned int>(
"pattern");
1580 const std::string desc_str =
1581 patterns[pattern_index]->description(
1583 out <<
"{\\it Possible values:} " << desc_str <<
'\n';
1586 else if (is_alias_node(p.second) ==
true)
1588 const std::string alias = p.second.get<std::string>(
"alias");
1591 out <<
"\\item {\\it Parameter name:} {\\tt "
1592 <<
escape(demangle(p.first)) <<
"}\n"
1593 <<
"\\phantomsection";
1597 std::string label =
"parameters:";
1598 for (
const auto &path : target_subsection_path)
1600 label.append(mangle(path));
1603 label.append(p.first);
1606 if (label.find(
"_20") != std::string::npos)
1610 out <<
"\\label{" << label <<
"}\n";
1614 out <<
"\\index[prmindex]{" <<
escape(demangle(p.first))
1616 out <<
"\\index[prmindexfull]{";
1617 for (
const auto &path : target_subsection_path)
1618 out <<
escape(path) <<
"!";
1619 out <<
escape(demangle(p.first)) <<
"}\n";
1623 <<
"This parameter is an alias for the parameter ``\\texttt{"
1624 <<
escape(alias) <<
"}''."
1625 << (p.second.get<std::string>(
"deprecation_status") ==
1627 " Its use is deprecated." :
1632 out <<
"\\end{itemize}" <<
'\n';
1639 std::size_t longest_name = 0;
1640 for (
const auto &p : current_section)
1641 if (is_parameter_node(p.second) ==
true)
1642 longest_name =
std::max(longest_name, demangle(p.first).size());
1645 for (
const auto &p : current_section)
1646 if (is_parameter_node(p.second) ==
true)
1649 out << std::setw(overall_indent_level * 2) <<
""
1650 <<
"set " << demangle(p.first)
1651 << std::setw(longest_name - demangle(p.first).size() + 1) <<
" "
1655 const unsigned int pattern_index =
1656 p.second.get<
unsigned int>(
"pattern");
1657 const std::string full_desc_str =
1659 const std::vector<std::string> description_str =
1661 full_desc_str, 78 - overall_indent_level * 2 - 2,
'|');
1662 if (description_str.size() > 1)
1665 for (
const auto &description : description_str)
1666 out << std::setw(overall_indent_level * 2 + 6) <<
""
1667 << description <<
'\n';
1669 else if (description_str.empty() ==
false)
1670 out <<
" " << description_str[0] <<
'\n';
1676 p.second.get<std::string>(
"documentation").size() != 0)
1677 out << std::setw(overall_indent_level * 2 + longest_name + 10)
1679 <<
"(" << p.second.get<std::string>(
"documentation") <<
")"
1692 unsigned int n_parameters = 0;
1693 unsigned int n_sections = 0;
1694 for (
const auto &p : current_section)
1695 if (is_parameter_node(p.second) ==
true)
1697 else if (is_alias_node(p.second) ==
false)
1701 (!(((style &
Text) != 0) && is_short)) && (n_parameters != 0) &&
1707 for (
const auto &p : current_section)
1708 if ((is_parameter_node(p.second) ==
false) &&
1709 (is_alias_node(p.second) ==
false))
1714 out << std::setw(overall_indent_level * 2) <<
""
1715 <<
"subsection " << demangle(p.first) <<
'\n';
1717 else if ((style &
LaTeX) != 0)
1719 auto escape = [](
const std::string &input) {
1724 out <<
'\n' <<
"\\subsection{Parameters in section \\tt ";
1728 for (
const auto &path : target_subsection_path)
1729 out <<
escape(path) <<
"/";
1730 out <<
escape(demangle(p.first));
1733 out <<
"\\label{parameters:";
1734 for (
const auto &path : target_subsection_path)
1735 out << mangle(path) <<
"/";
1736 out << p.first <<
"}";
1747 const std::string subsection = demangle(p.first);
1748 std::vector<std::string> directory_path = target_subsection_path;
1749 directory_path.emplace_back(subsection);
1752 tree, directory_path, style, overall_indent_level + 1, out);
1754 if (is_short && ((style &
Text) != 0))
1757 out << std::setw(overall_indent_level * 2) <<
""
1760 else if ((style &
Text) != 0)
1764 out << std::setw(overall_indent_level * 2) <<
""
1770 if (overall_indent_level == 0)
1777 else if ((style &
LaTeX) != 0)
1793 out.
push(
"parameters");
1808 boost::property_tree::ptree sorted_entries;
1809 boost::property_tree::ptree *current_entries =
entries.get();
1815 current_entries = &sorted_entries;
1824 const boost::property_tree::ptree ¤t_section =
1828 for (
const auto &p : current_section)
1829 if (is_parameter_node(p.second) ==
true)
1830 out << demangle(p.first) <<
": " << p.second.get<std::string>(
"value")
1834 for (
const auto &p : current_section)
1835 if (is_parameter_node(p.second) ==
false)
1837 out.
push(demangle(p.first));
1849 const std::string &input_filename,
1850 const unsigned int current_line_n,
1851 const bool skip_undefined)
1854 const std::string original_line = line;
1857 if (line.find(
'#') != std::string::npos)
1858 line.erase(line.find(
'#'), std::string::npos);
1861 while (line.find(
'\t') != std::string::npos)
1862 line.replace(line.find(
'\t'), 1,
" ");
1877 line.erase(0, std::string(
"subsection").size() + 1);
1896 while ((line.size() > 0) && ((std::isspace(line[0])) != 0))
1903 "Invalid content after 'end' or 'END' statement."));
1907 "There is no subsection to leave here."));
1919 pos != std::string::npos,
1922 "Invalid format of 'set' or 'SET' statement."));
1926 std::string entry_value =
1935 "deprecation_status") ==
"true")
1937 std::cerr <<
"Warning in line <" << current_line_n
1938 <<
"> of file <" << input_filename
1939 <<
">: You are using the deprecated spelling <"
1940 << entry_name <<
"> of the parameter <"
1943 <<
">." << std::endl;
1957 if (entry_value.find(
'{') == std::string::npos)
1960 const unsigned int pattern_index =
1968 patterns[pattern_index]->description()));
1972 const boost::optional<std::string> action_indices_as_string =
1975 if (action_indices_as_string)
1977 std::vector<int> action_indices =
1979 action_indices_as_string.get()));
1980 for (
const unsigned int index : action_indices)
1981 if (
actions.size() >= index + 1)
1992 std::pair<bool, bool>(map_iter->second.first,
true);
1995 ExcMessage(
"Could not find parameter " + path +
1996 " in map entries_set_status."));
2004 (
"No entry with name <" + entry_name +
2005 "> was declared in the current subsection.")));
2014 while ((line.size() > 0) && (line[0] ==
' '))
2021 "The current line is an 'include' or "
2022 "'INCLUDE' statement, but it does not "
2023 "name a file for inclusion."));
2025 std::ifstream input(line);
2042 "could not be parsed: please check to "
2043 "make sure that the file is not missing a "
2044 "'set', 'include', 'subsection', or 'end' "
2066 for (
unsigned int j = 0; j <
patterns.size(); ++j)
2077 std::ostringstream o1, o2;
2079 write_json(o2, *prm2.
entries);
2080 return (o1.str() == o2.str());
2085 std::set<std::string>
2088 std::set<std::string> entries_wrongly_not_set;
2091 if (it.second.first ==
true && it.second.second ==
false)
2092 entries_wrongly_not_set.insert(it.first);
2094 return entries_wrongly_not_set;
2102 const std::set<std::string> entries_wrongly_not_set =
2105 if (entries_wrongly_not_set.size() > 0)
2107 std::string list_of_missing_parameters =
"\n\n";
2108 for (
const auto &it : entries_wrongly_not_set)
2109 list_of_missing_parameters +=
" " + it +
"\n";
2110 list_of_missing_parameters +=
"\n";
2113 entries_wrongly_not_set.empty(),
2115 "Not all entries of the parameter handler that were declared with "
2116 "`has_to_be_set = true` have been set. The following parameters " +
2117 list_of_missing_parameters +
2118 " have not been set. "
2119 "A possible reason might be that you did not add these parameter to "
2120 "the input file or that their spelling is not correct."));
2134 const std::string &filename,
2135 const std::string &last_line,
2136 const bool skip_undefined)
2152 for (
unsigned int run_no = 0; run_no <
n_branches; ++run_no)
2171 multiple_choice.split_different_values();
2177 n_branches *= multiple_choice.different_values.size();
2183 if (multiple_choice.different_values.size() !=
n_branches)
2184 std::cerr <<
" The entry value" << std::endl
2185 <<
" " << multiple_choice.entry_value << std::endl
2186 <<
" for the entry named" << std::endl
2187 <<
" " << multiple_choice.entry_name << std::endl
2188 <<
" does not have the right number of entries for the "
2191 <<
" variant runs that will be performed." << std::endl;
2198 for (
unsigned int i = 0; i <
n_branches; ++i)
2207 const boost::property_tree::ptree ¤t_section =
2213 for (
const auto &p : current_section)
2214 if (is_parameter_node(p.second) ==
true)
2216 const std::string value = p.second.get<std::string>(
"value");
2217 if (value.find(
'{') != std::string::npos)
2224 for (
const auto &p : current_section)
2225 if (is_parameter_node(p.second) ==
false)
2238 unsigned int possibilities = 1;
2240 std::vector<Entry>::iterator choice;
2244 const unsigned int selection =
2245 (run_no / possibilities) % choice->different_values.size();
2246 std::string entry_value;
2248 entry_value = choice->different_values[selection];
2251 if (run_no >= choice->different_values.size())
2254 <<
"The given array for entry <" << choice->entry_name
2255 <<
"> does not contain enough elements! Taking empty string instead."
2260 entry_value = choice->different_values[run_no];
2272 set(choice->entry_name, entry_value);
2277 possibilities *= choice->different_values.size();
2288 mem += multiple_choice.memory_consumption();
2296 const std::string &Name,
2297 const std::string &Value)
2298 : subsection_path(ssp)
2300 , entry_value(Value)
2301 , type(
Entry::array)
2313 std::string prefix(entry_value, 0, entry_value.find(
'{'));
2314 std::string multiple(entry_value,
2315 entry_value.find(
'{') + 1,
2316 entry_value.rfind(
'}') - entry_value.find(
'{') - 1);
2317 std::string postfix(entry_value,
2318 entry_value.rfind(
'}') + 1,
2322 if (multiple[0] ==
'{')
2323 multiple.erase(0, 1);
2324 if (multiple.back() ==
'}')
2325 multiple.erase(multiple.size() - 1, 1);
2328 while (std::isspace(multiple[0]) != 0)
2329 multiple.erase(0, 1);
2330 while (std::isspace(multiple.back()) != 0)
2331 multiple.erase(multiple.size() - 1, 1);
2334 while (multiple.find(
" |") != std::string::npos)
2335 multiple.replace(multiple.find(
" |"), 2,
"|");
2336 while (multiple.find(
"| ") != std::string::npos)
2337 multiple.replace(multiple.find(
"| "), 2,
"|");
2339 while (multiple.find(
'|') != std::string::npos)
2341 different_values.push_back(
2342 prefix + std::string(multiple, 0, multiple.find(
'|')) + postfix);
2343 multiple.erase(0, multiple.find(
'|') + 1);
2347 different_values.push_back(prefix + multiple + postfix);
2350 if ((entry_value.find(
"{{") != std::string::npos) &&
2351 (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
virtual void parse_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="", const bool skip_undefined=false)
void init_branches_current_section()
void fill_entry_values(const unsigned int run_no)
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
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
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 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::string description(const OutputStyle style=Machine) const =0
virtual std::unique_ptr< PatternBase > clone() const =0
virtual bool match(const std::string &test_string) const =0
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcUnbalancedSubsections(std::string arg1, std::string arg2)
static ::ExceptionBase & ExcEntryUndeclared(std::string arg1)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcInvalidXMLParameterFile()
#define Assert(cond, exc)
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcValueDoesNotMatchPattern(std::string arg1, std::string arg2)
static ::ExceptionBase & ExcAlreadyAtTopLevel()
static ::ExceptionBase & ExcCannotParseLine(int arg1, std::string arg2, std::string arg3)
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcCannotOpenIncludeStatementFile(int arg1, std::string arg2, std::string arg3)
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)
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcFileNotFound(std::string arg1, std::string arg2)
#define AssertThrow(cond, exc)
types::global_dof_index size_type
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 > 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)