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> 40 DEAL_II_NAMESPACE_OPEN
57 bool has_only_whitespace (std::istream &in)
68 if ((c !=
' ') && (c !=
'\t'))
117 Assert(
false, ExcNotImplemented());
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))
194 return description.str();
216 std::istringstream is(description);
225 if (!(is >> lower_bound))
228 is.ignore(strlen(
"..."));
230 if (!(is >> upper_bound))
233 return new Integer(lower_bound, upper_bound);
252 lower_bound (lower_bound),
253 upper_bound (upper_bound)
260 std::istringstream str(test_string);
266 if (!has_only_whitespace (str))
293 return description.str();
301 return description.str();
318 std::istringstream is(description);
326 if (!(is >> lower_bound))
329 is.ignore(strlen(
"..."));
331 if (!(is >> upper_bound))
334 return new Double(lower_bound, upper_bound);
352 while (sequence.find(
" |") != std::string::npos)
353 sequence.replace (sequence.find(
" |"), 2,
"|");
354 while (sequence.find(
"| ") != std::string::npos)
355 sequence.replace (sequence.find(
"| "), 2,
"|");
362 std::vector<std::string> choices;
363 std::string tmp(sequence);
365 while (tmp.find(
'|') != std::string::npos)
367 if (test_string == std::string(tmp, 0, tmp.find(
'|')))
370 tmp.erase (0, tmp.find(
'|')+1);
373 if (test_string == tmp)
391 return description.str();
416 std::string sequence(description);
419 sequence.erase(sequence.length()-2, 2);
430 = std::numeric_limits<unsigned int>::max();
436 const unsigned int min_elements,
437 const unsigned int max_elements,
438 const std::string &separator)
441 min_elements (min_elements),
442 max_elements (max_elements),
443 separator (separator)
445 Assert (min_elements <= max_elements,
446 ExcInvalidRange (min_elements, max_elements));
447 Assert (separator.size() > 0,
448 ExcMessage (
"The separator must have a non-zero length."));
463 std::string tmp = test_string_list;
464 std::vector<std::string> split_list;
467 while (tmp.length() != 0)
472 if (name.find(
separator) != std::string::npos)
474 name.erase (name.find(
separator), std::string::npos);
480 while ((name.length() != 0) &&
481 (std::isspace (name[0])))
484 while (std::isspace (name[name.length()-1]))
485 name.erase (name.length()-1, 1);
487 split_list.push_back (name);
495 for (std::vector<std::string>::const_iterator
496 test_string = split_list.begin();
497 test_string != split_list.end(); ++test_string)
515 description <<
" separated by <" <<
separator <<
">";
518 return description.str();
533 return (
sizeof(*
this) +
546 std::istringstream is(description);
550 std::getline(is, str,
'>');
552 std_cxx11::shared_ptr<PatternBase> base_pattern (
pattern_factory(str));
554 is.ignore(strlen(
" of length "));
555 if (!(is >> min_elements))
556 return new List(*base_pattern);
558 is.ignore(strlen(
"..."));
559 if (!(is >> max_elements))
560 return new List(*base_pattern, min_elements);
562 is.ignore(strlen(
" separated by <"));
565 std::getline(is, separator,
'>');
569 return new List(*base_pattern, min_elements, max_elements, separator);
578 = std::numeric_limits<unsigned int>::max();
589 key_pattern (p_key.
clone()),
590 value_pattern (p_value.
clone()),
591 min_elements (min_elements),
592 max_elements (max_elements),
593 separator (separator)
595 Assert (min_elements <= max_elements,
596 ExcInvalidRange (min_elements, max_elements));
597 Assert (separator.size() > 0,
598 ExcMessage (
"The separator must have a non-zero length."));
600 ExcMessage (
"The separator can not be a colon ':' since that " 601 "is the separator between the two elements of <key:value> pairs"));
611 delete value_pattern;
619 std::string tmp = test_string_list;
620 std::vector<std::string> split_list;
623 while (tmp.length() != 0)
625 std::string map_entry;
628 if (map_entry.find(
separator) != std::string::npos)
630 map_entry.erase (map_entry.find(
separator), std::string::npos);
636 while ((map_entry.length() != 0) &&
637 (std::isspace (map_entry[0])))
638 map_entry.erase (0,1);
640 while (std::isspace (map_entry[map_entry.length()-1]))
641 map_entry.erase (map_entry.length()-1, 1);
643 split_list.push_back (map_entry);
651 for (std::vector<std::string>::const_iterator
652 test_string = split_list.begin();
653 test_string != split_list.end(); ++test_string)
656 if (test_string->find(
":") == std::string::npos)
661 std::string key = *test_string;
662 key.erase (key.find(
":"), std::string::npos);
663 while ((key.length() > 0) && (std::isspace (key[key.length()-1])))
664 key.erase (key.length()-1, 1);
666 std::string value = *test_string;
667 value.erase (0, value.find(
":")+1);
668 while ((value.length() > 0) && (std::isspace (value[0])))
674 if (value_pattern->
match (value) ==
false)
694 description <<
" separated by <" <<
separator <<
">";
697 return description.str();
714 return (
sizeof(*
this) +
728 std::istringstream is(description);
732 std::getline(is, str,
'>');
735 std::string key = str;
736 key.erase (key.find(
":"), std::string::npos);
738 std::string value = str;
739 value.erase (0, value.find(
":")+1);
742 std_cxx11::shared_ptr<PatternBase> value_pattern (
pattern_factory(value));
744 is.ignore(strlen(
" of length "));
745 if (!(is >> min_elements))
746 return new Map(*key_pattern, *value_pattern);
748 is.ignore(strlen(
"..."));
749 if (!(is >> max_elements))
750 return new Map(*key_pattern, *value_pattern, min_elements);
752 is.ignore(strlen(
" separated by <"));
755 std::getline(is, separator,
'>');
759 return new Map(*key_pattern, *value_pattern,
760 min_elements, max_elements,
774 Assert (seq.find (
",") == std::string::npos, ExcCommasNotAllowed(seq.find(
",")));
777 while (sequence.find(
" |") != std::string::npos)
778 sequence.replace (sequence.find(
" |"), 2,
"|");
779 while (sequence.find(
"| ") != std::string::npos)
780 sequence.replace (sequence.find(
"| "), 2,
"|");
787 std::string tmp = test_string_list;
788 std::list<std::string> split_list;
791 while (tmp.length() != 0)
796 if (name.find(
",") != std::string::npos)
798 name.erase (name.find(
","), std::string::npos);
799 tmp.erase (0, tmp.find(
",")+1);
804 while ((name.length() != 0) &&
805 (std::isspace (name[0])))
807 while (std::isspace (name[name.length()-1]))
808 name.erase (name.length()-1, 1);
810 split_list.push_back (name);
815 for (std::list<std::string>::const_iterator test_string = split_list.begin();
816 test_string != split_list.end(); ++test_string)
818 bool string_found =
false;
821 while (tmp.find(
'|') != std::string::npos)
823 if (*test_string == std::string(tmp, 0, tmp.find(
'|')))
833 tmp.erase (0, tmp.find(
'|')+1);
837 if (*test_string == tmp)
858 return description.str();
883 std::string sequence(description);
886 sequence.erase(sequence.length()-2, 2);
913 return description.str();
958 return description.str();
1004 description <<
" (Type: input)]";
1006 description <<
" (Type: output)]";
1008 return description.str();
1025 std::istringstream is(description);
1033 if (file_type ==
"input)]")
1067 return description.str();
1094 entries (new boost::property_tree::ptree())
1111 u.reserve (s.size());
1114 const bool mangle_whole_string = (s ==
"value");
1119 for (
unsigned int i=0; i<s.size(); ++i)
1121 static const std::string allowed_characters
1122 (
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
1124 if ((! mangle_whole_string)
1126 (allowed_characters.find (s[i]) != std::string::npos))
1131 static const char hex[16]
1132 = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'};
1133 u.push_back (hex[static_cast<unsigned char>(s[i])/16]);
1134 u.push_back (hex[static_cast<unsigned char>(s[i])%16]);
1147 u.reserve (s.size());
1149 for (
unsigned int i=0; i<s.size(); ++i)
1155 ExcMessage (
"Trying to demangle an invalid string."));
1157 unsigned char c = 0;
1209 Assert (
false, ExcInternalError());
1262 Assert (
false, ExcInternalError());
1265 u.push_back (static_cast<char>(c));
1283 is_parameter_node (
const boost::property_tree::ptree &p)
1285 return static_cast<bool>(p.get_optional<std::string>(
"value"));
1294 is_alias_node (
const boost::property_tree::ptree &p)
1296 return static_cast<bool>(p.get_optional<std::string>(
"alias"));
1324 if (path.empty() ==
false)
1335 const std::string &filename)
1342 std::string input_line;
1343 std::string fully_concatenated_line;
1344 bool is_concatenated =
false;
1345 unsigned int current_line_n = 0;
1348 while (std::getline (input, input_line))
1357 if (input_line.length() != 0 &&
1358 input_line.find_last_of(
'\\') == input_line.length() - 1)
1360 input_line.erase (input_line.length() - 1);
1361 is_concatenated =
true;
1363 fully_concatenated_line += input_line;
1367 else if (is_concatenated)
1369 fully_concatenated_line += input_line;
1370 is_concatenated =
false;
1376 fully_concatenated_line = input_line;
1379 if (!is_concatenated)
1381 status &=
scan_line (fully_concatenated_line, filename, current_line_n);
1382 fully_concatenated_line.clear();
1388 if (is_concatenated)
1390 status &=
scan_line (fully_concatenated_line, filename, current_line_n);
1395 std::cerr <<
"Unbalanced 'subsection'/'end' in file <" << filename
1396 <<
">." << std::endl;
1397 if (saved_path.size()>0)
1399 std::cerr <<
"Path before loading input:" << std::endl;
1400 for (
unsigned int i=0; i<saved_path.size(); ++i)
1401 std::cerr << std::setw(i*2+4) <<
" " 1402 <<
"subsection " << saved_path[i] << std::endl;
1404 std::cerr <<
"Current path:" << std::endl;
1406 std::cerr << std::setw(i*2+4) <<
" " 1420 const bool optional,
1421 const bool write_compact)
1427 std::string openname = search.
find(filename);
1428 std::ifstream file_stream (openname.c_str());
1433 catch (
const PathSearch::ExcFileNotFound &)
1435 std::cerr <<
"ParameterHandler::read_input: could not open file <" 1436 << filename <<
"> for reading." << std::endl;
1439 std:: cerr <<
"Trying to make file <" 1440 << filename <<
"> with default values for you." << std::endl;
1441 std::ofstream output (filename.c_str());
1453 std::istringstream input_stream (s);
1454 return read_input (input_stream,
"input string");
1470 read_xml_recursively (
const boost::property_tree::ptree &source,
1471 const std::string ¤t_path,
1473 const std::vector<std_cxx11::shared_ptr<const Patterns::PatternBase> > &
1475 boost::property_tree::ptree &destination)
1477 for (boost::property_tree::ptree::const_iterator p = source.begin();
1478 p != source.end(); ++p)
1482 if (p->second.get_optional<std::string>(
"value"))
1487 const std::string full_path
1488 = (current_path ==
"" 1492 current_path + path_separator + p->first);
1493 if (destination.get_optional<std::string> (full_path)
1495 destination.get_optional<std::string> (full_path +
1502 const std::string new_value
1503 = p->second.get<std::string>(
"value");
1505 const unsigned int pattern_index
1506 = destination.get<
unsigned int> (full_path +
1509 if (
patterns[pattern_index]->match(new_value) ==
false)
1511 std::cerr <<
" The entry value" << std::endl
1512 <<
" " << new_value << std::endl
1513 <<
" for the entry named" << std::endl
1514 <<
" " << full_path << std::endl
1515 <<
" does not match the given pattern" << std::endl
1516 <<
" " <<
patterns[pattern_index]->description()
1523 destination.put (full_path + path_separator +
"value",
1539 std::cerr <<
"The entry <" << full_path
1541 << p->second.get<std::string>(
"value")
1542 <<
"> has not been declared." 1547 else if (p->second.get_optional<std::string>(
"alias"))
1558 = read_xml_recursively (p->second,
1559 (current_path ==
"" ?
1561 current_path + path_separator + p->first),
1569 if (result ==
false)
1586 boost::property_tree::ptree single_node_tree;
1589 read_xml (in, single_node_tree);
1593 std::cerr <<
"This input stream appears not to be valid XML" 1600 if (!single_node_tree.get_optional<std::string>(
"ParameterHandler"))
1602 std::cerr <<
"There is no top-level XML element called \"ParameterHandler\"." 1609 if (std::distance (single_node_tree.begin(), single_node_tree.end()) != 1)
1611 std::cerr <<
"The top-level XML element \"ParameterHandler\" is " 1612 <<
"not the only one." 1614 std::cerr <<
"(There are " 1615 << std::distance (single_node_tree.begin(),
1616 single_node_tree.end())
1617 <<
" top-level elements.)" 1623 const boost::property_tree::ptree
1624 &my_entries = single_node_tree.get_child(
"ParameterHandler");
1634 entries.reset (
new boost::property_tree::ptree());
1641 const std::string &default_value,
1643 const std::string &documentation)
1654 patterns.push_back (std_cxx11::shared_ptr<const Patterns::PatternBase>
1657 static_cast<unsigned int>(
patterns.size()-1));
1668 "pattern_description",
1673 ExcValueDoesNotMatchPattern (default_value, pattern.
description()));
1680 const std::string &alias_name,
1681 const bool alias_is_deprecated)
1685 ExcMessage (
"You are trying to declare an alias entry <" 1687 "> that references an entry <" 1688 + existing_entry_name +
1689 ">, but the latter does not exist."));
1693 ExcMessage (
"You are trying to declare an alias entry <" 1695 "> that references an entry <" 1696 + existing_entry_name +
1697 ">, but the latter does not seem to be a " 1698 "parameter declaration."));
1707 ExcMessage (
"You are trying to declare an alias entry <" 1709 "> but a non-alias entry already exists in this " 1710 "subsection (i.e., there is either a preexisting " 1711 "further subsection, or a parameter entry, with " 1712 "the same name as the alias)."));
1715 existing_entry_name,
1716 ExcMessage (
"You are trying to declare an alias entry <" 1718 "> but an alias entry already exists in this " 1719 "subsection and this existing alias references a " 1720 "different parameter entry. Specifically, " 1721 "you are trying to reference the entry <" 1722 + existing_entry_name +
1723 "> whereas the existing alias references " 1730 existing_entry_name);
1732 (alias_is_deprecated ?
"true" :
"false"));
1744 boost::property_tree::ptree());
1769 if (boost::optional<std::string> value
1774 Assert (
false, ExcEntryUndeclared(entry_string));
1790 ExcMessage(
"Can't convert the parameter value <" 1791 +
get(entry_string) +
1794 " to an integer."));
1810 ExcMessage(
"Can't convert the parameter value <" 1811 +
get(entry_string) +
1814 " to a double precision variable."));
1823 const std::string s =
get(entry_string);
1826 (s==
"yes") || (s==
"no"),
1827 ExcMessage(
"Can't convert the parameter value <" 1828 +
get(entry_string) +
1832 if (s==
"true" || s==
"yes")
1842 const std::string &new_value)
1852 const unsigned int pattern_index
1855 ExcValueDoesNotMatchPattern (new_value,
1859 "pattern_description")));
1865 AssertThrow (
false, ExcEntryUndeclared(entry_string));
1871 const char *new_value)
1874 set (entry_string, std::string(new_value));
1880 const double &new_value)
1882 std::ostringstream s;
1883 s << std::setprecision(16);
1888 set (entry_string, s.str());
1895 const long int &new_value)
1897 std::ostringstream s;
1902 set (entry_string, s.str());
1909 const bool &new_value)
1914 (new_value ?
"true" :
"false"));
1947 boost::property_tree::ptree single_node_tree;
1948 single_node_tree.add_child(
"ParameterHandler",
1951 write_xml (out, single_node_tree);
1966 out <<
"# Listing of Parameters" << std::endl
1967 <<
"# ---------------------" << std::endl;
1970 out <<
"\\subsection{Global parameters}" << std::endl;
1971 out <<
"\\label{parameters:global}" << std::endl;
1972 out << std::endl << std::endl;
1975 out <<
"Listing of Parameters:" << std::endl << std::endl;
1980 Assert (
false, ExcNotImplemented());
1995 Assert (
false, ExcNotImplemented());
2011 const unsigned int indent_level,
2012 const bool include_top_level_elements)
2016 const boost::property_tree::ptree ¤t_section
2019 unsigned int overall_indent_level = indent_level;
2025 if (include_top_level_elements)
2046 boost::property_tree::ptree single_node_tree;
2054 single_node_tree.add_child(
"ParameterHandler",
2059 std::string path (
"ParameterHandler");
2061 single_node_tree.add_child(path,
2062 boost::property_tree::ptree());
2065 single_node_tree.add_child (path, current_section);
2068 write_xml (out, single_node_tree);
2071 Assert (
false, ExcNotImplemented());
2082 out << std::setw(overall_indent_level*2) <<
"" 2084 overall_indent_level += 1;
2097 std::size_t longest_name = 0;
2098 for (boost::property_tree::ptree::const_iterator
2099 p = current_section.begin();
2100 p != current_section.end(); ++p)
2101 if (is_parameter_node (p->second) ==
true)
2102 longest_name = std::max (longest_name,
2110 std::size_t longest_value = 0;
2111 for (boost::property_tree::ptree::const_iterator
2112 p = current_section.begin();
2113 p != current_section.end(); ++p)
2114 if (is_parameter_node (p->second) ==
true)
2115 longest_value = std::max (longest_value,
2116 p->second.get<std::string>(
"value").length());
2123 bool first_entry =
true;
2124 for (boost::property_tree::ptree::const_assoc_iterator
2125 p = current_section.ordered_begin();
2126 p != current_section.not_found(); ++p)
2127 if (is_parameter_node (p->second) ==
true)
2129 const std::string value = p->second.get<std::string>(
"value");
2141 if ((!(style & 128)) &&
2142 !p->second.get<std::string>(
"documentation").empty())
2144 if (first_entry ==
false)
2147 first_entry =
false;
2149 const std::vector<std::string> doc_lines
2152 78 - overall_indent_level*2 - 2);
2154 for (
unsigned int i=0; i<doc_lines.size(); ++i)
2155 out << std::setw(overall_indent_level*2) <<
"" 2165 out << std::setw(overall_indent_level*2) <<
"" 2168 << std::setw(longest_name-
demangle(p->first).length()+1) <<
" " 2175 if ((!(style & 64)) && value != p->second.get<std::string>(
"default_value"))
2177 out << std::setw(longest_value-value.length()+1) <<
' ' 2179 out <<
"default: " << p->second.get<std::string>(
"default_value");
2193 bool parameters_exist_here =
false;
2194 for (boost::property_tree::ptree::const_assoc_iterator
2195 p = current_section.ordered_begin();
2196 p != current_section.not_found(); ++p)
2197 if ((is_parameter_node (p->second) ==
true)
2199 (is_alias_node (p->second) ==
true))
2201 parameters_exist_here =
true;
2205 if (parameters_exist_here)
2207 out <<
"\\begin{itemize}" 2214 for (boost::property_tree::ptree::const_assoc_iterator
2215 p = current_section.ordered_begin();
2216 p != current_section.not_found(); ++p)
2217 if (is_parameter_node (p->second) ==
true)
2219 const std::string value = p->second.get<std::string>(
"value");
2222 out <<
"\\item {\\it Parameter name:} {\\tt " <<
demangle(p->first) <<
"}\n" 2223 <<
"\\phantomsection\\label{parameters:";
2230 out <<
"\\index[prmindex]{" 2233 out <<
"\\index[prmindexfull]{";
2240 out <<
"{\\it Value:} " << value <<
"\n\n" 2242 <<
"{\\it Default:} " 2243 << p->second.get<std::string>(
"default_value") <<
"\n\n" 2249 if (!p->second.get<std::string>(
"documentation").empty())
2250 out <<
"{\\it Description:} " 2251 << p->second.get<std::string>(
"documentation") <<
"\n\n" 2255 out <<
"{\\it Possible values:} " 2256 << p->second.get<std::string> (
"pattern_description")
2259 else if (is_alias_node (p->second) ==
true)
2261 const std::string alias = p->second.get<std::string>(
"alias");
2264 out <<
"\\item {\\it Parameter name:} {\\tt " <<
demangle(p->first) <<
"}\n" 2265 <<
"\\phantomsection\\label{parameters:";
2272 out <<
"\\index[prmindex]{" 2275 out <<
"\\index[prmindexfull]{";
2282 out <<
"This parameter is an alias for the parameter ``\\texttt{" 2284 << (p->second.get<std::string>(
"deprecation_status") ==
"true" 2286 " Its use is deprecated." 2292 out <<
"\\end{itemize}" << std::endl;
2304 out << std::setw(overall_indent_level*2) <<
"" 2306 overall_indent_level += 1;
2312 std::size_t longest_name = 0;
2313 for (boost::property_tree::ptree::const_iterator
2314 p = current_section.begin();
2315 p != current_section.end(); ++p)
2316 if (is_parameter_node (p->second) ==
true)
2317 longest_name = std::max (longest_name,
2324 for (boost::property_tree::ptree::const_assoc_iterator
2325 p = current_section.ordered_begin();
2326 p != current_section.not_found(); ++p)
2327 if (is_parameter_node (p->second) ==
true)
2329 const std::string value = p->second.get<std::string>(
"value");
2332 out << std::setw(overall_indent_level*2) <<
"" 2335 << std::setw(longest_name-
demangle(p->first).length()+1) <<
" " 2339 const std::vector<std::string> description_str
2341 (
"pattern_description"),
2342 78 - overall_indent_level*2 - 2,
'|');
2343 if (description_str.size() > 1)
2346 for (
unsigned int i=0; i<description_str.size(); ++i)
2347 out << std::setw(overall_indent_level*2+6) <<
"" 2348 << description_str[i] << std::endl;
2350 else if (description_str.empty() ==
false)
2351 out <<
" " << description_str[0] << std::endl;
2358 if (p->second.get<std::string>(
"documentation").length() != 0)
2359 out << std::setw(overall_indent_level*2 + longest_name + 10) <<
"" 2360 <<
"(" << p->second.get<std::string>(
"documentation") <<
")" << std::endl;
2367 Assert (
false, ExcNotImplemented());
2377 unsigned int n_parameters = 0;
2378 unsigned int n_sections = 0;
2379 for (boost::property_tree::ptree::const_iterator
2380 p = current_section.begin();
2381 p != current_section.end(); ++p)
2382 if (is_parameter_node (p->second) ==
true)
2384 else if (is_alias_node (p->second) ==
false)
2394 out << std::endl << std::endl;
2398 for (boost::property_tree::ptree::const_assoc_iterator
2399 p = current_section.ordered_begin();
2400 p != current_section.not_found(); ++p)
2401 if ((is_parameter_node (p->second) ==
false)
2403 (is_alias_node (p->second) ==
false))
2411 out << std::setw(overall_indent_level*2) <<
"" 2412 <<
"subsection " <<
demangle(p->first) << std::endl;
2417 <<
"\\subsection{Parameters in section \\tt ";
2427 out <<
"}" << std::endl;
2428 out <<
"\\label{parameters:";
2431 out << p->first <<
"}";
2439 Assert (
false, ExcNotImplemented());
2454 out << std::setw(overall_indent_level*2) <<
"" 2455 <<
"end" << std::endl
2461 if (overall_indent_level == 0)
2470 out << std::setw(overall_indent_level*2) <<
"" 2471 <<
"end" << std::endl;
2476 Assert (
false, ExcNotImplemented());
2494 overall_indent_level -= 1;
2495 out << std::setw(overall_indent_level*2) <<
"" 2496 <<
"end" << std::endl;
2503 Assert (
false, ExcNotImplemented());
2513 out.
push(
"parameters");
2526 const boost::property_tree::ptree ¤t_section
2533 for (boost::property_tree::ptree::const_assoc_iterator
2534 p = current_section.ordered_begin();
2535 p != current_section.not_found(); ++p)
2536 if (is_parameter_node (p->second) ==
true)
2538 << p->second.get<std::string>(
"value") << std::endl;
2543 for (boost::property_tree::ptree::const_assoc_iterator
2544 p = current_section.ordered_begin();
2545 p != current_section.not_found(); ++p)
2546 if (is_parameter_node (p->second) ==
false)
2560 const std::string &input_filename,
2561 const unsigned int current_line_n)
2564 if (line.find(
'#') != std::string::npos)
2565 line.erase (line.find(
"#"), std::string::npos);
2568 while (line.find(
'\t') != std::string::npos)
2569 line.replace (line.find(
'\t'), 1,
" ");
2575 if (line.length() == 0)
2579 if ((line.find (
"SUBSECTION ") == 0) ||
2580 (line.find (
"subsection ") == 0))
2583 line.erase (0, std::string(
"subsection").length()+1);
2590 std::cerr <<
"Line <" << current_line_n
2591 <<
"> of file <" << input_filename
2592 <<
">: There is no such subsection to be entered: " 2595 std::cerr << std::setw(i*2+4) <<
" " 2598 <<
"subsection " << subsection << std::endl;
2608 if ((line.find (
"END") == 0) ||
2609 (line.find (
"end") == 0))
2612 while ((line.size() > 0) && (std::isspace(line[0])))
2617 std::cerr <<
"Line <" << current_line_n
2618 <<
"> of file <" << input_filename
2619 <<
">: invalid content after 'end'!" << std::endl;
2625 std::cerr <<
"Line <" << current_line_n
2626 <<
"> of file <" << input_filename
2627 <<
">: There is no subsection to leave here!" << std::endl;
2639 if ((line.find (
"SET ") == 0) ||
2640 (line.find (
"set ") == 0))
2645 std::string::size_type pos = line.find(
"=");
2646 if (pos == std::string::npos)
2648 std::cerr <<
"Line <" << current_line_n
2649 <<
"> of file <" << input_filename
2650 <<
">: invalid format of set expression!" << std::endl;
2656 std::string entry_value =
Utilities::trim(std::string(line, pos+1, std::string::npos));
2665 std::cerr <<
"Warning in line <" << current_line_n
2666 <<
"> of file <" << input_filename
2667 <<
">: You are using the deprecated spelling <" 2669 <<
"> of the parameter <" 2671 <<
">." << std::endl;
2685 if (entry_value.find (
'{') == std::string::npos)
2687 const unsigned int pattern_index
2689 if (!
patterns[pattern_index]->match(entry_value))
2691 std::cerr <<
"Line <" << current_line_n
2692 <<
"> of file <" << input_filename
2693 <<
">:" << std::endl
2694 <<
" The entry value" << std::endl
2695 <<
" " << entry_value << std::endl
2696 <<
" for the entry named" << std::endl
2697 <<
" " << entry_name << std::endl
2698 <<
" does not match the given pattern" << std::endl
2699 <<
" " <<
patterns[pattern_index]->description()
2711 std::cerr <<
"Line <" << current_line_n
2712 <<
"> of file <" << input_filename
2713 <<
">: No such entry was declared:" << std::endl
2714 <<
" " << entry_name << std::endl
2715 <<
" <Present subsection:" << std::endl;
2717 std::cerr << std::setw(i*2+8) <<
" " 2719 std::cerr <<
" >" << std::endl;
2726 if ((line.find (
"INCLUDE ") == 0) ||
2727 (line.find (
"include ") == 0))
2731 while ((line.size() > 0) && (line[0] ==
' '))
2735 if (line.size() == 0)
2737 std::cerr <<
"Line <" << current_line_n
2738 <<
"> of file <" << input_filename
2739 <<
"> is an include statement but does not name a file!" 2745 std::ifstream input (line.c_str());
2748 std::cerr <<
"Line <" << current_line_n
2749 <<
"> of file <" << input_filename
2750 <<
"> is an include statement but the file <" 2751 << line <<
"> could not be opened!" 2761 std::cerr <<
"Line <" << current_line_n
2762 <<
"> of file <" << input_filename
2763 <<
">: This line matched nothing known ('set' or 'subsection' missing!?):" << std::endl
2764 <<
" " << line << std::endl;
2785 for (
unsigned int j=0; j<
patterns.size(); ++j)
2796 std::ostringstream o1, o2;
2798 write_json (o2, *prm2.
entries);
2799 return (o1.str() == o2.str());
2823 const std::string &filename)
2837 for (
unsigned int run_no=0; run_no<
n_branches; ++run_no)
2868 std::cerr <<
" The entry value" << std::endl
2870 <<
" for the entry named" << std::endl
2872 <<
" does not have the right number of entries for the " << std::endl
2873 <<
" " <<
n_branches <<
" variant runs that will be performed." 2889 const boost::property_tree::ptree ¤t_section
2900 for (boost::property_tree::ptree::const_assoc_iterator
2901 p = current_section.ordered_begin();
2902 p != current_section.not_found(); ++p)
2903 if (is_parameter_node (p->second) ==
true)
2905 const std::string value = p->second.get<std::string>(
"value");
2906 if (value.find(
'{') != std::string::npos)
2913 for (boost::property_tree::ptree::const_iterator
2914 p = current_section.begin();
2915 p != current_section.end(); ++p)
2916 if (is_parameter_node (p->second) ==
false)
2929 unsigned int possibilities = 1;
2931 std::vector<Entry>::iterator choice;
2936 const unsigned int selection
2937 = (run_no/possibilities) % choice->different_values.size();
2938 std::string entry_value;
2939 if (choice->type == Entry::variant)
2940 entry_value = choice->different_values[selection];
2943 if (run_no>=choice->different_values.size())
2945 std::cerr <<
"The given array for entry <" 2946 << choice->entry_name
2947 <<
"> does not contain enough elements! Taking empty string instead." 2952 entry_value = choice->different_values[run_no];
2964 set (choice->entry_name, entry_value);
2968 if (choice->type == Entry::variant)
2969 possibilities *= choice->different_values.size();
2989 const std::string &Name,
2990 const std::string &Value)
3009 if (multiple[0]==
'{')
3010 multiple.erase (0,1);
3011 if (multiple[multiple.size()-1] ==
'}')
3012 multiple.erase (multiple.size()-1, 1);
3015 while (std::isspace (multiple[0])) multiple.erase (0,1);
3016 while (std::isspace (multiple[multiple.size()-1])) multiple.erase (multiple.size()-1,1);
3019 while (multiple.find(
" |") != std::string::npos)
3020 multiple.replace (multiple.find(
" |"), 2,
"|");
3021 while (multiple.find(
"| ") != std::string::npos)
3022 multiple.replace (multiple.find(
"| "), 2,
"|");
3024 while (multiple.find(
'|') != std::string::npos)
3027 std::string(multiple, 0, multiple.find(
'|'))+
3029 multiple.erase (0, multiple.find(
'|')+1);
3036 if ((
entry_value.find(
"{{") != std::string::npos) &&
3038 type = Entry::array;
3040 type = Entry::variant;
3054 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()
virtual std::string description() const
static const char * description_init
static const char * description_init
virtual std::string description() const
virtual void run(ParameterHandler &prm)=0
std::string get_current_path() const
virtual bool match(const std::string &test_string) const
::ExceptionBase & ExcMessage(std::string arg1)
std::string trim(const std::string &input)
virtual std::string description() const =0
std::string get(const std::string &entry_string) const
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)
static Double * create(const std::string &description)
std::vector< std::string > subsection_path
static const int max_int_value
#define AssertThrow(cond, exc)
const unsigned int max_elements
static const char * description_init
std::vector< std::string > subsection_path
static const int min_int_value
virtual std::string description() const
virtual std::string description() const
double string_to_double(const std::string &s)
void init_branches_current_section()
virtual PatternBase * clone() const =0
void enter_subsection(const std::string &subsection)
FileName(const FileType type=input)
static const char * description_init
virtual PatternBase * clone() const
static const char * description_init
static Integer * create(const std::string &description)
virtual void create_new(const unsigned int run_no)=0
double get_double(const std::string &entry_name) const
std::size_t memory_consumption() const
static const char * description_init
static Bool * create(const std::string &description)
virtual ~MultipleParameterLoop()
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
virtual std::string description() const
static Anything * create(const std::string &description)
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)
virtual PatternBase * clone() const
virtual bool read_input_from_string(const char *s)
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")
bool get_bool(const std::string &entry_name) const
virtual bool match(const std::string &test_string) const
static const char * description_init
virtual PatternBase * clone() const
virtual bool match(const std::string &test_string) const =0
virtual PatternBase * clone() 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
virtual std::string description() 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 std::string description() const
virtual PatternBase * clone() const
static const double max_double_value
void push(const std::string &text)
virtual bool match(const std::string &test_string) const
virtual PatternBase * clone() const
bool scan_line(std::string line, const std::string &input_filename, const unsigned int current_line_n)
virtual std::string description() 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)
virtual std::string description() const
static DirectoryName * create(const std::string &description)
static FileName * create(const std::string &description)
static MultipleSelection * create(const std::string &description)
virtual bool match(const std::string &test_string) const
std::vector< std::string > different_values
const unsigned int min_elements
std::size_t memory_consumption() const
virtual bool read_input_from_xml(std::istream &input)
static List * create(const std::string &description)
static const unsigned int max_int_value
static Selection * create(const std::string &description)
virtual PatternBase * clone() const
virtual std::string description() const
const std::string separator
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 bool match(const std::string &test_string) const
const unsigned int min_elements
virtual bool read_input(std::istream &input, const std::string &filename="input file")
std::vector< std_cxx11::shared_ptr< const Patterns::PatternBase > > patterns
virtual PatternBase * clone() const