16 #include <deal.II/base/parameter_acceptor.h> 17 #include <deal.II/base/path_search.h> 18 #include <deal.II/base/utilities.h> 20 #include <boost/core/demangle.hpp> 24 DEAL_II_NAMESPACE_OPEN
33 : acceptor_id(class_list.size())
37 this, boost::core::demangle(
typeid(*this).name()).c_str());
51 boost::core::demangle(
typeid(*this).name()));
57 const std::string & filename,
58 const std::string & output_filename,
63 if (!filename.empty())
66 if (filename.substr(filename.find_last_of(
'.') + 1) ==
"prm")
72 catch (const ::PathSearch::ExcFileNotFound &)
74 std::ofstream out(filename);
81 "parameter file, but it does not exist. " +
82 "We created it for you."));
85 else if (filename.substr(filename.find_last_of(
'.') + 1) ==
"xml")
87 std::ifstream is(filename);
90 std::ofstream out(filename);
97 "parameter file, but it does not exist. " +
98 "We created it for you."));
106 "Invalid extension of parameter file. Please use .prm or .xml"));
109 if (!output_filename.empty())
111 std::ofstream outfile(output_filename.c_str());
113 std::string extension =
114 output_filename.substr(output_filename.find_last_of(
'.') + 1);
116 if (extension ==
"prm")
118 outfile <<
"# Parameter file generated with " << std::endl
119 <<
"# DEAL_II_PACKAGE_VERSION = " << DEAL_II_PACKAGE_VERSION
125 "Only Text or ShortText can be specified in output_style_for_prm_format."))
128 else if (extension ==
"xml")
130 else if (extension ==
"latex" || extension ==
"tex")
177 if (instance !=
nullptr)
179 instance->enter_my_subsection(
prm);
180 instance->parse_parameters(
prm);
181 instance->parse_parameters_call_back();
182 instance->leave_my_subsection(
prm);
190 if (instance !=
nullptr)
192 instance->enter_my_subsection(
prm);
193 instance->declare_parameters(
prm);
194 instance->declare_parameters_call_back();
195 instance->leave_my_subsection(
prm);
200 std::vector<std::string>
205 const bool is_absolute = (my_section_name.front() ==
sep);
207 std::vector<std::string> sections =
214 sections.erase(sections.begin());
224 bool has_trailing =
class_list[i]->get_section_name().back() ==
sep;
225 auto previous_path =
class_list[i]->get_section_path();
228 if ((previous_path.size() > 0) && has_trailing ==
false)
229 previous_path.resize(previous_path.size() - 1);
231 sections.insert(sections.begin(),
232 previous_path.begin(),
233 previous_path.end());
246 for (
const auto &sec : sections)
257 for (
unsigned int i = 0; i < sections.size(); ++i)
265 DEAL_II_NAMESPACE_CLOSE
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
const unsigned int acceptor_id
static void initialize(const std::string &filename="", const std::string &output_filename="", const ParameterHandler::OutputStyle output_style_for_prm_format=ParameterHandler::ShortText, ParameterHandler &prm=ParameterAcceptor::prm)
void enter_my_subsection(ParameterHandler &prm)
static ::ExceptionBase & ExcIO()
static void declare_all_parameters(ParameterHandler &prm=ParameterAcceptor::prm)
virtual void parse_parameters(ParameterHandler &prm)
std::ostream & print_parameters(std::ostream &out, const OutputStyle style) const
#define AssertThrow(cond, exc)
ParameterAcceptor(const std::string §ion_name="")
static std::vector< SmartPointer< ParameterAcceptor > > class_list
virtual ~ParameterAcceptor() override
void enter_subsection(const std::string &subsection)
virtual void parse_input_from_xml(std::istream &input)
static ::ExceptionBase & ExcMessage(std::string arg1)
std::string get_section_name() const
#define Assert(cond, exc)
virtual void parse_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="", const bool skip_undefined=false)
std::vector< std::string > get_section_path() const
virtual void declare_parameters(ParameterHandler &prm)
static ParameterHandler prm
static ::ExceptionBase & ExcNotImplemented()
static void parse_all_parameters(ParameterHandler &prm=ParameterAcceptor::prm)
const std::string section_name
void leave_my_subsection(ParameterHandler &prm)
static ::ExceptionBase & ExcInternalError()