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 & current_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"))
722 recursively_compress_tree(p.second);
732 const bool skip_undefined)
739 boost::property_tree::ptree single_node_tree;
742 read_xml(in, single_node_tree);
746 AssertThrow(single_node_tree.get_optional<std::string>(
"ParameterHandler"),
748 "called \"ParameterHandler\"."));
750 const std::size_t n_top_level_elements =
751 std::distance(single_node_tree.begin(), single_node_tree.end());
752 if (n_top_level_elements != 1)
754 std::ostringstream top_level_message;
755 top_level_message <<
"The ParameterHandler input parser found "
756 << n_top_level_elements
757 <<
" top level elements while reading\n "
758 <<
" an XML format input file, but there should be"
759 <<
" exactly one top level element.\n"
760 <<
" The top level elements are:\n";
762 unsigned int entry_n = 0;
763 for (boost::property_tree::ptree::iterator it = single_node_tree.begin();
764 it != single_node_tree.end();
769 << (entry_n != n_top_level_elements - 1 ?
"\n" :
"");
778 const boost::property_tree::ptree &my_entries =
779 single_node_tree.get_child(
"ParameterHandler");
781 read_xml_recursively(
788 const bool skip_undefined)
792 boost::property_tree::ptree node_tree;
797 read_json(in, node_tree);
799 catch (
const std::exception &
e)
804 "The provided JSON file is not valid. Boost aborted with the "
805 "following assert message: \n\n" +
806 std::string(
e.what())));
811 read_xml_recursively(
820 entries = std::make_unique<boost::property_tree::ptree>();
828 const std::string & default_value,
830 const std::string & documentation,
831 const bool has_to_be_set)
841 const std::pair<bool, bool> set_status =
842 std::pair<bool, bool>(has_to_be_set,
false);
850 static_cast<unsigned int>(
patterns.size() - 1));
861 "pattern_description",
874 const std::string & entry,
875 const std::function<
void(
const std::string &)> &action,
876 const bool execute_action)
881 boost::optional<std::string> current_actions =
890 const std::string all_actions =
891 current_actions.get() +
"," +
902 const std::string default_value =
entries->get<std::string>(
904 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."));
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());
2084 std::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)
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< T >::value, 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)