Bayeux  3.4.1
Core Foundation library for SuperNEMO
i_unary_function_with_parameters.h
Go to the documentation of this file.
1 //
4 // Copyright (c) 2015 by François Mauger <mauger@lpccaen.in2p3.fr>
5 //
6 // This file is part of Bayeux.
7 //
8 // Bayeux is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // Bayeux is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with Bayeux. If not, see <http://www.gnu.org/licenses/>.
20 
21 #ifndef MYGSL_I_UNARY_FUNCTION_WITH_PARAMETERS_H
22 #define MYGSL_I_UNARY_FUNCTION_WITH_PARAMETERS_H
23 
24 // Standard library:
25 #include <string>
26 #include <map>
27 
28 // Third party:
29 // - Bayeux/datatools:
30 #include <datatools/types.h>
31 
32 // This project:
33 #include <mygsl/i_unary_function.h>
34 #include <mygsl/parameter_store.h>
35 
36 namespace mygsl {
37 
41  {
42  public:
43 
46 
49 
52 
54  virtual bool is_initialized() const;
55 
57  virtual void initialize(const datatools::properties & config_,
58  const unary_function_dict_type & functors_);
59 
61  virtual void reset();
62 
64  bool has_parameter_store() const;
65 
67  void set_parameter_store(const parameter_store & store_);
68 
70  void reset_parameter_store();
71 
73  void register_requested_parameter(const std::string & parameter_name_,
74  datatools::basic_type parameter_type_);
75 
77  int get_parameter_index(const std::string & parameter_name_) const;
78 
80  bool is_parameter_set(int param_index_) const;
81 
83  void fetch_parameter(int param_index_, bool & value_) const;
84 
86  void fetch_parameter(int param_index_, int & value_) const;
87 
89  void fetch_parameter(int param_index_, double & value_) const;
90 
92  void fetch_parameter(int param_index_, std::string & value_) const;
93 
95  virtual void tree_dump(std::ostream & out_ = std::clog,
96  const std::string & title_ = "",
97  const std::string & indent_ = "",
98  bool inherit_ = false) const;
99 
101  void update_parameters();
102 
103  protected:
104 
106  double _eval(double x_) const;
107 
109  virtual double _eval_from_parameters(double x_) const = 0;
110 
112  virtual void _at_parameters_change() = 0;
113 
114  private:
115 
116  const parameter_store * _params_ = nullptr;
117  std::map<std::string, datatools::basic_type> _requested_parameters_;
118 
119  };
120 
121 } // end of namespace mygsl
122 
123 #endif // MYGSL_I_UNARY_FUNCTION_WITH_PARAMETERS_H
124 
125 // Local Variables: --
126 // mode: c++ --
127 // c-file-style: "gnu" --
128 // tab-width: 2 --
129 // End: --
void register_requested_parameter(const std::string &parameter_name_, datatools::basic_type parameter_type_)
Register requested parameter.
bool has_parameter_store() const
Check if an external parameter store is set.
virtual void initialize(const datatools::properties &config_, const unary_function_dict_type &functors_)
Initialization from a container of parameters and a dictionary of functors.
A store for parameters.
virtual ~i_unary_function_with_parameters()
Destructor.
virtual double _eval_from_parameters(double x_) const =0
Evaluation from parameters of the store.
double _eval(double x_) const
Evaluation.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart printing.
Subscriber.
Definition: parameter_store.h:137
basic_type
Basic type identifier.
Definition: types.h:28
void fetch_parameter(int param_index_, bool &value_) const
Fetch a boolean parameter at given index.
int get_parameter_index(const std::string &parameter_name_) const
Return the registration index of a parameter given its name.
void set_parameter_store(const parameter_store &store_)
Set an external parameter store.
virtual void reset()
Reset the functor.
Abstract interface for unary functions : R -> R.
Definition: i_unary_function.h:44
Abstract interface for unary functions with derivative.
Definition: i_unary_function_with_parameters.h:39
virtual void _at_parameters_change()=0
Action to perform when some parameters of the store have changed.
Top-level namespace of the Bayeux/mygsl module library.
Definition: base_decay_driver.h:47
std::map< std::string, unary_function_handle_type > unary_function_dict_type
Alias for dictionary of handles to unary function objects.
Definition: unary_function_utils.h:30
virtual bool is_initialized() const
Check initialization status.
i_unary_function_with_parameters()
Default constructor.
void reset_parameter_store()
Reset an external parameter store.
void update_parameters()
Update parameter.
Store of parameters.
Definition: parameter_store.h:40
bool is_parameter_set(int param_index_) const
Check if a parameter at given index is set.
A dictionary of arbitrary properties.
Definition: properties.h:125