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);
343 recursively_demangle(
const boost::property_tree::ptree &tree_in,
344 boost::property_tree::ptree & tree_out,
345 const bool is_parameter_or_alias_node =
false)
347 for (
const auto &p : tree_in)
349 if (is_parameter_or_alias_node)
351 tree_out.put_child(p.first, p.second);
355 boost::property_tree::ptree temp;
357 if (
const auto val = p.second.get_value_optional<std::string>())
358 temp.put_value<std::string>(*val);
360 recursively_demangle(p.second,
362 is_parameter_node(p.second) ||
363 is_alias_node(p.second));
364 tree_out.put_child(demangle(p.first), temp);
382 "You have chosen either no or multiple style formats. You can choose "
383 "between: PRM, Description, LaTeX, XML, JSON."));
402 if (path.empty() ==
false)
405 path += mangle(name);
414 const std::vector<std::string> &sub_path,
415 const std::string & name)
const
418 if (path.empty() ==
false)
421 if (sub_path.empty() ==
false)
424 path += mangle(name);
433 const std::string &filename,
434 const std::string &last_line,
435 const bool skip_undefined)
442 std::string input_line;
443 std::string fully_concatenated_line;
444 bool is_concatenated =
false;
448 unsigned int current_line_n = 0;
449 unsigned int current_logical_line_n = 0;
463 auto scan_line_or_cleanup = [
this,
465 &saved_path](
const std::string &line,
466 const std::string &filename,
467 const unsigned int line_number) {
470 scan_line(line, filename, line_number, skip_undefined);
482 while (std::getline(input, input_line))
485 if (!is_concatenated)
486 current_logical_line_n = current_line_n;
493 if (last_line.size() != 0 && input_line == last_line)
498 if (input_line.size() != 0 &&
499 input_line.find_last_of(
'\\') == input_line.size() - 1)
501 input_line.erase(input_line.size() - 1);
502 is_concatenated =
true;
504 fully_concatenated_line += input_line;
508 else if (is_concatenated)
510 fully_concatenated_line += input_line;
511 is_concatenated =
false;
517 fully_concatenated_line = input_line;
520 if (!is_concatenated)
522 scan_line_or_cleanup(fully_concatenated_line,
524 current_logical_line_n);
526 fully_concatenated_line.clear();
534 scan_line_or_cleanup(fully_concatenated_line, filename, current_line_n);
538 std::stringstream paths_message;
539 if (saved_path.size() > 0)
541 paths_message <<
"Path before loading input:\n";
544 paths_message << std::setw(i * 2 + 4) <<
" "
545 <<
"subsection " << saved_path[i] <<
'\n';
547 paths_message <<
"Current path:\n";
550 paths_message << std::setw(i * 2 + 4) <<
" "
566 const std::string &last_line,
567 const bool skip_undefined,
568 const bool assert_mandatory_entries_are_found)
570 std::ifstream is(filename);
573 std::string file_ending = filename.substr(filename.find_last_of(
'.') + 1);
574 boost::algorithm::to_lower(file_ending);
575 if (file_ending ==
"prm")
576 parse_input(is, filename, last_line, skip_undefined);
577 else if (file_ending ==
"xml")
579 else if (file_ending ==
"json")
583 ExcMessage(
"Unknown input file name extension. Supported types "
584 "are .prm, .xml, and .json."));
586 if (assert_mandatory_entries_are_found)
594 const std::string &last_line,
595 const bool skip_undefined)
597 std::istringstream input_stream(s);
598 parse_input(input_stream,
"input string", last_line, skip_undefined);
611 read_xml_recursively(
612 const boost::property_tree::ptree &source,
613 const std::string & current_path,
614 const char path_separator,
615 const std::vector<std::unique_ptr<const Patterns::PatternBase>> &patterns,
616 const bool skip_undefined,
619 for (
const auto &p : source)
622 if (p.second.empty())
629 prm.
set(demangle(p.first), p.second.data());
637 prm.
set(demangle(p.first), p.second.data());
639 else if (p.second.get_optional<std::string>(
"value"))
646 prm.
set(demangle(p.first),
647 p.second.get<std::string>(
"value"));
655 prm.
set(demangle(p.first), p.second.get<std::string>(
"value"));
662 else if (p.second.get_optional<std::string>(
"alias"))
672 read_xml_recursively(p.second,
673 (current_path.empty() ?
675 current_path + path_separator + p.first),
706 recursively_compress_tree(boost::property_tree::ptree &source)
708 for (
auto &p : source)
710 if (p.second.get_optional<std::string>(
"value"))
713 const auto temp = p.second.get<std::string>(
"value");
717 p.second.put_value<std::string>(temp);
719 else if (p.second.get_optional<std::string>(
"alias"))
724 recursively_compress_tree(p.second);
734 const bool skip_undefined)
741 boost::property_tree::ptree single_node_tree;
744 read_xml(in, single_node_tree);
748 AssertThrow(single_node_tree.get_optional<std::string>(
"ParameterHandler"),
750 "called \"ParameterHandler\"."));
752 const std::size_t n_top_level_elements =
753 std::distance(single_node_tree.begin(), single_node_tree.end());
754 if (n_top_level_elements != 1)
756 std::ostringstream top_level_message;
757 top_level_message <<
"The ParameterHandler input parser found "
758 << n_top_level_elements
759 <<
" top level elements while reading\n "
760 <<
" an XML format input file, but there should be"
761 <<
" exactly one top level element.\n"
762 <<
" The top level elements are:\n";
764 unsigned int entry_n = 0;
765 for (boost::property_tree::ptree::iterator it = single_node_tree.begin();
766 it != single_node_tree.end();
771 << (entry_n != n_top_level_elements - 1 ?
"\n" :
"");
780 const boost::property_tree::ptree &my_entries =
781 single_node_tree.get_child(
"ParameterHandler");
783 read_xml_recursively(
790 const bool skip_undefined)
794 boost::property_tree::ptree node_tree;
799 read_json(in, node_tree);
801 catch (
const std::exception &e)
806 "The provided JSON file is not valid. Boost aborted with the "
807 "following assert message: \n\n" +
808 std::string(e.what())));
813 read_xml_recursively(
822 entries = std::make_unique<boost::property_tree::ptree>();
830 const std::string & default_value,
832 const std::string & documentation,
833 const bool has_to_be_set)
843 const std::pair<bool, bool> set_status =
844 std::pair<bool, bool>(has_to_be_set,
false);
852 static_cast<unsigned int>(
patterns.size() - 1));
863 "pattern_description",
876 const std::string & entry,
877 const std::function<
void(
const std::string &)> &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);
912 const std::string &alias_name,
913 const bool alias_is_deprecated)
918 ExcMessage(
"You are trying to declare an alias entry <" + alias_name +
919 "> that references an entry <" + existing_entry_name +
920 ">, but the latter does not exist."));
926 ExcMessage(
"You are trying to declare an alias entry <" + alias_name +
927 "> that references an entry <" + existing_entry_name +
928 ">, but the latter does not seem to be a "
929 "parameter declaration."));
939 ExcMessage(
"You are trying to declare an alias entry <" +
941 "> but a non-alias entry already exists in this "
942 "subsection (i.e., there is either a preexisting "
943 "further subsection, or a parameter entry, with "
944 "the same name as the alias)."));
949 "You are trying to declare an alias entry <" + alias_name +
950 "> but an alias entry already exists in this "
951 "subsection and this existing alias references a "
952 "different parameter entry. Specifically, "
953 "you are trying to reference the entry <" +
954 existing_entry_name +
955 "> whereas the existing alias references "
963 existing_entry_name);
965 "deprecation_status",
966 (alias_is_deprecated ?
"true" :
"false"));
977 boost::property_tree::ptree());
1000 const std::vector<std::string> &sub_path)
const
1004 full_path.insert(full_path.end(), sub_path.begin(), sub_path.end());
1006 boost::optional<const boost::property_tree::ptree &> subsection(
1013 return !(!subsection || is_parameter_node(subsection.get()) ||
1014 is_alias_node(subsection.get()));
1024 if (boost::optional<std::string> value =
entries->get_optional<std::string>(
1038 const std::string & entry_string)
const
1042 if (boost::optional<std::string> value =
entries->get_optional<std::string>(
1067 ExcMessage(
"Can't convert the parameter value <" +
1068 get(entry_string) +
"> for entry <" +
1069 entry_string +
"> to an integer."));
1078 const std::vector<std::string> &entry_subsection_path,
1079 const std::string & entry_string)
const
1089 "Can't convert the parameter value <" +
1090 get(entry_subsection_path, entry_string) +
"> for entry <" +
1093 "> to an integer."));
1110 ExcMessage(
"Can't convert the parameter value <" +
1111 get(entry_string) +
"> for entry <" +
1113 "> to a double precision variable."));
1122 const std::vector<std::string> &entry_subsection_path,
1123 const std::string & entry_string)
const
1128 get(entry_subsection_path, entry_string));
1134 "Can't convert the parameter value <" +
1135 get(entry_subsection_path, entry_string) +
"> for entry <" +
1138 "> to a double precision variable."));
1148 const std::string s =
get(entry_string);
1150 AssertThrow((s ==
"true") || (s ==
"false") || (s ==
"yes") || (s ==
"no"),
1151 ExcMessage(
"Can't convert the parameter value <" +
1152 get(entry_string) +
"> for entry <" + entry_string +
1153 "> to a boolean."));
1154 if (s ==
"true" || s ==
"yes")
1164 const std::vector<std::string> &entry_subsection_path,
1165 const std::string & entry_string)
const
1167 const std::string s =
get(entry_subsection_path, entry_string);
1169 AssertThrow((s ==
"true") || (s ==
"false") || (s ==
"yes") || (s ==
"no"),
1170 ExcMessage(
"Can't convert the parameter value <" +
1171 get(entry_subsection_path, entry_string) +
1175 "> to a boolean."));
1176 if (s ==
"true" || s ==
"yes")
1186 const std::string &new_value)
1200 const unsigned int pattern_index =
1206 "pattern_description")));
1210 const boost::optional<std::string> action_indices_as_string =
1212 if (action_indices_as_string)
1216 for (
const unsigned int index : action_indices)
1217 if (
actions.size() >= index + 1)
1226 map_iter->second = std::pair<bool, bool>(map_iter->second.first,
true);
1229 ExcMessage(
"Could not find parameter " + path +
1230 " in map entries_set_status."));
1241 set(entry_string, std::string(new_value));
1248 std::ostringstream s;
1249 s << std::setprecision(16);
1254 set(entry_string, s.str());
1262 std::ostringstream s;
1267 set(entry_string, s.str());
1277 set(entry_string, (new_value ?
"true" :
"false"));
1288 assert_validity_of_output_style(style);
1293 boost::property_tree::ptree current_entries = *
entries.get();
1301 std::vector<std::string>(),
1309 boost::io::ios_flags_saver restore_flags(out);
1310 boost::io::basic_ios_fill_saver<char> restore_fill_state(out);
1318 if (((style &
Short) != 0) && ((style & (
XML |
JSON)) != 0))
1321 recursively_compress_tree(current_entries);
1324 if ((style &
XML) != 0)
1335 boost::property_tree::ptree single_node_tree;
1336 single_node_tree.add_child(
"ParameterHandler", current_entries);
1338 write_xml(out, single_node_tree);
1342 if ((style &
JSON) != 0)
1344 boost::property_tree::ptree current_entries_damangled;
1345 recursively_demangle(current_entries, current_entries_damangled);
1346 write_json(out, current_entries_damangled);
1351 if (((style &
Short) != 0) && ((style &
Text) != 0))
1355 else if ((style &
Text) != 0)
1357 out <<
"# Listing of Parameters" << std::endl
1358 <<
"# ---------------------" << std::endl;
1360 else if ((style &
LaTeX) != 0)
1362 out <<
"\\subsection{Global parameters}" << std::endl;
1363 out <<
"\\label{parameters:global}" << std::endl;
1364 out << std::endl << std::endl;
1368 out <<
"Listing of Parameters:" << std::endl << std::endl;
1378 std::vector<std::string>(),
1390 const std::string & filename,
1393 std::string extension = filename.substr(filename.find_last_of(
'.') + 1);
1394 boost::algorithm::to_lower(extension);
1397 if (extension ==
"prm")
1398 output_style = style |
PRM;
1399 else if (extension ==
"xml")
1400 output_style = style |
XML;
1401 else if (extension ==
"json")
1402 output_style = style |
JSON;
1403 else if (extension ==
"tex")
1404 output_style = style |
LaTeX;
1406 std::ofstream out(filename);
1415 const boost::property_tree::ptree &tree,
1416 const std::vector<std::string> & target_subsection_path,
1418 const unsigned int indent_level,
1419 std::ostream & out)
const
1426 const boost::property_tree::ptree ¤t_section =
1427 tree.get_child(collate_path_string(
path_separator, target_subsection_path));
1429 unsigned int overall_indent_level = indent_level;
1431 const bool is_short = (style &
Short) != 0;
1433 if ((style &
Text) != 0)
1442 std::size_t longest_name = 0;
1443 std::size_t longest_value = 0;
1444 for (
const auto &p : current_section)
1445 if (is_parameter_node(p.second) ==
true)
1447 longest_name =
std::max(longest_name, demangle(p.first).size());
1448 longest_value =
std::max(longest_value,
1449 p.second.get<std::string>(
"value").size());
1453 bool first_entry =
true;
1454 for (
const auto &p : current_section)
1455 if (is_parameter_node(p.second) ==
true)
1457 const std::string value = p.second.get<std::string>(
"value");
1465 !p.second.get<std::string>(
"documentation").empty())
1467 if (first_entry ==
false)
1470 first_entry =
false;
1472 const std::vector<std::string> doc_lines =
1474 p.second.get<std::string>(
"documentation"),
1475 78 - overall_indent_level * 2 - 2);
1477 for (
const auto &doc_line : doc_lines)
1478 out << std::setw(overall_indent_level * 2) <<
""
1479 <<
"# " << doc_line <<
'\n';
1483 out << std::setw(overall_indent_level * 2) <<
""
1484 <<
"set " << demangle(p.first)
1485 << std::setw(longest_name - demangle(p.first).size() + 1) <<
" "
1491 value != p.second.get<std::string>(
"default_value"))
1493 out << std::setw(longest_value - value.size() + 1) <<
' '
1496 << p.second.get<std::string>(
"default_value");
1502 else if ((style &
LaTeX) != 0)
1504 auto escape = [](
const std::string &input) {
1510 const bool parameters_exist_here =
1511 std::any_of(current_section.begin(),
1512 current_section.end(),
1513 [](
const boost::property_tree::ptree::value_type &p) {
1514 return is_parameter_node(p.second) ||
1515 is_alias_node(p.second);
1517 if (parameters_exist_here)
1519 out <<
"\\begin{itemize}" <<
'\n';
1522 for (
const auto &p : current_section)
1523 if (is_parameter_node(p.second) ==
true)
1525 const std::string value = p.second.get<std::string>(
"value");
1528 out <<
"\\item {\\it Parameter name:} {\\tt "
1529 << escape(demangle(p.first)) <<
"}\n"
1530 <<
"\\phantomsection";
1534 std::string label =
"parameters:";
1535 for (
const auto &path : target_subsection_path)
1537 label.append(mangle(path));
1540 label.append(p.first);
1543 if (label.find(
"_20") != std::string::npos)
1547 out <<
"\\label{" << label <<
"}\n";
1551 out <<
"\\index[prmindex]{" << escape(demangle(p.first))
1553 out <<
"\\index[prmindexfull]{";
1554 for (
const auto &path : target_subsection_path)
1555 out << escape(path) <<
"!";
1556 out << escape(demangle(p.first)) <<
"}\n";
1559 out <<
"{\\it Value:} " << escape(value) <<
"\n\n"
1561 <<
"{\\it Default:} "
1562 << escape(p.second.get<std::string>(
"default_value"))
1569 !p.second.get<std::string>(
"documentation").empty())
1570 out <<
"{\\it Description:} "
1571 << p.second.get<std::string>(
"documentation") <<
"\n\n"
1577 const unsigned int pattern_index =
1578 p.second.get<
unsigned int>(
"pattern");
1579 const std::string desc_str =
1580 patterns[pattern_index]->description(
1582 out <<
"{\\it Possible values:} " << desc_str <<
'\n';
1585 else if (is_alias_node(p.second) ==
true)
1587 const std::string alias = p.second.get<std::string>(
"alias");
1590 out <<
"\\item {\\it Parameter name:} {\\tt "
1591 << escape(demangle(p.first)) <<
"}\n"
1592 <<
"\\phantomsection";
1596 std::string label =
"parameters:";
1597 for (
const auto &path : target_subsection_path)
1599 label.append(mangle(path));
1602 label.append(p.first);
1605 if (label.find(
"_20") != std::string::npos)
1609 out <<
"\\label{" << label <<
"}\n";
1613 out <<
"\\index[prmindex]{" << escape(demangle(p.first))
1615 out <<
"\\index[prmindexfull]{";
1616 for (
const auto &path : target_subsection_path)
1617 out << escape(path) <<
"!";
1618 out << escape(demangle(p.first)) <<
"}\n";
1622 <<
"This parameter is an alias for the parameter ``\\texttt{"
1623 << escape(alias) <<
"}''."
1624 << (p.second.get<std::string>(
"deprecation_status") ==
1626 " Its use is deprecated." :
1631 out <<
"\\end{itemize}" <<
'\n';
1638 std::size_t longest_name = 0;
1639 for (
const auto &p : current_section)
1640 if (is_parameter_node(p.second) ==
true)
1641 longest_name =
std::max(longest_name, demangle(p.first).size());
1644 for (
const auto &p : current_section)
1645 if (is_parameter_node(p.second) ==
true)
1648 out << std::setw(overall_indent_level * 2) <<
""
1649 <<
"set " << demangle(p.first)
1650 << std::setw(longest_name - demangle(p.first).size() + 1) <<
" "
1654 const unsigned int pattern_index =
1655 p.second.get<
unsigned int>(
"pattern");
1656 const std::string full_desc_str =
1658 const std::vector<std::string> description_str =
1660 full_desc_str, 78 - overall_indent_level * 2 - 2,
'|');
1661 if (description_str.size() > 1)
1664 for (
const auto &description : description_str)
1665 out << std::setw(overall_indent_level * 2 + 6) <<
""
1666 << description <<
'\n';
1668 else if (description_str.empty() ==
false)
1669 out <<
" " << description_str[0] <<
'\n';
1675 p.second.get<std::string>(
"documentation").size() != 0)
1676 out << std::setw(overall_indent_level * 2 + longest_name + 10)
1678 <<
"(" << p.second.get<std::string>(
"documentation") <<
")"
1691 unsigned int n_parameters = 0;
1692 unsigned int n_sections = 0;
1693 for (
const auto &p : current_section)
1694 if (is_parameter_node(p.second) ==
true)
1696 else if (is_alias_node(p.second) ==
false)
1700 (!(((style &
Text) != 0) && is_short)) && (n_parameters != 0) &&
1706 for (
const auto &p : current_section)
1707 if ((is_parameter_node(p.second) ==
false) &&
1708 (is_alias_node(p.second) ==
false))
1713 out << std::setw(overall_indent_level * 2) <<
""
1714 <<
"subsection " << demangle(p.first) <<
'\n';
1716 else if ((style &
LaTeX) != 0)
1718 auto escape = [](
const std::string &input) {
1723 out <<
'\n' <<
"\\subsection{Parameters in section \\tt ";
1727 for (
const auto &path : target_subsection_path)
1728 out << escape(path) <<
"/";
1729 out << escape(demangle(p.first));
1732 out <<
"\\label{parameters:";
1733 for (
const auto &path : target_subsection_path)
1734 out << mangle(path) <<
"/";
1735 out << p.first <<
"}";
1746 const std::string subsection = demangle(p.first);
1747 std::vector<std::string> directory_path = target_subsection_path;
1748 directory_path.emplace_back(subsection);
1751 tree, directory_path, style, overall_indent_level + 1, out);
1753 if (is_short && ((style &
Text) != 0))
1756 out << std::setw(overall_indent_level * 2) <<
""
1759 else if ((style &
Text) != 0)
1763 out << std::setw(overall_indent_level * 2) <<
""
1769 if (overall_indent_level == 0)
1776 else if ((style &
LaTeX) != 0)
1792 out.
push(
"parameters");
1807 boost::property_tree::ptree sorted_entries;
1808 boost::property_tree::ptree *current_entries =
entries.get();
1814 current_entries = &sorted_entries;
1823 const boost::property_tree::ptree ¤t_section =
1827 for (
const auto &p : current_section)
1828 if (is_parameter_node(p.second) ==
true)
1829 out << demangle(p.first) <<
": " << p.second.get<std::string>(
"value")
1833 for (
const auto &p : current_section)
1834 if (is_parameter_node(p.second) ==
false)
1836 out.
push(demangle(p.first));
1848 const std::string &input_filename,
1849 const unsigned int current_line_n,
1850 const bool skip_undefined)
1853 const std::string original_line = line;
1856 if (line.find(
'#') != std::string::npos)
1857 line.erase(line.find(
'#'), std::string::npos);
1860 while (line.find(
'\t') != std::string::npos)
1861 line.replace(line.find(
'\t'), 1,
" ");
1867 if (line.size() == 0)
1876 line.erase(0, std::string(
"subsection").size() + 1);
1895 while ((line.size() > 0) && ((std::isspace(line[0])) != 0))
1902 "Invalid content after 'end' or 'END' statement."));
1906 "There is no subsection to leave here."));
1916 std::string::size_type pos = line.find(
'=');
1918 pos != std::string::npos,
1921 "Invalid format of 'set' or 'SET' statement."));
1925 std::string entry_value =
1934 "deprecation_status") ==
"true")
1936 std::cerr <<
"Warning in line <" << current_line_n
1937 <<
"> of file <" << input_filename
1938 <<
">: You are using the deprecated spelling <"
1939 << entry_name <<
"> of the parameter <"
1942 <<
">." << std::endl;
1956 if (entry_value.find(
'{') == std::string::npos)
1959 const unsigned int pattern_index =
1967 patterns[pattern_index]->description()));
1971 const boost::optional<std::string> action_indices_as_string =
1974 if (action_indices_as_string)
1976 std::vector<int> action_indices =
1978 action_indices_as_string.get()));
1979 for (
const unsigned int index : action_indices)
1980 if (
actions.size() >= index + 1)
1991 std::pair<bool, bool>(map_iter->second.first,
true);
1994 ExcMessage(
"Could not find parameter " + path +
1995 " in map entries_set_status."));
2003 (
"No entry with name <" + entry_name +
2004 "> was declared in the current subsection.")));
2013 while ((line.size() > 0) && (line[0] ==
' '))
2020 "The current line is an 'include' or "
2021 "'INCLUDE' statement, but it does not "
2022 "name a file for inclusion."));
2024 std::ifstream input(line.c_str());
2041 "could not be parsed: please check to "
2042 "make sure that the file is not missing a "
2043 "'set', 'include', 'subsection', or 'end' "
2065 for (
unsigned int j = 0; j <
patterns.size(); ++j)
2076 std::ostringstream o1, o2;
2078 write_json(o2, *prm2.
entries);
2079 return (o1.str() == o2.str());
2084std::set<std::string>
2087 std::set<std::string> entries_wrongly_not_set;
2090 if (it.second.first ==
true && it.second.second ==
false)
2091 entries_wrongly_not_set.insert(it.first);
2093 return entries_wrongly_not_set;
2101 const std::set<std::string> entries_wrongly_not_set =
2104 if (entries_wrongly_not_set.size() > 0)
2106 std::string list_of_missing_parameters =
"\n\n";
2107 for (
const auto &it : entries_wrongly_not_set)
2108 list_of_missing_parameters +=
" " + it +
"\n";
2109 list_of_missing_parameters +=
"\n";
2112 entries_wrongly_not_set.size() == 0,
2114 "Not all entries of the parameter handler that were declared with "
2115 "`has_to_be_set = true` have been set. The following parameters " +
2116 list_of_missing_parameters +
2117 " have not been set. "
2118 "A possible reason might be that you did not add these parameter to "
2119 "the input file or that their spelling is not correct."));
2133 const std::string &filename,
2134 const std::string &last_line,
2135 const bool skip_undefined)
2151 for (
unsigned int run_no = 0; run_no <
n_branches; ++run_no)
2170 multiple_choice.split_different_values();
2176 n_branches *= multiple_choice.different_values.size();
2182 if (multiple_choice.different_values.size() !=
n_branches)
2183 std::cerr <<
" The entry value" << std::endl
2184 <<
" " << multiple_choice.entry_value << std::endl
2185 <<
" for the entry named" << std::endl
2186 <<
" " << multiple_choice.entry_name << std::endl
2187 <<
" does not have the right number of entries for the "
2190 <<
" variant runs that will be performed." << std::endl;
2197 for (
unsigned int i = 0; i <
n_branches; ++i)
2206 const boost::property_tree::ptree ¤t_section =
2212 for (
const auto &p : current_section)
2213 if (is_parameter_node(p.second) ==
true)
2215 const std::string value = p.second.get<std::string>(
"value");
2216 if (value.find(
'{') != std::string::npos)
2223 for (
const auto &p : current_section)
2224 if (is_parameter_node(p.second) ==
false)
2237 unsigned int possibilities = 1;
2239 std::vector<Entry>::iterator choice;
2243 const unsigned int selection =
2244 (run_no / possibilities) % choice->different_values.size();
2245 std::string entry_value;
2247 entry_value = choice->different_values[selection];
2250 if (run_no >= choice->different_values.size())
2253 <<
"The given array for entry <" << choice->entry_name
2254 <<
"> does not contain enough elements! Taking empty string instead."
2259 entry_value = choice->different_values[run_no];
2271 set(choice->entry_name, entry_value);
2276 possibilities *= choice->different_values.size();
2287 mem += multiple_choice.memory_consumption();
2295 const std::string & Name,
2296 const std::string & Value)
2297 : subsection_path(ssp)
2299 , entry_value(Value)
2300 , type(
Entry::array)
2312 std::string prefix(entry_value, 0, entry_value.find(
'{'));
2313 std::string multiple(entry_value,
2314 entry_value.find(
'{') + 1,
2315 entry_value.rfind(
'}') - entry_value.find(
'{') - 1);
2316 std::string postfix(entry_value,
2317 entry_value.rfind(
'}') + 1,
2321 if (multiple[0] ==
'{')
2322 multiple.erase(0, 1);
2323 if (multiple.back() ==
'}')
2324 multiple.erase(multiple.size() - 1, 1);
2327 while (std::isspace(multiple[0]) != 0)
2328 multiple.erase(0, 1);
2329 while (std::isspace(multiple.back()) != 0)
2330 multiple.erase(multiple.size() - 1, 1);
2333 while (multiple.find(
" |") != std::string::npos)
2334 multiple.replace(multiple.find(
" |"), 2,
"|");
2335 while (multiple.find(
"| ") != std::string::npos)
2336 multiple.replace(multiple.find(
"| "), 2,
"|");
2338 while (multiple.find(
'|') != std::string::npos)
2340 different_values.push_back(
2341 prefix + std::string(multiple, 0, multiple.find(
'|')) + postfix);
2342 multiple.erase(0, multiple.find(
'|') + 1);
2346 different_values.push_back(prefix + multiple + postfix);
2349 if ((entry_value.find(
"{{") != std::string::npos) &&
2350 (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)
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 > 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 > &)