BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ParameterPool.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Param/Base/ParameterPool.h
6 //! @brief Defines class ParameterPool.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
15 #ifndef BORNAGAIN_CORE_PARAMETRIZATION_PARAMETERPOOL_H
16 #define BORNAGAIN_CORE_PARAMETRIZATION_PARAMETERPOOL_H
17 
18 #include "Base/Types/ICloneable.h"
19 #include <ostream>
20 #include <string>
21 #include <vector>
22 
23 class RealLimits;
24 class RealParameter;
25 
26 //! Container with parameters for IParameterized object.
27 //! @ingroup tools_internal
28 
29 class ParameterPool : public ICloneable
30 {
31 public:
33  virtual ~ParameterPool();
34 
35  ParameterPool* clone() const;
36 
37  void copyToExternalPool(const std::string& prefix, ParameterPool* other_pool) const;
38 
39  void clear();
40 
41  //! Returns number of parameters in the pool.
42  size_t size() const { return m_params.size(); }
43  bool empty() const { return size() == 0; }
44 
46 
47  RealParameter* parameter(const std::string& name);
48 
49  const RealParameter* parameter(const std::string& name) const;
50 
51  //! Returns full vector of parameters.
52  const std::vector<RealParameter*> parameters() const { return m_params; }
53 
54  std::vector<RealParameter*> getMatchedParameters(const std::string& pattern) const;
55  RealParameter* getUniqueMatch(const std::string& pattern) const;
56 
57  void setParameterValue(const std::string& name, double value);
58 
59  int setMatchedParametersValue(const std::string& wildcards, double value);
60  void setUniqueMatchValue(const std::string& pattern, double value);
61 
62  std::vector<std::string> parameterNames() const;
63 
64  friend std::ostream& operator<<(std::ostream& ostr, const ParameterPool& obj)
65  {
66  obj.print(ostr);
67  return ostr;
68  }
69 
70  void removeParameter(const std::string& name);
71 
72  const RealParameter* operator[](size_t index) const;
73  RealParameter* operator[](size_t index);
74 
75 private:
76  virtual void print(std::ostream& ostr) const;
77 #ifndef SWIG
78  [[noreturn]] void report_find_matched_parameters_error(const std::string& pattern) const;
79  [[noreturn]] void report_set_value_error(const std::string& parname, double value,
80  std::string message = {}) const;
81 #endif
82  size_t check_index(size_t index) const;
83 
84  std::vector<RealParameter*> m_params;
85 };
86 
87 #endif // BORNAGAIN_CORE_PARAMETRIZATION_PARAMETERPOOL_H
Defines and implements the standard mix-in ICloneable.
Interface for polymorphic classes that should not be copied, except by explicit cloning.
Definition: ICloneable.h:25
Container with parameters for IParameterized object.
Definition: ParameterPool.h:30
std::vector< RealParameter * > m_params
Definition: ParameterPool.h:84
virtual void print(std::ostream &ostr) const
RealParameter * parameter(const std::string &name)
Returns parameter with given name.
virtual ~ParameterPool()
void report_set_value_error(const std::string &parname, double value, std::string message={}) const
Reports error while setting parname to given value.
void report_find_matched_parameters_error(const std::string &pattern) const
reports error while finding parameters matching given name.
const std::vector< RealParameter * > parameters() const
Returns full vector of parameters.
Definition: ParameterPool.h:52
RealParameter & addParameter(RealParameter *newPar)
Adds parameter to the pool, and returns reference to the input pointer.
void setUniqueMatchValue(const std::string &pattern, double value)
Sets value of the one parameter that matches pattern ('*' allowed), or throws.
void copyToExternalPool(const std::string &prefix, ParameterPool *other_pool) const
Copies parameters of given pool to other pool, prepeding prefix to the parameter names.
void clear()
Clears the parameter map.
std::vector< std::string > parameterNames() const
ParameterPool * clone() const
Returns a literal clone.
bool empty() const
Definition: ParameterPool.h:43
int setMatchedParametersValue(const std::string &wildcards, double value)
Sets value of the nonzero parameters that match pattern ('*' allowed), or throws.
size_t size() const
Returns number of parameters in the pool.
Definition: ParameterPool.h:42
const RealParameter * operator[](size_t index) const
ParameterPool()
Constructs an empty parameter pool.
void setParameterValue(const std::string &name, double value)
Sets parameter value.
void removeParameter(const std::string &name)
Removes parameter with given name from the pool.
std::vector< RealParameter * > getMatchedParameters(const std::string &pattern) const
Returns nonempty vector of parameters that match the pattern ('*' allowed), or throws.
size_t check_index(size_t index) const
RealParameter * getUniqueMatch(const std::string &pattern) const
Returns the one parameter that matches the pattern (wildcards '*' allowed), or throws.
friend std::ostream & operator<<(std::ostream &ostr, const ParameterPool &obj)
Definition: ParameterPool.h:64
Limits for a real fit parameter.
Definition: RealLimits.h:25
Wraps a parameter of type double.
Definition: RealParameter.h:32