BornAgain  1.19.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 reflection and scattering
4 //
5 //! @file Fit/Param/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 // Swig: not %include'd, but #include'd
16 
17 #ifndef USER_API
18 #ifndef BORNAGAIN_FIT_PARAM_ATTRIBUTES_H
19 #define BORNAGAIN_FIT_PARAM_ATTRIBUTES_H
20 
21 #include <ostream>
22 
23 //! %Attributes for a fit parameter. Currently, the only attribute is fixed/free.
24 //! @ingroup fitting
25 
26 class Attributes {
27 public:
28  Attributes() : m_is_fixed(false) {}
29  //! Creates a fixed value object
30  static Attributes fixed() { return Attributes(true); }
31  static Attributes free() { return Attributes(false); }
32 
33  void setFixed(bool is_fixed) { m_is_fixed = is_fixed; }
34  bool isFixed() const { return m_is_fixed; }
35  bool isFree() const { return !isFixed(); }
36 
37  friend std::ostream& operator<<(std::ostream& ostr, const Attributes& m)
38  {
39  m.print(ostr);
40  return ostr;
41  }
42 
43  bool operator==(const Attributes& other) const { return isFixed() == other.isFixed(); }
44  bool operator!=(const Attributes& other) const { return !(*this == other); }
45 
46 protected:
47  Attributes(bool is_fixed) : m_is_fixed(is_fixed) {}
48 
49  bool m_is_fixed; //! parameter is fixed
50 
51  void print(std::ostream& ostr) const;
52 };
53 
54 //! Prints class
55 inline void Attributes::print(std::ostream& ostr) const
56 {
57  if (isFixed())
58  ostr << "fixed";
59  else
60  ostr << "free";
61 }
62 
63 #endif // BORNAGAIN_FIT_PARAM_ATTRIBUTES_H
64 #endif // USER_API
Attributes for a fit parameter.
Definition: Attributes.h:26
Attributes(bool is_fixed)
Definition: Attributes.h:47
bool m_is_fixed
Definition: Attributes.h:49
void print(std::ostream &ostr) const
parameter is fixed
Definition: Attributes.h:55
static Attributes fixed()
Creates a fixed value object.
Definition: Attributes.h:30
bool operator!=(const Attributes &other) const
Definition: Attributes.h:44
bool operator==(const Attributes &other) const
Definition: Attributes.h:43
bool isFree() const
Definition: Attributes.h:35
static Attributes free()
Definition: Attributes.h:31
bool isFixed() const
Definition: Attributes.h:34
friend std::ostream & operator<<(std::ostream &ostr, const Attributes &m)
Definition: Attributes.h:37
void setFixed(bool is_fixed)
Definition: Attributes.h:33