BornAgain  1.19.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 reflection and scattering
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_PARAM_BASE_PARAMETERPOOL_H
16 #define BORNAGAIN_PARAM_BASE_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 IParametricComponent object.
27 //! @ingroup tools_internal
28 
29 class ParameterPool : public ICloneable {
30 public:
32  virtual ~ParameterPool();
33 
34  ParameterPool* clone() const;
35 
36  void copyToExternalPool(const std::string& prefix, ParameterPool* other_pool) const;
37 
38  void clear();
39 
40  //! Returns number of parameters in the pool.
41  size_t size() const { return m_params.size(); }
42  bool empty() const { return size() == 0; }
43 
45 
46  RealParameter* parameter(const std::string& name);
47 
48  const RealParameter* parameter(const std::string& name) const;
49 
50  //! Returns full vector of parameters.
51  const std::vector<RealParameter*> parameters() const { return m_params; }
52 
53  std::vector<RealParameter*> getMatchedParameters(const std::string& pattern) const;
54  RealParameter* getUniqueMatch(const std::string& pattern) const;
55 
56  void setParameterValue(const std::string& name, double value);
57 
58  int setMatchedParametersValue(const std::string& wildcards, double value);
59  void setUniqueMatchValue(const std::string& pattern, double value);
60 
61  std::vector<std::string> parameterNames() const;
62 
63  friend std::ostream& operator<<(std::ostream& ostr, const ParameterPool& obj)
64  {
65  obj.print(ostr);
66  return ostr;
67  }
68 
69  void removeParameter(const std::string& name);
70 
71  RealParameter* operator[](size_t index); // used by libBornAgainParam.i
72  const RealParameter* operator[](size_t index) const; // needed by the above
73 
74 private:
75  virtual void print(std::ostream& ostr) const;
76 #ifndef SWIG
77  [[noreturn]] void report_find_matched_parameters_error(const std::string& pattern) const;
78  [[noreturn]] void report_set_value_error(const std::string& parname, double value,
79  std::string message = {}) const;
80 #endif
81  size_t check_index(size_t index) const;
82 
83  std::vector<RealParameter*> m_params;
84 };
85 
86 #endif // BORNAGAIN_PARAM_BASE_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 IParametricComponent object.
Definition: ParameterPool.h:29
std::vector< RealParameter * > m_params
Definition: ParameterPool.h:83
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:51
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:42
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:41
RealParameter * operator[](size_t index)
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:63
Limits for a real fit parameter.
Definition: RealLimits.h:24
Wraps a parameter of type double.
Definition: RealParameter.h:31
QString const & name(EShape k)
Definition: particles.cpp:21