![]() |
Reference documentation for deal.II version 9.6.0
|
#include <deal.II/base/parameter_acceptor.h>
Public Member Functions | |
template<typename... Args> | |
ParameterAcceptorProxy (const std::string §ion_name, Args... args) | |
virtual void | declare_parameters (ParameterHandler &prm) override |
virtual void | parse_parameters (ParameterHandler &prm) override |
unsigned int | get_acceptor_id () const |
std::string | get_section_name () const |
std::vector< std::string > | get_section_path () const |
template<typename ParameterType > | |
void | add_parameter (const std::string &entry, ParameterType ¶meter, const std::string &documentation="", ParameterHandler &prm_=prm, const Patterns::PatternBase &pattern= *Patterns::Tools::Convert< ParameterType >::to_pattern()) |
void | enter_subsection (const std::string &subsection) |
void | leave_subsection () |
void | enter_my_subsection (ParameterHandler &prm) |
void | leave_my_subsection (ParameterHandler &prm) |
template<class Archive > | |
void | serialize (Archive &ar, const unsigned int version) |
Subscriptor functionality | |
Classes derived from Subscriptor provide a facility to subscribe to this object. This is mostly used by the SmartPointer class. | |
void | subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
void | unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
unsigned int | n_subscriptions () const |
template<typename StreamType > | |
void | list_subscribers (StreamType &stream) const |
void | list_subscribers () const |
Static Public Member Functions | |
static void | initialize (const std::string &filename="", const std::string &output_filename="", const ParameterHandler::OutputStyle output_style_for_output_filename=ParameterHandler::Short, ParameterHandler &prm=ParameterAcceptor::prm, const ParameterHandler::OutputStyle output_style_for_filename=ParameterHandler::DefaultStyle) |
static void | initialize (std::istream &input_stream, ParameterHandler &prm=ParameterAcceptor::prm) |
static void | clear () |
static void | parse_all_parameters (ParameterHandler &prm=ParameterAcceptor::prm) |
static void | declare_all_parameters (ParameterHandler &prm=ParameterAcceptor::prm) |
static ::ExceptionBase & | ExcInUse (int arg1, std::string arg2, std::string arg3) |
static ::ExceptionBase & | ExcNoSubscriber (std::string arg1, std::string arg2) |
Public Attributes | |
boost::signals2::signal< void()> | declare_parameters_call_back |
boost::signals2::signal< void()> | parse_parameters_call_back |
Static Public Attributes | |
static ParameterHandler | prm |
Protected Attributes | |
const std::string | section_name |
std::vector< std::string > | subsections |
Private Types | |
using | map_value_type = decltype(counter_map)::value_type |
using | map_iterator = decltype(counter_map)::iterator |
Private Member Functions | |
void | check_no_subscribers () const noexcept |
Static Private Member Functions | |
static unsigned int | get_next_free_id () |
Private Attributes | |
const unsigned int | acceptor_id |
std::atomic< unsigned int > | counter |
std::map< std::string, unsigned int > | counter_map |
std::vector< std::atomic< bool > * > | validity_pointers |
const std::type_info * | object_info |
Static Private Attributes | |
static std::mutex | class_list_mutex |
static std::set< ParameterAcceptor *, internal::ParameterAcceptorCompare > | class_list |
static const char | sep = '/' |
static std::mutex | mutex |
A proxy ParameterAcceptor wrapper for classes that have a static member function declare_parameters
, and a non virtual parse_parameters
method.
If you cannot or do not want to derive your "parameter accepting" class from ParameterAcceptor, for example if by design you are required to have a static member function declare_parameters
and a member parse_parameters
, or if someone has already implemented such a class for you, and only provides you with an API that you cannot modify, then you may be able to use ParameterAcceptor facilities nonetheless, by wrapping your class into ParameterAcceptorProxy.
This class implements the public interface of ParameterAcceptor, and at the same time it derives from the template class SourceClass
, allowing you to register your existing SourceClass
as a ParameterAcceptor class, without requiring you to explicitly derive your SourceClass
from ParameterAcceptor.
An example usage is given by the following snippet of code, using Functions::ParsedFunction as an example source class:
The above snippet of code will initialize ParameterAcceptor::prm with a section "Some function", and will correctly parse and assign to the object fun
the expression parsed from the file test.prm
. If non-existent, the program will exit, and generate it for you (here you can see the resulting short text version of the parameter file generated with the above snippet):
The resulting fun
object, is both a ParsedFunction object and a ParameterAcceptor one, allowing you to use it as a replacement of the ParsedFunction class, with automatic declaration and parsing of parameter files.
See the tutorial program step-60 for an example on how to use this class.
Definition at line 696 of file parameter_acceptor.h.
|
privateinherited |
The data type used in counter_map.
Definition at line 229 of file subscriptor.h.
|
privateinherited |
The iterator type used in counter_map.
Definition at line 234 of file subscriptor.h.
ParameterAcceptorProxy< SourceClass >::ParameterAcceptorProxy | ( | const std::string & | section_name, |
Args... | args ) |
Default constructor. The argument section_name
is forwarded to the constructor of the ParameterAcceptor class, while all other arguments are passed to the SourceClass constructor.
Definition at line 742 of file parameter_acceptor.h.
|
overridevirtual |
Overloads the ParameterAcceptor::declare_parameters function, by calling SourceClass::declare_parameters
with prm
as an argument.
Reimplemented from ParameterAcceptor.
Definition at line 753 of file parameter_acceptor.h.
|
overridevirtual |
Overloads the ParameterAcceptor::parse_parameters function, by calling SourceClass::parse_parameters
with prm
as an argument.
Reimplemented from ParameterAcceptor.
Definition at line 762 of file parameter_acceptor.h.
|
inlineinherited |
Get the acceptor id of this object.
Definition at line 275 of file parameter_acceptor.cc.
|
staticinherited |
Call declare_all_parameters(), read the parameters from filename
(only if filename
is a non-empty string), and then call parse_all_parameters().
If the parameter filename
is the empty string, then no attempt to read a parameter file is done. This may be useful if you are ok with using default values, and don't want to read external files to use a class derived from ParameterAcceptor.
If output_filename
is not the empty string, then we write the content that was read into the output_filename
file, using the style specified in output_style_for_output_filename
. The format of both input and output files are selected using the extensions of the files themselves. This can be either prm
, xml
, or json
for the filename
, and any of the supported formats for the output_filename
.
If the input file does not exist, a default one with the same name is created for you following the style specified in output_style_for_filename
, and an exception is thrown.
By default, the file format used to write the files is deduced from the extension of the file names. If the corresponding ParameterHandler::OutputStyle specifies a format specification, this must be compatible with the file extension, or an exception will be thrown.
If the extension is not recognized, and you do not specify a format in the corresponding ParameterHandler::OutputStyle, an assertion is thrown.
filename | Input file name |
output_filename | Output file name |
output_style_for_output_filename | How to write the output file |
prm | The ParameterHandler to use |
output_style_for_filename | How to write the default input file if it does not exist |
Definition at line 80 of file parameter_acceptor.cc.
|
staticinherited |
Call declare_all_parameters(), read the parameters from the input_stream
in prm
format, and then call parse_all_parameters().
An exception is thrown if the input_stream
is invalid.
input_stream | Input stream |
prm | The ParameterHandler to use |
Definition at line 114 of file parameter_acceptor.cc.
|
staticinherited |
Clear class list and global parameter file.
Definition at line 126 of file parameter_acceptor.cc.
|
staticinherited |
Parse the given ParameterHandler. This function enters the subsection returned by get_section_name() for each derived class, and parses all parameters that were added using add_parameter().
Definition at line 148 of file parameter_acceptor.cc.
|
staticinherited |
Initialize the global ParameterHandler with all derived classes parameters.This function enters the subsection returned by get_section_name() for each derived class, and declares all parameters that were added using add_parameter().
Definition at line 162 of file parameter_acceptor.cc.
|
inherited |
Return the section name of this class. If a name was provided at construction time, then that name is returned, otherwise it returns the demangled name of this class.
Definition at line 71 of file parameter_acceptor.cc.
|
inherited |
Traverse all registered classes, and figure out what subsections we need to enter.
Definition at line 176 of file parameter_acceptor.cc.
|
inherited |
Add a parameter in the correct path. This method forwards all arguments to the prm.add_parameter() method, after entering the correct section path. By default it uses the ParameterAcceptor::prm variable as ParameterHandler.
See the documentation of ParameterHandler::add_parameter() for more information.
Definition at line 727 of file parameter_acceptor.h.
|
inherited |
Add the given subsection
to the global path stored in this class.
This function changes the behavior of enter_my_subsection(), by appending a new subsection to the path stored in this class.
This method can be used to split the parameters of this class into subsections, while still maintaining the general behavior of this class.
An example usage is given by the following snippet:
which will produce a parameter file organized as
Definition at line 224 of file parameter_acceptor.cc.
|
inherited |
Leave the subsection that was entered by calling the enter_subsection() function.
Definition at line 239 of file parameter_acceptor.cc.
|
inherited |
Make sure we enter the right subsection of the given parameter.
Definition at line 249 of file parameter_acceptor.cc.
|
inherited |
This function undoes what the enter_my_subsection() function did. It only makes sense if enter_my_subsection() was called on prm
before this one.
Definition at line 262 of file parameter_acceptor.cc.
|
staticprivateinherited |
Get the next free id for this class.
Definition at line 283 of file parameter_acceptor.cc.
|
inherited |
Subscribes a user of the object by storing the pointer validity
. The subscriber may be identified by text supplied as identifier
.
Definition at line 135 of file subscriptor.cc.
|
inherited |
Unsubscribes a user from the object.
identifier
and the validity
pointer must be the same as the one supplied to subscribe(). Definition at line 155 of file subscriptor.cc.
|
inlineinherited |
Return the present number of subscriptions to this object. This allows to use this class for reference counted lifetime determination where the last one to unsubscribe also deletes the object.
Definition at line 300 of file subscriptor.h.
|
inlineinherited |
List the subscribers to the input stream
.
Definition at line 317 of file subscriptor.h.
|
inherited |
List the subscribers to deallog
.
Definition at line 203 of file subscriptor.cc.
|
inlineinherited |
Read or write the data of this object to or from a stream for the purpose of serialization using the BOOST serialization library.
This function does not actually serialize any of the member variables of this class. The reason is that what this class stores is only who subscribes to this object, but who does so at the time of storing the contents of this object does not necessarily have anything to do with who subscribes to the object when it is restored. Consequently, we do not want to overwrite the subscribers at the time of restoring, and then there is no reason to write the subscribers out in the first place.
Definition at line 309 of file subscriptor.h.
|
privatenoexceptinherited |
Check that there are no objects subscribing to this object. If this check passes then it is safe to destroy the current object. It this check fails then this function will either abort or print an error message to deallog (by using the AssertNothrow mechanism), but will not throw an exception.
Definition at line 52 of file subscriptor.cc.
|
inherited |
Declare parameter call back. This signal is triggered right after declare_parameters() has been called, to allow users to prepare their variables right after parameters have been declared. The default implementation is empty.
Definition at line 459 of file parameter_acceptor.h.
|
inherited |
Parse parameter call back. This function is called at the end of parse_parameters(), to allow users to process their parameters right after they have been parsed. The default implementation is empty.
You can use this function, for example, to create a quadrature rule after you have read how many quadrature points you wanted to use from the parameter file.
Definition at line 478 of file parameter_acceptor.h.
|
staticinherited |
The global parameter handler.
Definition at line 533 of file parameter_acceptor.h.
|
staticprivateinherited |
A mutex to prevent writing on the class_list set from multiple threads.
Definition at line 619 of file parameter_acceptor.h.
|
staticprivateinherited |
A set containing the address of all constructed classes of type ParameterAcceptor.
Definition at line 626 of file parameter_acceptor.h.
|
privateinherited |
The id of this specific class instance.
Definition at line 629 of file parameter_acceptor.h.
|
staticprivateinherited |
Separator between sections.
Definition at line 634 of file parameter_acceptor.h.
|
protectedinherited |
The subsection name for this class.
Definition at line 638 of file parameter_acceptor.h.
|
protectedinherited |
The subsubsections that are currently active.
Definition at line 641 of file parameter_acceptor.h.
|
mutableprivateinherited |
Store the number of objects which subscribed to this object. Initially, this number is zero, and upon destruction it shall be zero again (i.e. all objects which subscribed should have unsubscribed again).
The creator (and owner) of an object is counted in the map below if HE manages to supply identification.
We use the mutable
keyword in order to allow subscription to constant objects also.
This counter may be read from and written to concurrently in multithreaded code: hence we use the std::atomic
class template.
Definition at line 218 of file subscriptor.h.
|
mutableprivateinherited |
In this map, we count subscriptions for each different identification string supplied to subscribe().
Definition at line 224 of file subscriptor.h.
|
mutableprivateinherited |
In this vector, we store pointers to the validity bool in the SmartPointer objects that subscribe to this class.
Definition at line 240 of file subscriptor.h.
|
mutableprivateinherited |
Pointer to the typeinfo object of this object, from which we can later deduce the class name. Since this information on the derived class is neither available in the destructor, nor in the constructor, we obtain it in between and store it here.
Definition at line 248 of file subscriptor.h.
|
staticprivateinherited |
A mutex used to ensure data consistency when accessing the mutable
members of this class. This lock is used in the subscribe() and unsubscribe() functions, as well as in list_subscribers()
.
Definition at line 271 of file subscriptor.h.