* - format options: PRM, LaTeX, Description, XML, JSON
* - stylistic options: Short, KeepDeclarationOrder
*
- * A valid combination of options is given in the following table:
+ * Only one format option may be specified at the time. Any function that
+ * accepts an OutputStyle as an option will throw if you specify more than
+ * one.
*
- * Stylistic options | Default | PRM | LaTeX | Description | XML | JSON
- * -------------------- | ------- | --- | ----- | ----------- | --- | ----
- * Default | X | X | X | X | X | X
- * Short | X | X | - | X | X | X
- * KeepDeclarationOrder | X | X | X | X | X | X
- *
- * Valid combinations are checked at the beginning of the functions that
- * accept an OutputStyle as an input argument.
- *
- * Furthermore, a number of shortcuts of commonly used option combinations are
- * provided. E.g., ShortPRM prints the parameters in the PRM
- * format, while skipping the documentation.
+ * A number of shortcuts of commonly used option combinations are provided.
+ * E.g., ShortPRM prints the parameters in the PRM format, while skipping the
+ * documentation.
*/
enum OutputStyle
{
JSON = 0x0100,
/**
- * Write input for ParameterHandler without comments or changed default
+ * Write the content of ParameterHandler without comments or changed default
* values.
*/
ShortPRM = PRM | Short,
/**
- * Write input for ParameterHandler without comments or changed default
+ * Write the content of ParameterHandler without comments or changed default
* values.
*
* @deprecated Use `ShortPRM` instead of `ShortText`.
ShortText = ShortPRM,
/**
- * Write input for ParameterHandler without comments or changed default
+ * Write the content of ParameterHandler without comments or changed default
* values as a XML file.
*/
ShortXML = XML | Short,
/**
- * Write input for ParameterHandler without comments or changed default
+ * Write the content of ParameterHandler without comments or changed default
* values as a JSON file.
*/
ShortJSON = JSON | Short,
+
+ /**
+ * Write the content of ParameterHandler without comments or changed default
+ * values as a LaTeX file.
+ */
+ ShortLaTeX = LaTeX | Short,
};
* available.
*
* By using the flag <tt>Short</tt> in combination with <tt>PRM</tt>,
- * <tt>XML</tt>, or <tt>JSON</tt> (or by using the shortcuts
- * <tt>ShortPRM</tt>, <tt>ShortXML</tt>, or <tt>ShortJSON</tt>), a reduced
- * output can be generated, only containing the values and skipping the
- * documentation.
+ * <tt>XML</tt>, <tt>JSON</tt>, or <tt>LaTeX</tt> (or by using the shortcuts
+ * <tt>ShortPRM</tt>, <tt>ShortXML</tt>, <tt>ShortJSON</tt>, or
+ * <tt>ShortLaTeX</tt>), a reduced output can be generated, only containing
+ * the values and skipping the documentation.
*
* 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
((style & ParameterHandler::Description) != 0) +
((style & ParameterHandler::LaTeX) != 0)) == 1,
ExcMessage(
- "You have chosen either no or multiple style formats. You can choose between: PRM, Description, LaTeX, XML, JSON."));
-
- AssertThrow(((style & ParameterHandler::LaTeX) &&
- (style & ParameterHandler::Short)) == false,
- ExcMessage("It is not possible to request short LaTex."));
+ "You have chosen either no or multiple style formats. You can choose "
+ "between: PRM, Description, LaTeX, XML, JSON."));
}
} // namespace
const bool assert_mandatory_entries_are_found)
{
std::ifstream is(filename);
- AssertThrow(is,
- ExcMessage("Invalid filename " + filename +
- " provided. File does not exist or "
- "can not be read from."));
+ AssertThrow(is, PathSearch::ExcFileNotFound(filename, "ParameterHandler"));
std::string file_ending = filename.substr(filename.find_last_of('.') + 1);
boost::algorithm::to_lower(file_ending);
//
// This function is strongly based on read_xml_recursively().
void
- recursively_remove_documentation_from_tree(
- boost::property_tree::ptree &source)
+ recursively_compress_tree(boost::property_tree::ptree &source)
{
for (auto &p : source)
{
else
{
// it must be a subsection
- recursively_remove_documentation_from_tree(p.second);
+ recursively_compress_tree(p.second);
}
}
}
// done recursively in our own code. take care of the two special formats
// first
- // explicity eliminate the documentation from the tree if requested
- if (style & Short)
+ // explicity compress the tree if requested
+ if ((style & Short) && (style & (XML | JSON)))
{
// modify the copy of the tree
- recursively_remove_documentation_from_tree(current_entries);
+ recursively_compress_tree(current_entries);
}
if (style & XML)
<< "# " << doc_line << '\n';
}
-
-
// print name and value of this entry
out << std::setw(overall_indent_level * 2) << ""
<< "set " << demangle(p.first)
// if there is a documenting string, print it as well but
// don't escape to allow formatting/formulas
- if (!(style & Short))
- if (!p.second.get<std::string>("documentation").empty())
- out << "{\\it Description:} "
- << p.second.get<std::string>("documentation") << "\n\n"
- << '\n';
-
- // also output possible values, do not escape because the
- // description internally will use LaTeX formatting
- const unsigned int pattern_index =
- p.second.get<unsigned int>("pattern");
- const std::string desc_str =
- patterns[pattern_index]->description(
- Patterns::PatternBase::LaTeX);
- out << "{\\it Possible values:} " << desc_str << '\n';
+ if (!is_short &&
+ !p.second.get<std::string>("documentation").empty())
+ out << "{\\it Description:} "
+ << p.second.get<std::string>("documentation") << "\n\n"
+ << '\n';
+ if (!is_short)
+ {
+ // also output possible values, do not escape because the
+ // description internally will use LaTeX formatting
+ const unsigned int pattern_index =
+ p.second.get<unsigned int>("pattern");
+ const std::string desc_str =
+ patterns[pattern_index]->description(
+ Patterns::PatternBase::LaTeX);
+ out << "{\\it Possible values:} " << desc_str << '\n';
+ }
}
else if (is_alias_node(p.second) == true)
{
out << '\n';
// if there is a documenting string, print it as well
- if (p.second.get<std::string>("documentation").length() != 0)
+ if (!is_short &&
+ p.second.get<std::string>("documentation").length() != 0)
out << std::setw(overall_indent_level * 2 + longest_name + 10)
<< ""
<< "(" << p.second.get<std::string>("documentation") << ")"
if (overall_indent_level == 0)
out << '\n';
}
- else if (style == Description)
+ else if (style & Description)
{
// nothing to do
}
- else if (style == LaTeX)
+ else if (style & LaTeX)
{
// nothing to do
}
DEAL:parameters:Second Class::Second string: bye bye
DEAL::reading used_parameter_acceptor_05.xml
DEAL::<?xml version="1.0" encoding="utf-8"?>
-DEAL::<ParameterHandler><First_20Class><First_20bool><value>true</value><default_value>true</default_value><documentation/><pattern>2</pattern><pattern_description>[Bool]</pattern_description><actions>2</actions></First_20bool><First_20double><value>7.7</value><default_value>7.7</default_value><documentation/><pattern>1</pattern><pattern_description>[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]</pattern_description><actions>1</actions></First_20double><First_20int><value>3</value><default_value>3</default_value><documentation/><pattern>0</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description><actions>0</actions></First_20int><First_20string><value>hello</value><default_value>hello</default_value><documentation/><pattern>3</pattern><pattern_description>[Anything]</pattern_description><actions>3</actions></First_20string></First_20Class><Second_20Class><Second_20bool><value>false</value><default_value>false</default_value><documentation/><pattern>6</pattern><pattern_description>[Bool]</pattern_description><actions>6</actions></Second_20bool><Second_20double><value>9.9</value><default_value>9.9</default_value><documentation/><pattern>5</pattern><pattern_description>[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]</pattern_description><actions>5</actions></Second_20double><Second_20int><value>5</value><default_value>5</default_value><documentation/><pattern>4</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description><actions>4</actions></Second_20int><Second_20string><value>bye bye</value><default_value>bye bye</default_value><documentation/><pattern>7</pattern><pattern_description>[Anything]</pattern_description><actions>7</actions></Second_20string></Second_20Class></ParameterHandler>
+DEAL::<ParameterHandler><First_20Class><First_20bool>true</First_20bool><First_20double>7.7</First_20double><First_20int>3</First_20int><First_20string>hello</First_20string></First_20Class><Second_20Class><Second_20bool>false</Second_20bool><Second_20double>9.9</Second_20double><Second_20int>5</Second_20int><Second_20string>bye bye</Second_20string></Second_20Class></ParameterHandler>
DEAL::{\it Default:} true
DEAL::
DEAL::
-DEAL::{\it Possible values:} A boolean value (true or false)
DEAL::\item {\it Parameter name:} {\tt First double}
DEAL::\phantomsection\label{parameters:First Class/First double}
DEAL::\label{parameters:First_20Class/First_20double}
DEAL::{\it Value:} 7.7
DEAL::
DEAL::
-DEAL::{\it Default:} 7.700000
+DEAL::{\it Default:} 7.7
DEAL::
DEAL::
-DEAL::{\it Possible values:} A floating point number $v$ such that $-\text{MAX\_DOUBLE} \leq v \leq \text{MAX\_DOUBLE}$
DEAL::\item {\it Parameter name:} {\tt First int}
DEAL::\phantomsection\label{parameters:First Class/First int}
DEAL::\label{parameters:First_20Class/First_20int}
DEAL::{\it Default:} 3
DEAL::
DEAL::
-DEAL::{\it Possible values:} An integer $n$ such that $-2147483648\leq n \leq 2147483647$
DEAL::\item {\it Parameter name:} {\tt First string}
DEAL::\phantomsection\label{parameters:First Class/First string}
DEAL::\label{parameters:First_20Class/First_20string}
DEAL::{\it Default:} hello
DEAL::
DEAL::
-DEAL::{\it Possible values:} Any string
DEAL::\end{itemize}
DEAL::
DEAL::\subsection{Parameters in section \tt Second Class}
DEAL::{\it Default:} false
DEAL::
DEAL::
-DEAL::{\it Possible values:} A boolean value (true or false)
DEAL::\item {\it Parameter name:} {\tt Second double}
DEAL::\phantomsection\label{parameters:Second Class/Second double}
DEAL::\label{parameters:Second_20Class/Second_20double}
DEAL::{\it Value:} 9.9
DEAL::
DEAL::
-DEAL::{\it Default:} 9.900000
+DEAL::{\it Default:} 9.9
DEAL::
DEAL::
-DEAL::{\it Possible values:} A floating point number $v$ such that $-\text{MAX\_DOUBLE} \leq v \leq \text{MAX\_DOUBLE}$
DEAL::\item {\it Parameter name:} {\tt Second int}
DEAL::\phantomsection\label{parameters:Second Class/Second int}
DEAL::\label{parameters:Second_20Class/Second_20int}
DEAL::{\it Default:} 5
DEAL::
DEAL::
-DEAL::{\it Possible values:} An integer $n$ such that $-2147483648\leq n \leq 2147483647$
DEAL::\item {\it Parameter name:} {\tt Second string}
DEAL::\phantomsection\label{parameters:Second Class/Second string}
DEAL::\label{parameters:Second_20Class/Second_20string}
DEAL::{\it Default:} bye bye
DEAL::
DEAL::
-DEAL::{\it Possible values:} Any string
DEAL::\end{itemize}
--- /dev/null
+//-----------------------------------------------------------
+//
+// Copyright (C) 2020 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+//-----------------------------------------------------------
+
+// Test that ParameterAcceptor::initialize() works as expected
+
+
+#include <deal.II/base/parameter_acceptor.h>
+#include <deal.II/base/point.h>
+
+#include "../tests.h"
+
+// Test subsectioning
+
+class Test : public ParameterAcceptor
+{
+public:
+ Test()
+ {
+ add_parameter("A point", a_point);
+ };
+
+private:
+ Point<3> a_point;
+};
+
+void
+test_ext(const std::string &ext)
+{
+ Test a;
+
+ deallog << "Generate and read input." << ext << std::endl;
+ try
+ {
+ ParameterAcceptor::initialize("input." + ext);
+ }
+ catch (...)
+ {
+ // The above call must have created a file named input.ext
+ cat_file(("input." + ext).c_str());
+ }
+}
+
+int
+main()
+{
+ initlog();
+ test_ext("prm");
+ test_ext("xml");
+ test_ext("json");
+}
--- /dev/null
+
+DEAL::Generate and read input.prm
+# Listing of Parameters
+# ---------------------
+subsection Test
+ set A point = 0, 0, 0
+end
+
+
+
+DEAL::Generate and read input.xml
+<?xml version="1.0" encoding="utf-8"?>
+<ParameterHandler><Test><A_20point><value>0, 0, 0</value><default_value>0, 0, 0</default_value><documentation/><pattern>1</pattern><pattern_description>[List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 3...3 (inclusive)]</pattern_description><actions>0,1</actions></A_20point></Test></ParameterHandler>
+
+DEAL::Generate and read input.json
+{
+ "Test":
+ {
+ "A_20point":
+ {
+ "value": "0, 0, 0",
+ "default_value": "0, 0, 0",
+ "documentation": "",
+ "pattern": "2",
+ "pattern_description": "[List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 3...3 (inclusive)]",
+ "actions": "0,1,2"
+ }
+ }
+}
+
DEAL::
--------------------------------------------------------
An error occurred in file <parameter_handler.cc> in function
- void dealii::ParameterHandler::set(const string&, const string&)
-The violated condition was:
+ void dealii::ParameterHandler::set(const std::string &, const std::string &)
+The violated condition was:
false
-Additional information:
+Additional information:
You can't ask for entry <Precison> you have not yet declared.
--------------------------------------------------------
--------------------------------------------------------
An error occurred in file <parameter_handler.cc> in function
void dealii::ParameterHandler::assert_that_entries_have_been_set() const
-The violated condition was:
+The violated condition was:
entries_wrongly_not_set.size() == 0
-Additional information:
- Not all entries of the parameter handler that were declared with `has_to_be_set = true` have been set. The following parameters
+Additional information:
+ Not all entries of the parameter handler that were declared with `has_to_be_set = true` have been set. The following parameters
General.Precision
General.dim
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2020 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+
+// test ParameterHandler::print_parameters for different formats
+
+#include <deal.II/base/parameter_handler.h>
+
+#include "../tests.h"
+
+int
+main()
+{
+ initlog();
+
+ double a = 1.0;
+ bool some_bool = true;
+ std::string a_string = "Ciao";
+
+ ParameterHandler prm;
+ prm.enter_subsection("Testing");
+ prm.add_parameter("A double", a);
+ prm.add_parameter("A bool", some_bool);
+ prm.add_parameter("A string", a_string);
+ prm.leave_subsection();
+
+ deallog << "PRM format: " << std::endl
+ << "========================================" << std::endl;
+ prm.print_parameters("output.prm");
+ cat_file("output.prm");
+
+ deallog << "XML format: " << std::endl
+ << "========================================" << std::endl;
+ prm.print_parameters("output.xml");
+ cat_file("output.xml");
+
+ deallog << "JSON format: " << std::endl
+ << "========================================" << std::endl;
+ prm.print_parameters("output.json");
+ cat_file("output.json");
+
+ deallog << "LaTeX format: " << std::endl
+ << "========================================" << std::endl;
+ prm.print_parameters("output.tex");
+ cat_file("output.tex");
+
+ deallog << "Description format: " << std::endl
+ << "========================================" << std::endl;
+ prm.print_parameters("output.dsc", ParameterHandler::Description);
+ cat_file("output.dsc");
+}
--- /dev/null
+
+DEAL::PRM format:
+DEAL::========================================
+# Listing of Parameters
+# ---------------------
+subsection Testing
+ set A bool = true
+ set A double = 1
+ set A string = Ciao
+end
+
+
+
+DEAL::XML format:
+DEAL::========================================
+<?xml version="1.0" encoding="utf-8"?>
+<ParameterHandler><Testing><A_20bool><value>true</value><default_value>true</default_value><documentation/><pattern>1</pattern><pattern_description>[Bool]</pattern_description><actions>1</actions></A_20bool><A_20double><value>1</value><default_value>1</default_value><documentation/><pattern>0</pattern><pattern_description>[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]</pattern_description><actions>0</actions></A_20double><A_20string><value>Ciao</value><default_value>Ciao</default_value><documentation/><pattern>2</pattern><pattern_description>[Anything]</pattern_description><actions>2</actions></A_20string></Testing></ParameterHandler>
+
+DEAL::JSON format:
+DEAL::========================================
+{
+ "Testing":
+ {
+ "A_20bool":
+ {
+ "value": "true",
+ "default_value": "true",
+ "documentation": "",
+ "pattern": "1",
+ "pattern_description": "[Bool]",
+ "actions": "1"
+ },
+ "A_20double":
+ {
+ "value": "1",
+ "default_value": "1",
+ "documentation": "",
+ "pattern": "0",
+ "pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]",
+ "actions": "0"
+ },
+ "A_20string":
+ {
+ "value": "Ciao",
+ "default_value": "Ciao",
+ "documentation": "",
+ "pattern": "2",
+ "pattern_description": "[Anything]",
+ "actions": "2"
+ }
+ }
+}
+
+DEAL::LaTeX format:
+DEAL::========================================
+\subsection{Global parameters}
+\label{parameters:global}
+
+
+
+\subsection{Parameters in section \tt Testing}
+\label{parameters:Testing}
+
+\begin{itemize}
+\item {\it Parameter name:} {\tt A bool}
+\phantomsection\label{parameters:Testing/A bool}
+\label{parameters:Testing/A_20bool}
+
+
+\index[prmindex]{A bool}
+\index[prmindexfull]{Testing!A bool}
+{\it Value:} true
+
+
+{\it Default:} true
+
+
+{\it Possible values:} A boolean value (true or false)
+\item {\it Parameter name:} {\tt A double}
+\phantomsection\label{parameters:Testing/A double}
+\label{parameters:Testing/A_20double}
+
+
+\index[prmindex]{A double}
+\index[prmindexfull]{Testing!A double}
+{\it Value:} 1
+
+
+{\it Default:} 1
+
+
+{\it Possible values:} A floating point number $v$ such that $-\text{MAX\_DOUBLE} \leq v \leq \text{MAX\_DOUBLE}$
+\item {\it Parameter name:} {\tt A string}
+\phantomsection\label{parameters:Testing/A string}
+\label{parameters:Testing/A_20string}
+
+
+\index[prmindex]{A string}
+\index[prmindexfull]{Testing!A string}
+{\it Value:} Ciao
+
+
+{\it Default:} Ciao
+
+
+{\it Possible values:} Any string
+\end{itemize}
+
+DEAL::Description format:
+DEAL::========================================
+Listing of Parameters:
+
+subsection Testing
+ set A bool = A boolean value (true or false)
+ set A double = A floating point number v such that -MAX_DOUBLE <= v <= MAX_DOUBLE
+ set A string = Any string
+
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2020 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+
+// test ParameterHandler::print_parameters for different formats in
+// combination with Short
+
+#include <deal.II/base/parameter_handler.h>
+
+#include "../tests.h"
+
+int
+main()
+{
+ initlog(1);
+
+ double a = 1.0;
+ double b = 2.0;
+
+ ParameterHandler prm;
+ prm.add_parameter("A double", a, "Documentation for a.");
+ prm.enter_subsection("Section two");
+ prm.add_parameter("Another double", b, "Documentation for b.");
+ prm.leave_subsection();
+
+ const auto style = ParameterHandler::Short;
+
+ deallog << "ShortPRM format: " << std::endl
+ << "========================================" << std::endl;
+ prm.print_parameters("output.prm", style);
+ cat_file("output.prm");
+
+ deallog << "ShortXML format: " << std::endl
+ << "========================================" << std::endl;
+ prm.print_parameters("output.xml", style);
+ cat_file("output.xml");
+
+ deallog << "ShortJSON format: " << std::endl
+ << "========================================" << std::endl;
+ prm.print_parameters("output.json", style);
+ cat_file("output.json");
+
+ deallog << "ShortLaTeX format: " << std::endl
+ << "========================================" << std::endl;
+ prm.print_parameters("output.tex", style);
+ cat_file("output.tex");
+
+ deallog << "Short | Description format: " << std::endl
+ << "========================================" << std::endl;
+ prm.print_parameters("output.dsc", ParameterHandler::Description | style);
+ cat_file("output.dsc");
+}
--- /dev/null
+
+DEAL::ShortPRM format:
+DEAL::========================================
+set A double = 1
+subsection Section two
+ set Another double = 2
+end
+
+DEAL::ShortXML format:
+DEAL::========================================
+<?xml version="1.0" encoding="utf-8"?>
+<ParameterHandler><A_20double>1</A_20double><Section_20two><Another_20double>2</Another_20double></Section_20two></ParameterHandler>
+
+DEAL::ShortJSON format:
+DEAL::========================================
+{
+ "A_20double": "1",
+ "Section_20two": {
+ "Another_20double": "2"
+ }
+}
+
+DEAL::ShortLaTeX format:
+DEAL::========================================
+\subsection{Global parameters}
+\label{parameters:global}
+
+
+\begin{itemize}
+\item {\it Parameter name:} {\tt A double}
+\phantomsection\label{parameters:A double}
+\label{parameters:A_20double}
+
+
+\index[prmindex]{A double}
+\index[prmindexfull]{A double}
+{\it Value:} 1
+
+
+{\it Default:} 1
+
+
+\end{itemize}
+
+
+
+\subsection{Parameters in section \tt Section two}
+\label{parameters:Section_20two}
+
+\begin{itemize}
+\item {\it Parameter name:} {\tt Another double}
+\phantomsection\label{parameters:Section two/Another double}
+\label{parameters:Section_20two/Another_20double}
+
+
+\index[prmindex]{Another double}
+\index[prmindexfull]{Section two!Another double}
+{\it Value:} 2
+
+
+{\it Default:} 2
+
+
+\end{itemize}
+
+DEAL::Short | Description format:
+DEAL::========================================
+Listing of Parameters:
+
+set A double = A floating point number v such that -MAX_DOUBLE <= v <= MAX_DOUBLE
+subsection Section two
+ set Another double = A floating point number v such that -MAX_DOUBLE <= v <= MAX_DOUBLE
+