/**
* Print all parameters with the given style to <tt>out</tt>. Presently
- * only <tt>Text</tt> and <tt>LaTeX</tt> are implemented.
+ * only <tt>Text</tt>, <tt>LaTeX</tt> and <tt>XML</tt> are implemented.
*
* In <tt>Text</tt> format, the output is formatted in such a way that it
* is possible to use it for later input again. This is most useful to
* well as the documenting string given to the declare_entry() function
* if available.
*
+ * In <tt>XML</tt> format, the output starts with one root element
+ * <tt>ParameterHandler</tt> in order to get a valid XML document
+ * and all subsections under it.
+ *
* In <tt>Text</tt> format, the output contains the same information but
* in a format so that the resulting file can be input into a latex
* document such as a manual for the code for which this object handles
* by entering and leaving subsections through the enter_subsection() and
* leave_subsection() functions.
*
+ * If <tt>include_top_level_elements</tt> is <tt>true</tt>, also
+ * the higher subsection elements are printed. In <tt>XML</tt> format
+ * this is required to get a valid XML document and output starts
+ * with one root element <tt>ParameterHandler</tt>.
+ *
* In most cases, you will not want to use this function directly, but
* have it called recursively by the previous function.
*/
void print_parameters_section (std::ostream &out,
const OutputStyle style,
- const unsigned int indent_level);
+ const unsigned int indent_level,
+ const bool include_top_level_elements = false);
/**
* Print parameters to a logstream. This function allows to print all
void
ParameterHandler::print_parameters_section (std::ostream &out,
const OutputStyle style,
- const unsigned int indent_level)
+ const unsigned int indent_level,
+ const bool include_top_level_elements)
{
AssertThrow (out, ExcIO());
const boost::property_tree::ptree ¤t_section
= entries->get_child (get_current_path());
+ unsigned int overall_indent_level = indent_level;
+
switch (style)
{
+ case XML:
+ {
+ if (include_top_level_elements)
+ {
+ // call the writer
+ // function and exit as
+ // there is nothing
+ // further to do down in
+ // this function
+ //
+ // XML has a requirement that
+ // there can only be one
+ // single top-level entry,
+ // but a section has multiple
+ // entries and sections. we
+ // work around this by
+ // creating a tree just for
+ // this purpose with the
+ // single top-level node
+ // "ParameterHandler" and
+ // assign the full path of
+ // down to the current section
+ // under it
+ boost::property_tree::ptree single_node_tree;
+
+ // if there is no subsection selected,
+ // add the whole tree of entries,
+ // otherwise add a root element
+ // and the selected subsection under it
+ if (subsection_path.size() == 0)
+ {
+ single_node_tree.add_child("ParameterHandler",
+ *entries);
+ }
+ else
+ {
+ std::string path ("ParameterHandler");
+
+ single_node_tree.add_child(path,
+ boost::property_tree::ptree());
+
+ path += path_separator + get_current_path ();
+ single_node_tree.add_child (path, current_section);
+ };
+
+ write_xml (out, single_node_tree);
+ }
+ else
+ Assert (false, ExcNotImplemented());
+
+ break;
+ }
case Text:
case ShortText:
{
+ // if there are top level elements to print, do it
+ if (include_top_level_elements && (subsection_path.size() > 0))
+ for (unsigned int i=0; i<subsection_path.size(); ++i)
+ {
+ out << std::setw(overall_indent_level*2) << ""
+ << "subsection " << demangle (subsection_path[i]) << std::endl;
+ overall_indent_level += 1;
+ };
+
// first find out the longest
// entry name to be able to
// align the equal signs
const std::vector<std::string> doc_lines
= Utilities::
break_text_into_lines (p->second.get<std::string>("documentation"),
- 78 - indent_level*2 - 2);
+ 78 - overall_indent_level*2 - 2);
for (unsigned int i=0; i<doc_lines.size(); ++i)
- out << std::setw(indent_level*2) << ""
+ out << std::setw(overall_indent_level*2) << ""
<< "# "
<< doc_lines[i]
<< std::endl;
// print name and value
// of this entry
- out << std::setw(indent_level*2) << ""
+ out << std::setw(overall_indent_level*2) << ""
<< "set "
<< demangle(p->first)
<< std::setw(longest_name-demangle(p->first).length()+1) << " "
case Description:
{
+ // if there are top level elements to print, do it
+ if (include_top_level_elements && (subsection_path.size() > 0))
+ for (unsigned int i=0; i<subsection_path.size(); ++i)
+ {
+ out << std::setw(overall_indent_level*2) << ""
+ << "subsection " << demangle (subsection_path[i]) << std::endl;
+ overall_indent_level += 1;
+ };
+
// first find out the longest
// entry name to be able to
// align the equal signs
const std::string value = p->second.get<std::string>("value");
// print name and value
- out << std::setw(indent_level*2) << ""
+ out << std::setw(overall_indent_level*2) << ""
<< "set "
<< demangle(p->first)
<< std::setw(longest_name-demangle(p->first).length()+1) << " "
const std::vector<std::string> description_str
= Utilities::break_text_into_lines (p->second.get<std::string>
("pattern_description"),
- 78 - indent_level*2 - 2, '|');
+ 78 - overall_indent_level*2 - 2, '|');
if (description_str.size() > 1)
{
out << std::endl;
for (unsigned int i=0; i<description_str.size(); ++i)
- out << std::setw(indent_level*2+6) << ""
+ out << std::setw(overall_indent_level*2+6) << ""
<< description_str[i] << std::endl;
}
else if (description_str.empty() == false)
// documenting string,
// print it as well
if (p->second.get<std::string>("documentation").length() != 0)
- out << std::setw(indent_level*2 + longest_name + 10) << ""
+ out << std::setw(overall_indent_level*2 + longest_name + 10) << ""
<< "(" << p->second.get<std::string>("documentation") << ")" << std::endl;
}
// sections to come, put two newlines
// between the last entry and the first
// subsection
+ if (style != XML)
{
unsigned int n_parameters = 0;
unsigned int n_sections = 0;
&&
(n_sections != 0))
out << std::endl << std::endl;
- }
// now traverse subsections tree,
// in alphabetical order
case Text:
case Description:
case ShortText:
- out << std::setw(indent_level*2) << ""
+ out << std::setw(overall_indent_level*2) << ""
<< "subsection " << demangle(p->first) << std::endl;
break;
case LaTeX:
// then the contents of the
// subsection
enter_subsection (demangle(p->first));
- print_parameters_section (out, style, indent_level+1);
+ print_parameters_section (out, style, overall_indent_level+1);
leave_subsection ();
switch (style)
{
// subsection. one
// blank line after
// each subsection
- out << std::setw(indent_level*2) << ""
+ out << std::setw(overall_indent_level*2) << ""
<< "end" << std::endl
<< std::endl;
// if this is a toplevel
// subsection, then have two
// newlines
- if (indent_level == 0)
+ if (overall_indent_level == 0)
out << std::endl;
break;
case ShortText:
// write end of
// subsection.
- out << std::setw(indent_level*2) << ""
+ out << std::setw(overall_indent_level*2) << ""
<< "end" << std::endl;
break;
case LaTeX:
}
}
+ // close top level elements, if there are any
+ switch (style)
+ {
+ case XML:
+ case LaTeX:
+ case Description:
+ break;
+ case Text:
+ case ShortText:
+ {
+ if (include_top_level_elements && (subsection_path.size() > 0))
+ for (unsigned int i=0; i<subsection_path.size(); ++i)
+ {
+ overall_indent_level -= 1;
+ out << std::setw(overall_indent_level*2) << ""
+ << "end" << std::endl;
+ };
+
+ break;
+ }
+
+ default:
+ Assert (false, ExcNotImplemented());
+ }
+
+}
+
void