Reference documentation for deal.II version 9.0.0
parameter_acceptor.h
1 //-----------------------------------------------------------
2 //
3 // Copyright (C) 2017 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 //-----------------------------------------------------------
15 
16 #ifndef dealii_base_parameter_acceptor_h
17 #define dealii_base_parameter_acceptor_h
18 
19 #include <deal.II/base/config.h>
20 #include <deal.II/base/parameter_handler.h>
21 #include <deal.II/base/smartpointer.h>
22 #include <deal.II/base/logstream.h>
23 #include <deal.II/base/exceptions.h>
24 #include <boost/signals2/signal.hpp>
25 #include <typeinfo>
26 
27 DEAL_II_NAMESPACE_OPEN
28 
346 {
347 public:
354  ParameterAcceptor(const std::string &section_name="");
355 
359  virtual ~ParameterAcceptor();
360 
387  static void initialize(const std::string &filename="",
388  const std::string &output_filename="",
389  const ParameterHandler::OutputStyle output_style_for_prm_format=ParameterHandler::ShortText,
391 
401  static void initialize(std::istream &input_stream,
403 
404 
408  static void clear();
409 
415  virtual void declare_parameters(ParameterHandler &prm);
416 
423  boost::signals2::signal<void()> declare_parameters_call_back;
424 
430  virtual void parse_parameters(ParameterHandler &prm);
431 
441  boost::signals2::signal<void()> parse_parameters_call_back;
442 
449 
457 
463  std::string get_section_name() const;
464 
469  std::vector<std::string> get_section_path() const;
470 
480  template <class ParameterType>
481  void add_parameter(const std::string &entry,
482  ParameterType &parameter,
483  const std::string &documentation = std::string(),
484  ParameterHandler &prm_ = prm,
485  const Patterns::PatternBase &pattern =
487 
492 
497 
503 
504 private:
509  static std::vector<SmartPointer<ParameterAcceptor> > class_list;
510 
512  const unsigned int acceptor_id;
513 
517  static const char sep = '/';
518 
519 protected:
521  const std::string section_name;
522 };
523 
524 
525 
577 template<class SourceClass>
578 class ParameterAcceptorProxy : public SourceClass, public ParameterAcceptor
579 {
580 public:
586  template<typename... Args>
587  ParameterAcceptorProxy(const std::string section_name, Args... args);
588 
593  virtual void declare_parameters(ParameterHandler &prm);
594 
599  virtual void parse_parameters(ParameterHandler &prm);
600 };
601 
602 
603 
604 // Inline and template functions
605 template<class ParameterType>
606 void ParameterAcceptor::add_parameter(const std::string &entry,
607  ParameterType &parameter,
608  const std::string &documentation,
609  ParameterHandler &prm,
610  const Patterns::PatternBase &pattern)
611 {
613  prm.add_parameter(entry, parameter, documentation, pattern);
615 }
616 
617 
618 
619 template<class SourceClass>
620 template<typename... Args>
622 ParameterAcceptorProxy(const std::string section_name, Args... args) :
623  SourceClass(args...),
624  ParameterAcceptor(section_name)
625 {
626 }
627 
628 
629 
630 template<class SourceClass>
632 {
633  SourceClass::declare_parameters(prm);
634 }
635 
636 
637 
638 template<class SourceClass>
640 {
641  SourceClass::parse_parameters(prm);
642 }
643 
644 DEAL_II_NAMESPACE_CLOSE
645 
646 #endif
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 void declare_all_parameters(ParameterHandler &prm=ParameterAcceptor::prm)
virtual void parse_parameters(ParameterHandler &prm)
void add_parameter(const std::string &entry, ParameterType &parameter, const std::string &documentation=std::string(), ParameterHandler &prm_=prm, const Patterns::PatternBase &pattern= *Patterns::Tools::Convert< ParameterType >::to_pattern())
ParameterAcceptorProxy(const std::string section_name, Args... args)
ParameterAcceptor(const std::string &section_name="")
virtual void declare_parameters(ParameterHandler &prm)
virtual void parse_parameters(ParameterHandler &prm)
boost::signals2::signal< void()> declare_parameters_call_back
static std::vector< SmartPointer< ParameterAcceptor > > class_list
std::string get_section_name() const
static const char sep
std::vector< std::string > get_section_path() const
virtual void declare_parameters(ParameterHandler &prm)
void add_parameter(const std::string &entry, ParameterType &parameter, const std::string &documentation=std::string(), const Patterns::PatternBase &pattern= *Patterns::Tools::Convert< ParameterType >::to_pattern())
static ParameterHandler prm
static void parse_all_parameters(ParameterHandler &prm=ParameterAcceptor::prm)
const std::string section_name
void leave_my_subsection(ParameterHandler &prm)
boost::signals2::signal< void()> parse_parameters_call_back