BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
PyFmtLimits.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Core/Export/PyFmtLimits.cpp
6 //! @brief Implements functions from namespace pyfmt.
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 
16 #include "Core/Export/PyFmt.h"
17 #include "Fit/Param/RealLimits.h"
18 #include <iomanip>
19 
20 namespace pyfmt {
21 
22 std::string printRealLimits(const RealLimits& limits, const std::string& units)
23 {
24  std::ostringstream result;
25 
26  if (limits.isLimitless()) {
27  result << "RealLimits()";
28  }
29 
30  else if (limits.isPositive()) {
31  result << "RealLimits.positive()";
32  }
33 
34  else if (limits.isNonnegative()) {
35  result << "RealLimits.nonnegative()";
36  }
37 
38  else if (limits.isLowerLimited()) {
39  result << "RealLimits.lowerLimited(" << pyfmt::printValue(limits.lowerLimit(), units)
40  << ")";
41  }
42 
43  else if (limits.isUpperLimited()) {
44  result << "RealLimits.upperLimited(" << pyfmt::printValue(limits.upperLimit(), units)
45  << ")";
46  }
47 
48  else if (limits.isLimited()) {
49  result << "RealLimits.limited(" << pyfmt::printValue(limits.lowerLimit(), units) << ", "
50  << pyfmt::printValue(limits.upperLimit(), units) << ")";
51  }
52 
53  return result.str();
54 }
55 
56 //! Prints RealLimits in the form of argument (in the context of ParameterDistribution and
57 //! similar). Default RealLimits will not be printed, any other will be printed as
58 //! ", ba.RealLimits.limited(1*deg, 2*deg)"
59 
60 std::string printRealLimitsArg(const RealLimits& limits, const std::string& units)
61 {
62  return limits.isLimitless() ? "" : ", ba." + printRealLimits(limits, units);
63 }
64 
65 } // namespace pyfmt
Defines functions in namespace pyfmt.
Defines functions in namespace pyfmt.
Defines class RealLimits.
Limits for a real fit parameter.
Definition: RealLimits.h:24
bool isLimited() const
Definition: RealLimits.cpp:199
bool isLowerLimited() const
Definition: RealLimits.cpp:189
bool isPositive() const
Definition: RealLimits.cpp:178
double upperLimit() const
Returns upper limit.
Definition: RealLimits.cpp:62
double lowerLimit() const
Returns lower limit.
Definition: RealLimits.cpp:40
bool isNonnegative() const
Definition: RealLimits.cpp:184
bool isLimitless() const
Definition: RealLimits.cpp:173
bool isUpperLimited() const
Definition: RealLimits.cpp:194
Utility functions for writing Python code snippets.
Definition: PyFmt.cpp:22
std::string printRealLimits(const RealLimits &limits, const std::string &units)
Definition: PyFmtLimits.cpp:22
std::string printRealLimitsArg(const RealLimits &limits, const std::string &units)
Prints RealLimits in the form of argument (in the context of ParameterDistribution and similar).
Definition: PyFmtLimits.cpp:60
std::string printValue(double value, const std::string &units)
Definition: PyFmt.cpp:118