* Write input for ParameterHandler without comments or changed default
* values.
*/
- ShortText = 193
+ ShortText = 193,
+
+ /**
+ * Write input for ParameterHandler without comments or changed default
+ * values as a XML file.
+ */
+ ShortXML = 194,
+
+ /**
+ * Write input for ParameterHandler without comments or changed default
+ * values as a JSON file.
+ */
+ ShortJSON = 195
};
set(const std::string &entry_name, const bool new_value);
/**
- * Print all parameters with the given style to <tt>out</tt>.
+ * Print all parameters with the given style to @p out.
*
* Before printing, all current parameters and subsections are sorted
* alphabetically by default.
* This behavior can be disabled setting the last parameter @p sort_alphabetical
- * to @p false: in this case entries are printed in the same order
+ * to <tt>false</tt>: in this case entries are printed in the same order
* as they have been declared.
*
+ * In the case of <tt>XML</tt> or <tt>JSON</tt>, a reduced tree, only
+ * containing the values and skipping the documentation, can be
+ * printed by setting @p print_documentation to <tt>false</tt>.
+ *
* 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 record
* the parameters for a specific run, since if you output the parameters
}
}
}
+
+ // Recursively go through the @p source tree and collapse the nodes of the
+ // format:
+ //
+ //"key":
+ // {
+ // "value" : "val",
+ // "default_value" : "...",
+ // "documentation" : "...",
+ // "pattern" : "...",
+ // "pattern_description": "..."
+ // },
+ //
+ // to
+ //
+ // "key" : "val";
+ //
+ // As an example a JSON file is shown. However, this function also works for
+ // XML since both formats are build around the same BOOST data structures.
+ //
+ // This function is strongly based on read_xml_recursively().
+ void
+ recursively_remove_documentation_from_tree(
+ boost::property_tree::ptree &source)
+ {
+ for (auto &p : source)
+ {
+ if (p.second.get_optional<std::string>("value"))
+ {
+ // save the value in a temporal variable
+ const auto temp = p.second.get<std::string>("value");
+ // clear node (children and value)
+ p.second.clear();
+ // set the correct value
+ p.second.put_value<std::string>(temp);
+ }
+ else if (p.second.get_optional<std::string>("alias"))
+ {}
+ else
+ {
+ // it must be a subsection
+ recursively_remove_documentation_from_tree(p.second);
+ }
+ }
+ }
} // namespace
// Create entries copy and sort it, if needed.
// In this way we ensure that the class state is never
// modified by this function.
- boost::property_tree::ptree sorted_entries;
- boost::property_tree::ptree *current_entries = entries.get();
+ boost::property_tree::ptree current_entries = *entries.get();
// Sort parameters alphabetically, if needed.
if (sort_alphabetical)
{
- sorted_entries = *entries;
- current_entries = &sorted_entries;
-
// Dive recursively into the subsections,
// starting from the top level.
recursively_sort_parameters(path_separator,
std::vector<std::string>(),
- sorted_entries);
+ current_entries);
}
// we'll have to print some text that is padded with spaces;
// we treat XML and JSON is one step via BOOST, whereas all of the others are
// done recursively in our own code. take care of the two special formats
// first
- if (style == XML)
+
+ // explicity eliminate the documentation from the tree if requested
+ if (style == ShortXML || style == ShortJSON)
+ {
+ // modify the copy of the tree
+ recursively_remove_documentation_from_tree(current_entries);
+ }
+
+ if (style == XML || style == ShortXML)
{
// call the writer function and exit as there is nothing
// further to do down in this function
// single top-level node "ParameterHandler" and
// assign the existing tree under it
boost::property_tree::ptree single_node_tree;
- single_node_tree.add_child("ParameterHandler", *current_entries);
+ single_node_tree.add_child("ParameterHandler", current_entries);
write_xml(out, single_node_tree);
return out;
}
- if (style == JSON)
+ if (style == JSON || style == ShortJSON)
{
- write_json(out, *current_entries);
+ write_json(out, current_entries);
return out;
}
// dive recursively into the subsections
recursively_print_parameters(
- *current_entries,
+ current_entries,
std::vector<std::string>(), // start at the top level
style,
0,