/**
* List of possible output
* formats.
+ *
+ * The formats down the list with
+ * prefix <em>Short</em> and bit
+ * 6 and 7 set reproduce the old
+ * behavior of not writing
+ * comments or original values to
+ * the files.
*/
enum OutputStyle {
/**
- * Write human readable output.
+ * Write human readable
+ * output suitable to be
+ * read by ParameterHandler
+ * again.
*/
- Text,
+ Text = 1,
/**
* Write paramteters as a
* LaTeX table.
*/
- LaTeX,
+ LaTeX = 2,
/**
- * Write parameters as an
- * HTML table.
+ * Write input for
+ * ParameterHandler without
+ * comments or changed
+ * default values.
*/
- HTML
+ ShortText = 193
};
/**
* Read input from a file the
- * name of which is given.
+ * name of which is given. The
+ * PathSearch class "PARAMETERS"
+ * is used to find the file.
*
* Return whether the read was
* successful.
*
- * This function will
- * automatically generate the
- * requested file with default
- * values if the file did not
- * exist.
+ * Unless <tt>optional</tt> is
+ * <tt>true</tt>, this function
+ * will automatically generate
+ * the requested file with
+ * default values if the file did
+ * not exist. This file will not
+ * contain additional comments if
+ * <tt>write_stripped_file</tt>
+ * is <tt>true</tt>.
*/
- virtual bool read_input (const std::string &filename);
+ virtual bool read_input (const std::string &filename,
+ const bool optional = false,
+ const bool write_stripped_file = false);
/**
* Read input from a string in
*/
virtual ~MultipleParameterLoop ();
- /**
- * Read input from a stream until stream
- * returns <tt>eof</tt> condition or error.
- */
- virtual bool read_input (std::istream &Input);
-
- /**
- * Read input from a file the name of which
- * is given.
- */
- virtual bool read_input (const std::string &FileName);
+ virtual bool read_input (std::istream &Input);
+ virtual bool read_input (const std::string &FileName,
+ const bool optional = false,
+ const bool write_stripped_file = false);
/**
* Read input from a string in memory. The
#include <base/parameter_handler.h>
#include <base/logstream.h>
+#include <base/path_search.h>
#include <base/memory_consumption.h>
#include <base/utilities.h>
#include <fstream>
-bool ParameterHandler::read_input (const std::string &filename)
+bool ParameterHandler::read_input (const std::string &filename,
+ bool optional,
+ bool write_compact)
{
- std::ifstream input (filename.c_str());
- if (!input)
+ PathSearch search("PARAMETERS");
+
+ try
+ {
+ std::string openname = search.find(filename);
+ std::ifstream input (openname.c_str());
+ if (!input)
+ {
+ AssertThrow(false, ExcInternalError());
+ }
+ return read_input (input);
+ }
+ catch (...)
{
std::cerr << "ParameterHandler::read_input: could not open file <"
- << filename << "> for reading." << std::endl
- << "Trying to make file <"
- << filename << "> with default values for you." << std::endl;
-
- std::ofstream output (filename.c_str());
- if (output)
- print_parameters (output, Text);
-
- return false;
+ << filename << "> for reading." << std::endl;
+ if (!optional)
+ {
+ std:: cerr << "Trying to make file <"
+ << filename << "> with default values for you." << std::endl;
+ std::ofstream output (filename.c_str());
+ if (output)
+ print_parameters (output, (write_compact ? ShortText : Text));
+ }
}
-
- return read_input (input);
+ return false;
}
ParameterHandler::print_parameters (std::ostream &out,
const OutputStyle style)
{
- // assert that only known formats are
- // given as "style"
- Assert ((style == Text) || (style == LaTeX), ExcNotImplemented());
-
AssertThrow (out, ExcIO());
switch (style)
out << "\\begin{itemize}"
<< std::endl;
break;
+ case ShortText:
+ break;
default:
Assert (false, ExcNotImplemented());
};
switch (style)
{
case Text:
+ case ShortText:
break;
case LaTeX:
out << "\\end{itemize}" << std::endl;
}
+// Print a section in the desired style. The styles are separated into
+// several verbosity classes depending on the higher bits.
+//
+// If bit 7 (128) is set, comments are not printed.
+// If bit 6 (64) is set, default values after change are not printed.
void
ParameterHandler::print_parameters_section (std::ostream &out,
const OutputStyle style,
const unsigned int indent_level)
{
- // assert that only known formats are
- // given as "style"
- Assert ((style == Text) || (style == LaTeX), ExcNotImplemented());
-
AssertThrow (out, ExcIO());
Section *pd = get_present_defaults_subsection ();
switch (style)
{
case Text:
- {
- // first find out the longest
- // entry name to be able to
- // align the equal signs
+ case ShortText:
+ {
+ // first find out the longest
+ // entry name to be able to
+ // align the equal signs
unsigned int longest_name = 0;
for (ptr = pd->entries.begin(); ptr != pd->entries.end(); ++ptr)
if (ptr->first.length() > longest_name)
// chunks such that the whole
// thing is at most 78 characters
// wide
- if (pd->entries[ptr->first].has_documentation())
+ if ((!style & 128) && pd->entries[ptr->first].has_documentation())
{
if (ptr != pd->entries.begin())
out << std::endl;
// default value, but
// only if it differs
// from the actual value
- if (value != pd->entries[ptr->first].value)
+ if ((!style & 64) && value != pd->entries[ptr->first].value)
{
out << std::setw(longest_value-value.length()+1) << " "
<< "# ";
// subsection; also make sure that the
// subsections will be printed at all
// (i.e. at least one of them is non-empty)
- if ((pd->entries.size() != 0)
+ if ((!style & 128)
+ &&
+ (pd->entries.size() != 0)
&&
(pd->subsections.size() != 0)
&&
switch (style)
{
case Text:
+ case ShortText:
out << std::setw(indent_level*2) << ""
<< "subsection " << ptrss->first << std::endl;
break;
leave_subsection ();
switch (style)
{
- case Text:
- // write end of
- // subsection. one
- // blank line after
- // each subsection
- out << std::setw(indent_level*2) << ""
- << "end" << std::endl
- << std::endl;
-
- // if this is a toplevel
- // subsection, then have two
- // newlines
- if (indent_level == 0)
- out << std::endl;
-
+ case Text:
+ // write end of
+ // subsection. one
+ // blank line after
+ // each subsection
+ out << std::setw(indent_level*2) << ""
+ << "end" << std::endl
+ << std::endl;
+
+ // if this is a toplevel
+ // subsection, then have two
+ // newlines
+ if (indent_level == 0)
+ out << std::endl;
+
+ break;
+ case ShortText:
+ // write end of
+ // subsection.
+ out << std::setw(indent_level*2) << ""
+ << "end" << std::endl;
break;
case LaTeX:
out << "\\end{itemize}"
-bool MultipleParameterLoop::read_input (const std::string &filename)
+bool MultipleParameterLoop::read_input (const std::string &filename,
+ bool optional,
+ bool write_compact)
{
- return ParameterHandler::read_input (filename);
+ return ParameterHandler::read_input (filename, optional, write_compact);
// don't call init_branches, since this read_input
// function calls
// MultipleParameterLoop::Readinput(std::istream &, std::ostream &)