17 #include <deal.II/base/parameter_handler.h> 18 #include <deal.II/base/logstream.h> 19 #include <deal.II/base/path_search.h> 20 #include <deal.II/base/memory_consumption.h> 21 #include <deal.II/base/utilities.h> 23 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
24 #include <boost/property_tree/ptree.hpp> 25 #include <boost/property_tree/xml_parser.hpp> 26 #include <boost/property_tree/json_parser.hpp> 27 DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
40 DEAL_II_NAMESPACE_OPEN
57 bool has_only_whitespace (std::istream &in)
68 if ((c !=
' ') && (c !=
'\t'))
131 if (dynamic_cast<const Integer *>(
this) != 0)
133 else if (dynamic_cast<const Double *>(
this) != 0)
135 else if (dynamic_cast<const Bool *>(
this) != 0)
137 else if (dynamic_cast<const Anything *>(
this) != 0)
140 return sizeof(*this) + 32;
151 const int upper_bound)
153 lower_bound (lower_bound),
154 upper_bound (upper_bound)
161 std::istringstream str(test_string);
167 if (!has_only_whitespace (str))
268 is.ignore(strlen(
"..."));
290 const double upper_bound)
292 lower_bound (lower_bound),
293 upper_bound (upper_bound)
300 std::istringstream str(test_string);
306 if (!has_only_whitespace (str))
359 description <<
"A floating point number v such that ";
373 return "A floating point number";
381 description <<
"A floating point number @f$v@f$ such that @f$";
396 return "A floating point number";
418 if (
description.compare(0, description_init_str.size(), description_init_str) != 0)
423 std::string temp =
description.substr(description_init_str.size());
425 return new Double(1.0, -1.0);
427 if (temp.find(
"...") != std::string::npos)
428 temp.replace(temp.find(
"..."), 3,
" ");
433 std::istringstream is(temp);
434 if (0 == temp.compare(0, std::strlen(
" -MAX_DOUBLE"),
" -MAX_DOUBLE"))
435 is.ignore(std::strlen(
" -MAX_DOUBLE"));
459 while (
sequence.find(
" |") != std::string::npos)
461 while (
sequence.find(
"| ") != std::string::npos)
472 while ((tmp.length() != 0) && (std::isspace (tmp[0])))
476 while (tmp.find(
'|') != std::string::npos)
478 if (test_string == std::string(tmp, 0, tmp.find(
'|')))
481 tmp.erase (0, tmp.find(
'|')+1);
485 while ((tmp.length() != 0) && (std::isspace (*(tmp.end()-1))))
486 tmp.erase (tmp.end()-1);
489 if (test_string == tmp)
567 = std::numeric_limits<unsigned int>::max();
573 const unsigned int min_elements,
574 const unsigned int max_elements,
575 const std::string &separator)
578 min_elements (min_elements),
579 max_elements (max_elements),
580 separator (separator)
585 ExcMessage (
"The separator must have a non-zero length."));
600 std::string tmp = test_string_list;
601 std::vector<std::string> split_list;
604 while (tmp.length() != 0)
609 if (name.find(
separator) != std::string::npos)
611 name.erase (name.find(
separator), std::string::npos);
617 while ((name.length() != 0) &&
618 (std::isspace (name[0])))
621 while (std::isspace (name[name.length()-1]))
622 name.erase (name.length()-1, 1);
624 split_list.push_back (name);
632 for (std::vector<std::string>::const_iterator
633 test_string = split_list.begin();
634 test_string != split_list.end(); ++test_string)
697 return (
sizeof(*
this) +
714 std::getline(is, str,
'>');
716 std_cxx11::shared_ptr<PatternBase> base_pattern (
pattern_factory(str));
718 is.ignore(strlen(
" of length "));
720 return new List(*base_pattern);
722 is.ignore(strlen(
"..."));
726 is.ignore(strlen(
" separated by <"));
742 = std::numeric_limits<unsigned int>::max();
749 const unsigned int min_elements,
750 const unsigned int max_elements,
751 const std::string &separator)
753 key_pattern (p_key.clone()),
754 value_pattern (p_value.clone()),
755 min_elements (min_elements),
756 max_elements (max_elements),
757 separator (separator)
762 ExcMessage (
"The separator must have a non-zero length."));
764 ExcMessage (
"The separator can not be a colon ':' since that " 765 "is the separator between the two elements of <key:value> pairs"));
775 delete value_pattern;
783 std::string tmp = test_string_list;
784 std::vector<std::string> split_list;
787 while (tmp.length() != 0)
789 std::string map_entry;
792 if (map_entry.find(
separator) != std::string::npos)
794 map_entry.erase (map_entry.find(
separator), std::string::npos);
800 while ((map_entry.length() != 0) &&
801 (std::isspace (map_entry[0])))
802 map_entry.erase (0,1);
804 while (std::isspace (map_entry[map_entry.length()-1]))
805 map_entry.erase (map_entry.length()-1, 1);
807 split_list.push_back (map_entry);
815 for (std::vector<std::string>::const_iterator
816 test_string = split_list.begin();
817 test_string != split_list.end(); ++test_string)
820 if (test_string->find(
":") == std::string::npos)
825 std::string key = *test_string;
826 key.erase (key.find(
":"), std::string::npos);
827 while ((key.length() > 0) && (std::isspace (key[key.length()-1])))
828 key.erase (key.length()-1, 1);
830 std::string value = *test_string;
831 value.erase (0, value.find(
":")+1);
832 while ((value.length() > 0) && (std::isspace (value[0])))
838 if (value_pattern->
match (value) ==
false)
880 <<
" and each value is [" 908 return (
sizeof(*
this) +
926 std::getline(is, str,
'>');
929 std::string key = str;
930 key.erase (key.find(
":"), std::string::npos);
932 std::string value = str;
933 value.erase (0, value.find(
":")+1);
936 std_cxx11::shared_ptr<PatternBase> value_pattern (
pattern_factory(value));
938 is.ignore(strlen(
" of length "));
942 is.ignore(strlen(
"..."));
946 is.ignore(strlen(
" separated by <"));
971 while (
sequence.find(
" |") != std::string::npos)
973 while (
sequence.find(
"| ") != std::string::npos)
981 std::string tmp = test_string_list;
982 std::vector<std::string> split_names;
985 while (tmp.length() != 0)
990 if (name.find(
",") != std::string::npos)
992 name.erase (name.find(
","), std::string::npos);
993 tmp.erase (0, tmp.find(
",")+1);
998 while ((name.length() != 0) &&
999 (std::isspace (name[0])))
1001 while (std::isspace (name[name.length()-1]))
1002 name.erase (name.length()-1, 1);
1004 split_names.push_back (name);
1009 for (std::vector<std::string>::const_iterator test_string = split_names.begin();
1010 test_string != split_names.end(); ++test_string)
1012 bool string_found =
false;
1015 while (tmp.find(
'|') != std::string::npos)
1017 if (*test_string == std::string(tmp, 0, tmp.find(
'|')))
1023 string_found =
true;
1027 tmp.erase (0, tmp.find(
'|')+1);
1031 if (*test_string == tmp)
1032 string_found =
true;
1063 description <<
"A comma-separated list of any of " 1137 return "A boolean value (true or false)";
1198 return "Any string";
1265 return "an input filename";
1267 return "an output filename";
1342 return "A directory name";
1376 entries (new boost::property_tree::ptree())
1393 u.reserve (s.size());
1396 const bool mangle_whole_string = (s ==
"value");
1401 for (
unsigned int i=0; i<s.size(); ++i)
1403 static const std::string allowed_characters
1404 (
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
1406 if ((! mangle_whole_string)
1408 (allowed_characters.find (s[i]) != std::string::npos))
1413 static const char hex[16]
1414 = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'};
1415 u.push_back (hex[static_cast<unsigned char>(s[i])/16]);
1416 u.push_back (hex[static_cast<unsigned char>(s[i])%16]);
1429 u.reserve (s.size());
1431 for (
unsigned int i=0; i<s.size(); ++i)
1437 ExcMessage (
"Trying to demangle an invalid string."));
1439 unsigned char c = 0;
1547 u.push_back (static_cast<char>(c));
1565 is_parameter_node (
const boost::property_tree::ptree &p)
1567 return static_cast<bool>(p.get_optional<std::string>(
"value"));
1576 is_alias_node (
const boost::property_tree::ptree &p)
1578 return static_cast<bool>(p.get_optional<std::string>(
"alias"));
1606 if (path.empty() ==
false)
1617 const std::string &filename,
1618 const std::string &last_line)
1625 catch (
const ExcIO &)
1634 std::cerr << exc.
what() << std::endl;
1642 const std::string &filename,
1643 const std::string &last_line)
1650 std::string input_line;
1651 std::string fully_concatenated_line;
1652 bool is_concatenated =
false;
1656 unsigned int current_line_n = 0;
1657 unsigned int current_logical_line_n = 0;
1659 while (std::getline (input, input_line))
1662 if (!is_concatenated)
1663 current_logical_line_n = current_line_n;
1670 if (last_line.length() != 0 &&
1671 input_line == last_line)
1676 if (input_line.length() != 0 &&
1677 input_line.find_last_of(
'\\') == input_line.length() - 1)
1679 input_line.erase (input_line.length() - 1);
1680 is_concatenated =
true;
1682 fully_concatenated_line += input_line;
1686 else if (is_concatenated)
1688 fully_concatenated_line += input_line;
1689 is_concatenated =
false;
1695 fully_concatenated_line = input_line;
1698 if (!is_concatenated)
1700 scan_line (fully_concatenated_line, filename, current_logical_line_n);
1701 fully_concatenated_line.clear();
1707 if (is_concatenated)
1709 scan_line (fully_concatenated_line, filename, current_line_n);
1714 std::stringstream paths_message;
1715 if (saved_path.size() > 0)
1717 paths_message <<
"Path before loading input:\n";
1720 paths_message << std::setw(i*2 + 4)
1726 paths_message <<
"Current path:\n";
1729 paths_message << std::setw(i*2 + 4)
1745 const bool optional,
1746 const bool write_compact,
1747 const std::string &last_line)
1753 std::string openname = search.
find(filename);
1754 std::ifstream file_stream (openname.c_str());
1757 return read_input (file_stream, filename, last_line);
1761 std::cerr <<
"ParameterHandler::read_input: could not open file <" 1762 << filename <<
"> for reading." << std::endl;
1765 std::cerr <<
"Trying to make file <" 1766 << filename <<
"> with default values for you." << std::endl;
1767 std::ofstream output (filename.c_str());
1778 const std::string &last_line)
1782 std::string openname = search.
find(filename);
1783 std::ifstream file_stream (openname.c_str());
1791 const std::string &last_line)
1798 catch (
const ExcIO &)
1807 std::cerr << exc.
what() << std::endl;
1816 const std::string &last_line)
1818 std::istringstream input_stream (s);
1819 parse_input (input_stream,
"input string", last_line);
1832 read_xml_recursively (
const boost::property_tree::ptree &source,
1833 const std::string ¤t_path,
1834 const char path_separator,
1835 const std::vector<std_cxx11::shared_ptr<const Patterns::PatternBase> > &
1837 boost::property_tree::ptree &destination)
1839 for (boost::property_tree::ptree::const_iterator p = source.begin();
1840 p != source.end(); ++p)
1843 if (p->second.get_optional<std::string>(
"value"))
1847 const std::string full_path
1848 = (current_path ==
"" 1852 current_path + path_separator + p->first);
1854 const std::string new_value
1855 = p->second.get<std::string>(
"value");
1856 AssertThrow (destination.get_optional<std::string> (full_path)
1858 destination.get_optional<std::string>
1859 (full_path + path_separator +
"value"),
1864 const unsigned int pattern_index
1865 = destination.get<
unsigned int> (full_path +
1868 AssertThrow (patterns[pattern_index]->match(new_value),
1874 patterns[pattern_index]->description()));
1877 destination.put (full_path + path_separator +
"value",
1885 else if (p->second.get_optional<std::string>(
"alias"))
1894 read_xml_recursively (p->second,
1895 (current_path ==
"" ?
1897 current_path + path_separator + p->first),
1915 catch (
const ExcIO &)
1921 std::cerr << exc.
what() << std::endl;
1935 boost::property_tree::ptree single_node_tree;
1938 read_xml (in, single_node_tree);
1942 AssertThrow (single_node_tree.get_optional<std::string>(
"ParameterHandler"),
1944 "called \"ParameterHandler\"."));
1946 const std::size_t n_top_level_elements = std::distance (single_node_tree.begin(),
1947 single_node_tree.end());
1948 if (n_top_level_elements != 1)
1950 std::ostringstream top_level_message;
1951 top_level_message <<
"The ParameterHandler input parser found " 1952 << n_top_level_elements
1953 <<
" top level elements while reading\n " 1954 <<
" an XML format input file, but there should be" 1955 <<
" exactly one top level element.\n" 1956 <<
" The top level elements are:\n";
1958 unsigned int entry_n = 0;
1959 for (boost::property_tree::ptree::iterator it = single_node_tree.begin();
1960 it != single_node_tree.end(); ++it, ++entry_n)
1962 top_level_message <<
" " 1964 << (entry_n != n_top_level_elements - 1 ?
"\n" :
"");
1973 const boost::property_tree::ptree
1974 &my_entries = single_node_tree.get_child(
"ParameterHandler");
1983 entries.reset (
new boost::property_tree::ptree());
1990 const std::string &default_value,
1992 const std::string &documentation)
2003 patterns.push_back (std_cxx11::shared_ptr<const Patterns::PatternBase>
2006 static_cast<unsigned int>(
patterns.size()-1));
2017 "pattern_description",
2029 const std::string &alias_name,
2030 const bool alias_is_deprecated)
2034 ExcMessage (
"You are trying to declare an alias entry <" 2036 "> that references an entry <" 2037 + existing_entry_name +
2038 ">, but the latter does not exist."));
2042 ExcMessage (
"You are trying to declare an alias entry <" 2044 "> that references an entry <" 2045 + existing_entry_name +
2046 ">, but the latter does not seem to be a " 2047 "parameter declaration."));
2056 ExcMessage (
"You are trying to declare an alias entry <" 2058 "> but a non-alias entry already exists in this " 2059 "subsection (i.e., there is either a preexisting " 2060 "further subsection, or a parameter entry, with " 2061 "the same name as the alias)."));
2064 existing_entry_name,
2065 ExcMessage (
"You are trying to declare an alias entry <" 2067 "> but an alias entry already exists in this " 2068 "subsection and this existing alias references a " 2069 "different parameter entry. Specifically, " 2070 "you are trying to reference the entry <" 2071 + existing_entry_name +
2072 "> whereas the existing alias references " 2079 existing_entry_name);
2081 (alias_is_deprecated ?
"true" :
"false"));
2091 boost::property_tree::ptree());
2116 if (boost::optional<std::string> value
2137 ExcMessage(
"Can't convert the parameter value <" 2138 +
get(entry_string) +
2141 " to an integer."));
2157 ExcMessage(
"Can't convert the parameter value <" 2158 +
get(entry_string) +
2161 " to a double precision variable."));
2170 const std::string s =
get(entry_string);
2173 (s==
"yes") || (s==
"no"),
2174 ExcMessage(
"Can't convert the parameter value <" 2175 +
get(entry_string) +
2179 if (s==
"true" || s==
"yes")
2189 const std::string &new_value)
2199 const unsigned int pattern_index
2206 "pattern_description")));
2218 const char *new_value)
2221 set (entry_string, std::string(new_value));
2227 const double &new_value)
2229 std::ostringstream s;
2230 s << std::setprecision(16);
2235 set (entry_string, s.str());
2242 const long int &new_value)
2244 std::ostringstream s;
2249 set (entry_string, s.str());
2256 const bool &new_value)
2261 (new_value ?
"true" :
"false"));
2294 boost::property_tree::ptree single_node_tree;
2295 single_node_tree.add_child(
"ParameterHandler",
2298 write_xml (out, single_node_tree);
2313 out <<
"# Listing of Parameters" << std::endl
2314 <<
"# ---------------------" << std::endl;
2317 out <<
"\\subsection{Global parameters}" << std::endl;
2318 out <<
"\\label{parameters:global}" << std::endl;
2319 out << std::endl << std::endl;
2322 out <<
"Listing of Parameters:" << std::endl << std::endl;
2358 const unsigned int indent_level,
2359 const bool include_top_level_elements)
2363 const boost::property_tree::ptree ¤t_section
2366 unsigned int overall_indent_level = indent_level;
2372 if (include_top_level_elements)
2393 boost::property_tree::ptree single_node_tree;
2401 single_node_tree.add_child(
"ParameterHandler",
2406 std::string path (
"ParameterHandler");
2408 single_node_tree.add_child(path,
2409 boost::property_tree::ptree());
2412 single_node_tree.add_child (path, current_section);
2415 write_xml (out, single_node_tree);
2429 out << std::setw(overall_indent_level*2) <<
"" 2431 overall_indent_level += 1;
2444 std::size_t longest_name = 0;
2445 for (boost::property_tree::ptree::const_iterator
2446 p = current_section.begin();
2447 p != current_section.end(); ++p)
2448 if (is_parameter_node (p->second) ==
true)
2449 longest_name = std::max (longest_name,
2457 std::size_t longest_value = 0;
2458 for (boost::property_tree::ptree::const_iterator
2459 p = current_section.begin();
2460 p != current_section.end(); ++p)
2461 if (is_parameter_node (p->second) ==
true)
2462 longest_value = std::max (longest_value,
2463 p->second.get<std::string>(
"value").length());
2470 bool first_entry =
true;
2471 for (boost::property_tree::ptree::const_assoc_iterator
2472 p = current_section.ordered_begin();
2473 p != current_section.not_found(); ++p)
2474 if (is_parameter_node (p->second) ==
true)
2476 const std::string value = p->second.get<std::string>(
"value");
2488 if ((!(style & 128)) &&
2489 !p->second.get<std::string>(
"documentation").empty())
2491 if (first_entry ==
false)
2494 first_entry =
false;
2496 const std::vector<std::string> doc_lines
2499 78 - overall_indent_level*2 - 2);
2501 for (
unsigned int i=0; i<doc_lines.size(); ++i)
2502 out << std::setw(overall_indent_level*2) <<
"" 2512 out << std::setw(overall_indent_level*2) <<
"" 2515 << std::setw(longest_name-
demangle(p->first).length()+1) <<
" " 2522 if ((!(style & 64)) && value != p->second.get<std::string>(
"default_value"))
2524 out << std::setw(longest_value-value.length()+1) <<
' ' 2526 out <<
"default: " << p->second.get<std::string>(
"default_value");
2540 bool parameters_exist_here =
false;
2541 for (boost::property_tree::ptree::const_assoc_iterator
2542 p = current_section.ordered_begin();
2543 p != current_section.not_found(); ++p)
2544 if ((is_parameter_node (p->second) ==
true)
2546 (is_alias_node (p->second) ==
true))
2548 parameters_exist_here =
true;
2552 if (parameters_exist_here)
2554 out <<
"\\begin{itemize}" 2561 for (boost::property_tree::ptree::const_assoc_iterator
2562 p = current_section.ordered_begin();
2563 p != current_section.not_found(); ++p)
2564 if (is_parameter_node (p->second) ==
true)
2566 const std::string value = p->second.get<std::string>(
"value");
2569 out <<
"\\item {\\it Parameter name:} {\\tt " <<
demangle(p->first) <<
"}\n" 2570 <<
"\\phantomsection\\label{parameters:";
2577 out <<
"\\index[prmindex]{" 2580 out <<
"\\index[prmindexfull]{";
2587 out <<
"{\\it Value:} " << value <<
"\n\n" 2589 <<
"{\\it Default:} " 2590 << p->second.get<std::string>(
"default_value") <<
"\n\n" 2596 if (!p->second.get<std::string>(
"documentation").empty())
2597 out <<
"{\\it Description:} " 2598 << p->second.get<std::string>(
"documentation") <<
"\n\n" 2602 const unsigned int pattern_index = p->second.get<
unsigned int> (
"pattern");
2604 out <<
"{\\it Possible values:} " 2608 else if (is_alias_node (p->second) ==
true)
2610 const std::string alias = p->second.get<std::string>(
"alias");
2613 out <<
"\\item {\\it Parameter name:} {\\tt " <<
demangle(p->first) <<
"}\n" 2614 <<
"\\phantomsection\\label{parameters:";
2621 out <<
"\\index[prmindex]{" 2624 out <<
"\\index[prmindexfull]{";
2631 out <<
"This parameter is an alias for the parameter ``\\texttt{" 2633 << (p->second.get<std::string>(
"deprecation_status") ==
"true" 2635 " Its use is deprecated." 2641 out <<
"\\end{itemize}" << std::endl;
2653 out << std::setw(overall_indent_level*2) <<
"" 2655 overall_indent_level += 1;
2661 std::size_t longest_name = 0;
2662 for (boost::property_tree::ptree::const_iterator
2663 p = current_section.begin();
2664 p != current_section.end(); ++p)
2665 if (is_parameter_node (p->second) ==
true)
2666 longest_name = std::max (longest_name,
2673 for (boost::property_tree::ptree::const_assoc_iterator
2674 p = current_section.ordered_begin();
2675 p != current_section.not_found(); ++p)
2676 if (is_parameter_node (p->second) ==
true)
2679 out << std::setw(overall_indent_level*2) <<
"" 2682 << std::setw(longest_name-
demangle(p->first).length()+1) <<
" " 2686 const unsigned int pattern_index = p->second.get<
unsigned int> (
"pattern");
2688 const std::vector<std::string> description_str
2690 78 - overall_indent_level*2 - 2,
'|');
2691 if (description_str.size() > 1)
2694 for (
unsigned int i=0; i<description_str.size(); ++i)
2695 out << std::setw(overall_indent_level*2+6) <<
"" 2696 << description_str[i] << std::endl;
2698 else if (description_str.empty() ==
false)
2699 out <<
" " << description_str[0] << std::endl;
2706 if (p->second.get<std::string>(
"documentation").length() != 0)
2707 out << std::setw(overall_indent_level*2 + longest_name + 10) <<
"" 2708 <<
"(" << p->second.get<std::string>(
"documentation") <<
")" << std::endl;
2725 unsigned int n_parameters = 0;
2726 unsigned int n_sections = 0;
2727 for (boost::property_tree::ptree::const_iterator
2728 p = current_section.begin();
2729 p != current_section.end(); ++p)
2730 if (is_parameter_node (p->second) ==
true)
2732 else if (is_alias_node (p->second) ==
false)
2742 out << std::endl << std::endl;
2746 for (boost::property_tree::ptree::const_assoc_iterator
2747 p = current_section.ordered_begin();
2748 p != current_section.not_found(); ++p)
2749 if ((is_parameter_node (p->second) ==
false)
2751 (is_alias_node (p->second) ==
false))
2759 out << std::setw(overall_indent_level*2) <<
"" 2760 <<
"subsection " <<
demangle(p->first) << std::endl;
2765 <<
"\\subsection{Parameters in section \\tt ";
2775 out <<
"}" << std::endl;
2776 out <<
"\\label{parameters:";
2779 out << p->first <<
"}";
2802 out << std::setw(overall_indent_level*2) <<
"" 2803 <<
"end" << std::endl
2809 if (overall_indent_level == 0)
2818 out << std::setw(overall_indent_level*2) <<
"" 2819 <<
"end" << std::endl;
2842 overall_indent_level -= 1;
2843 out << std::setw(overall_indent_level*2) <<
"" 2844 <<
"end" << std::endl;
2861 out.
push(
"parameters");
2874 const boost::property_tree::ptree ¤t_section
2881 for (boost::property_tree::ptree::const_assoc_iterator
2882 p = current_section.ordered_begin();
2883 p != current_section.not_found(); ++p)
2884 if (is_parameter_node (p->second) ==
true)
2886 << p->second.get<std::string>(
"value") << std::endl;
2891 for (boost::property_tree::ptree::const_assoc_iterator
2892 p = current_section.ordered_begin();
2893 p != current_section.not_found(); ++p)
2894 if (is_parameter_node (p->second) ==
false)
2908 const std::string &input_filename,
2909 const unsigned int current_line_n)
2912 const std::string original_line = line;
2915 if (line.find(
'#') != std::string::npos)
2916 line.erase (line.find(
"#"), std::string::npos);
2919 while (line.find(
'\t') != std::string::npos)
2920 line.replace (line.find(
'\t'), 1,
" ");
2926 if (line.length() == 0)
2935 line.erase (0, std::string(
"subsection").length()+1);
2953 while ((line.size() > 0) && (std::isspace(line[0])))
2959 "Invalid content after 'end' or 'END' statement."));
2963 "There is no subsection to leave here."));
2973 std::string::size_type pos = line.find(
"=");
2977 "Invalid format of 'set' or 'SET' statement."));
2981 std::string entry_value =
Utilities::trim(std::string(line, pos+1, std::string::npos));
2990 std::cerr <<
"Warning in line <" << current_line_n
2991 <<
"> of file <" << input_filename
2992 <<
">: You are using the deprecated spelling <" 2994 <<
"> of the parameter <" 2996 <<
">." << std::endl;
3010 if (entry_value.find (
'{') == std::string::npos)
3012 const unsigned int pattern_index
3019 patterns[pattern_index]->description()));
3030 (
"No entry with name <" + entry_name +
3031 "> was declared in the current subsection.")));
3040 while ((line.size() > 0) && (line[0] ==
' '))
3047 "The current line is an 'include' or " 3048 "'INCLUDE' statement, but it does not " 3049 "name a file for inclusion."));
3051 std::ifstream input (line.c_str());
3066 "could not be parsed: please check to " 3067 "make sure that the file is not missing a " 3068 "'set', 'include', 'subsection', or 'end' " 3090 for (
unsigned int j=0; j<
patterns.size(); ++j)
3101 std::ostringstream o1, o2;
3103 write_json (o2, *prm2.
entries);
3104 return (o1.str() == o2.str());
3129 const std::string &filename,
3130 const std::string &last_line)
3138 catch (
const ExcIO &)
3147 std::cerr << exc.
what() << std::endl;
3156 const std::string &filename,
3157 const std::string &last_line)
3172 for (
unsigned int run_no=0; run_no<
n_branches; ++run_no)
3203 std::cerr <<
" The entry value" << std::endl
3205 <<
" for the entry named" << std::endl
3207 <<
" does not have the right number of entries for the " << std::endl
3208 <<
" " <<
n_branches <<
" variant runs that will be performed." 3224 const boost::property_tree::ptree ¤t_section
3235 for (boost::property_tree::ptree::const_assoc_iterator
3236 p = current_section.ordered_begin();
3237 p != current_section.not_found(); ++p)
3238 if (is_parameter_node (p->second) ==
true)
3240 const std::string value = p->second.get<std::string>(
"value");
3241 if (value.find(
'{') != std::string::npos)
3248 for (boost::property_tree::ptree::const_iterator
3249 p = current_section.begin();
3250 p != current_section.end(); ++p)
3251 if (is_parameter_node (p->second) ==
false)
3264 unsigned int possibilities = 1;
3266 std::vector<Entry>::iterator choice;
3271 const unsigned int selection
3272 = (run_no/possibilities) % choice->different_values.size();
3273 std::string entry_value;
3275 entry_value = choice->different_values[selection];
3278 if (run_no>=choice->different_values.size())
3280 std::cerr <<
"The given array for entry <" 3281 << choice->entry_name
3282 <<
"> does not contain enough elements! Taking empty string instead." 3287 entry_value = choice->different_values[run_no];
3299 set (choice->entry_name, entry_value);
3304 possibilities *= choice->different_values.size();
3324 const std::string &Name,
3325 const std::string &Value)
3327 subsection_path (ssp), entry_name(Name), entry_value(Value), type (
Entry::array)
3338 std::string prefix (entry_value, 0, entry_value.find(
'{'));
3339 std::string multiple(entry_value, entry_value.find(
'{')+1,
3340 entry_value.rfind(
'}')-entry_value.find(
'{')-1);
3341 std::string postfix (entry_value, entry_value.rfind(
'}')+1, std::string::npos);
3344 if (multiple[0]==
'{')
3345 multiple.erase (0,1);
3346 if (multiple[multiple.size()-1] ==
'}')
3347 multiple.erase (multiple.size()-1, 1);
3350 while (std::isspace (multiple[0])) multiple.erase (0,1);
3351 while (std::isspace (multiple[multiple.size()-1])) multiple.erase (multiple.size()-1,1);
3354 while (multiple.find(
" |") != std::string::npos)
3355 multiple.replace (multiple.find(
" |"), 2,
"|");
3356 while (multiple.find(
"| ") != std::string::npos)
3357 multiple.replace (multiple.find(
"| "), 2,
"|");
3359 while (multiple.find(
'|') != std::string::npos)
3361 different_values.push_back (prefix +
3362 std::string(multiple, 0, multiple.find(
'|'))+
3364 multiple.erase (0, multiple.find(
'|')+1);
3368 different_values.push_back (prefix+multiple+postfix);
3371 if ((entry_value.find(
"{{") != std::string::npos) &&
3372 (entry_value.find(
"}}") != std::string::npos))
3389 DEAL_II_NAMESPACE_CLOSE
std::vector< Entry > multiple_choices
std::size_t memory_consumption() const
long int get_integer(const std::string &entry_string) const
virtual bool match(const std::string &test_string) const
static const char path_separator
PatternBase * key_pattern
virtual bool match(const std::string &test_string) const
virtual ~ParameterHandler()
static const char * description_init
static const char * description_init
static ::ExceptionBase & ExcInvalidEntryForPatternXML(std::string arg1, std::string arg2, std::string arg3)
static ::ExceptionBase & ExcCannotOpenIncludeStatementFile(int arg1, std::string arg2, std::string arg3)
static ::ExceptionBase & ExcIO()
virtual void run(ParameterHandler &prm)=0
std::string get_current_path() const
virtual bool match(const std::string &test_string) const
static ::ExceptionBase & ExcEntryUndeclared(std::string arg1)
std::string trim(const std::string &input)
std::string get(const std::string &entry_string) const
static ::ExceptionBase & ExcUnbalancedSubsections(std::string arg1, std::string arg2)
std::size_t memory_consumption() const
const std::string separator
static Map * create(const std::string &description)
void log_parameters(LogStream &out)
std::vector< std::string > break_text_into_lines(const std::string &original_text, const unsigned int width, const char delimiter=' ')
static const unsigned int max_int_value
static const char * description_init
void set(const std::string &entry_name, const std::string &new_value)
virtual PatternBase * clone() const
virtual bool match(const std::string &test_string) const
void log_parameters_section(LogStream &out)
virtual std::string description(const OutputStyle style=Machine) const
static Double * create(const std::string &description)
virtual void parse_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="")
static const int max_int_value
#define AssertThrow(cond, exc)
const unsigned int max_elements
static ::ExceptionBase & ExcCommasNotAllowed(int arg1)
static const char * description_init
static ::ExceptionBase & ExcValueDoesNotMatchPattern(std::string arg1, std::string arg2)
std::vector< std::string > subsection_path
static const int min_int_value
double string_to_double(const std::string &s)
void init_branches_current_section()
static ::ExceptionBase & ExcInvalidRange(int arg1, int arg2)
virtual PatternBase * clone() const =0
void enter_subsection(const std::string &subsection)
static ::ExceptionBase & ExcFileNotFound(std::string arg1, std::string arg2)
virtual void parse_input_from_xml(std::istream &input)
FileName(const FileType type=input)
static ::ExceptionBase & ExcInvalidXMLParameterFile()
static const char * description_init
virtual PatternBase * clone() const
static ::ExceptionBase & ExcMessage(std::string arg1)
static const char * description_init
static Integer * create(const std::string &description)
virtual void create_new(const unsigned int run_no)=0
static ::ExceptionBase & ExcCannotParseLine(int arg1, std::string arg2, std::string arg3)
double get_double(const std::string &entry_name) const
virtual bool read_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="") 1
std::size_t memory_consumption() const
static const char * description_init
static Bool * create(const std::string &description)
virtual std::string description(const OutputStyle style=Machine) const
virtual ~MultipleParameterLoop()
virtual bool read_input_from_xml(std::istream &input) 1
virtual std::string description(const OutputStyle style=Machine) const
Double(const double lower_bound=min_double_value, const double upper_bound=max_double_value)
#define Assert(cond, exc)
std::string get_current_full_path(const std::string &name) const
List(const PatternBase &base_pattern, const unsigned int min_elements=0, const unsigned int max_elements=max_int_value, const std::string &separator=",")
MultipleSelection(const std::string &seq)
virtual std::size_t memory_consumption() const
static const char * description_init
static Anything * create(const std::string &description)
static ::ExceptionBase & ExcInvalidRange(int arg1, int arg2)
Map(const PatternBase &key_pattern, const PatternBase &value_pattern, const unsigned int min_elements=0, const unsigned int max_elements=max_int_value, const std::string &separator=",")
PatternBase * pattern_factory(const std::string &description)
static std::string mangle(const std::string &s)
bool match_at_string_start(const std::string &name, const std::string &pattern)
virtual std::string description(const OutputStyle style=Machine) const
virtual PatternBase * clone() const
std::size_t memory_consumption() const
static const double min_double_value
void fill_entry_values(const unsigned int run_no)
virtual bool read_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="") 1
virtual std::string description(const OutputStyle style=Machine) const
bool get_bool(const std::string &entry_name) const
virtual bool match(const std::string &test_string) const
static const char * description_init
virtual void parse_input_from_string(const char *s, const std::string &last_line="")
static ::ExceptionBase & ExcAlreadyAtTopLevel()
virtual PatternBase * clone() const
std::string replace_in_string(const std::string &input, const std::string &from, const std::string &to)
virtual std::string description(const OutputStyle style=Machine) const
virtual bool match(const std::string &test_string) const =0
virtual PatternBase * clone() const
virtual std::string description(const OutputStyle style=Machine) const
bool operator==(const ParameterHandler &prm2) const
std::string find(const std::string &filename, const char *open_mode="r")
virtual bool match(const std::string &test_string) const
static const char * description_init
std::size_t memory_consumption() const
std_cxx11::enable_if< std_cxx11::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
std::size_t memory_consumption() const
virtual PatternBase * clone() const
static const double max_double_value
void push(const std::string &text)
virtual std::string description(const OutputStyle style=Machine) const =0
virtual bool match(const std::string &test_string) const
virtual PatternBase * clone() const
static std::string demangle(const std::string &s)
std::ostream & print_parameters(std::ostream &out, const OutputStyle style)
Integer(const int lower_bound=min_int_value, const int upper_bound=max_int_value)
void print_parameters_section(std::ostream &out, const OutputStyle style, const unsigned int indent_level, const bool include_top_level_elements=false)
virtual PatternBase * clone() const
std_cxx11::unique_ptr< boost::property_tree::ptree > entries
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string())
int string_to_int(const std::string &s)
Selection(const std::string &seq)
static DirectoryName * create(const std::string &description)
static ::ExceptionBase & ExcNotImplemented()
static FileName * create(const std::string &description)
static MultipleSelection * create(const std::string &description)
virtual bool match(const std::string &test_string) const
void scan_line(std::string line, const std::string &input_filename, const unsigned int current_line_n)
const unsigned int min_elements
std::size_t memory_consumption() const
static ::ExceptionBase & ExcInvalidEntryForPattern(int arg1, std::string arg2, std::string arg3, std::string arg4, std::string arg5)
static List * create(const std::string &description)
virtual bool read_input_from_string(const char *s, const std::string &last_line="")
static const unsigned int max_int_value
static Selection * create(const std::string &description)
virtual PatternBase * clone() const
static ::ExceptionBase & ExcNoSubsection(int arg1, std::string arg2, std::string arg3)
const std::string separator
virtual std::string description(const OutputStyle style=Machine) const
void split_different_values()
void declare_alias(const std::string &existing_entry_name, const std::string &alias_name, const bool alias_is_deprecated=false)
const unsigned int max_elements
virtual std::string description(const OutputStyle style=Machine) const
virtual const char * what() const DEAL_II_NOEXCEPT
virtual bool match(const std::string &test_string) const
const unsigned int min_elements
virtual std::string description(const OutputStyle style=Machine) const
std::vector< std_cxx11::shared_ptr< const Patterns::PatternBase > > patterns
virtual PatternBase * clone() const
static ::ExceptionBase & ExcInternalError()
virtual void parse_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="")