BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Attributes.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Fit/Tools/Attributes.h
6 //! @brief Defines and implements class Attributes.
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_FIT_TOOLS_ATTRIBUTES_H
16 #define BORNAGAIN_FIT_TOOLS_ATTRIBUTES_H
17 
18 #include <ostream>
19 
20 //! Attributes for a fit parameter. Currently, the only attribute is fixed/free.
21 //! @ingroup fitting
22 
24 {
25 public:
26  Attributes() : m_is_fixed(false) {}
27  //! Creates a fixed value object
28  static Attributes fixed() { return Attributes(true); }
29  static Attributes free() { return Attributes(false); }
30 
31  void setFixed(bool is_fixed) { m_is_fixed = is_fixed; }
32  bool isFixed() const { return m_is_fixed; }
33  bool isFree() const { return !isFixed(); }
34 
35  friend std::ostream& operator<<(std::ostream& ostr, const Attributes& m)
36  {
37  m.print(ostr);
38  return ostr;
39  }
40 
41  bool operator==(const Attributes& other) const { return isFixed() == other.isFixed(); }
42  bool operator!=(const Attributes& other) const { return !(*this == other); }
43 
44 protected:
45  Attributes(bool is_fixed) : m_is_fixed(is_fixed) {}
46 
47  bool m_is_fixed; //! parameter is fixed
48 
49  void print(std::ostream& ostr) const;
50 };
51 
52 //! Prints class
53 inline void Attributes::print(std::ostream& ostr) const
54 {
55  if (isFixed())
56  ostr << "fixed";
57  else
58  ostr << "free";
59 }
60 
61 #endif // BORNAGAIN_FIT_TOOLS_ATTRIBUTES_H
Attributes for a fit parameter.
Definition: Attributes.h:24
Attributes(bool is_fixed)
Definition: Attributes.h:45
bool m_is_fixed
Definition: Attributes.h:47
void print(std::ostream &ostr) const
parameter is fixed
Definition: Attributes.h:53
static Attributes fixed()
Creates a fixed value object.
Definition: Attributes.h:28
bool operator!=(const Attributes &other) const
Definition: Attributes.h:42
bool operator==(const Attributes &other) const
Definition: Attributes.h:41
bool isFree() const
Definition: Attributes.h:33
static Attributes free()
Definition: Attributes.h:29
bool isFixed() const
Definition: Attributes.h:32
friend std::ostream & operator<<(std::ostream &ostr, const Attributes &m)
Definition: Attributes.h:35
void setFixed(bool is_fixed)
Definition: Attributes.h:31