BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::JsonUtils Namespace Reference

Functions

MVVM_MODEL_EXPORT RealLimits CreateLimits (const std::string &text, double min=0.0, double max=0.0)
 
MVVM_MODEL_EXPORT std::string ModelToJsonString (const SessionModel &model)
 Returns multiline string representing model content as json. More...
 
MVVM_MODEL_EXPORT std::string ToString (const RealLimits &limits)
 Returns string representation of RealLimits. More...
 

Function Documentation

◆ CreateLimits()

RealLimits ModelView::JsonUtils::CreateLimits ( const std::string &  text,
double  min = 0.0,
double  max = 0.0 
)

Definition at line 60 of file jsonutils.cpp.

61 {
62  if (text == text_limitless)
63  return RealLimits();
64  else if (text == text_positive)
65  return RealLimits::positive();
66  else if (text == text_nonnegative)
67  return RealLimits::nonnegative();
68  else if (text == text_lowerlimited)
69  return RealLimits::lowerLimited(min);
70  else if (text == text_upperlimited)
71  return RealLimits::upperLimited(max);
72  else if (text == text_limited)
73  return RealLimits::limited(min, max);
74  else
75  throw std::runtime_error("JsonUtils::CreateLimits -> Unknown type");
76 }
Limits for double.
Definition: reallimits.h:25
static RealLimits upperLimited(double bound_value)
Creates an object bounded from the right.
Definition: RealLimits.cpp:120
static RealLimits lowerLimited(double bound_value)
Creates an object bounded from the left.
Definition: RealLimits.cpp:105
static RealLimits positive()
Creates an object which can have only positive values (>0., zero is not included)
Definition: RealLimits.cpp:110
static RealLimits nonnegative()
Creates an object which can have only positive values with 0. included.
Definition: RealLimits.cpp:115
static RealLimits limited(double left_bound_value, double right_bound_value)
Creates an object bounded from the left and right.
Definition: RealLimits.cpp:125

References ModelView::RealLimits::limited(), ModelView::RealLimits::lowerLimited(), ModelView::RealLimits::nonnegative(), ModelView::RealLimits::positive(), and ModelView::RealLimits::upperLimited().

Referenced by TEST_F().

Here is the call graph for this function:

◆ ModelToJsonString()

std::string ModelView::JsonUtils::ModelToJsonString ( const SessionModel model)

Returns multiline string representing model content as json.

Definition at line 34 of file jsonutils.cpp.

35 {
36  auto converter = CreateModelCopyConverter();
37  QJsonObject json_source = converter->to_json(model);
38  QJsonDocument document(json_source);
39  return QString(document.toJson(QJsonDocument::Indented)).toStdString();
40 }
MVVM_MODEL_EXPORT std::unique_ptr< JsonModelConverterInterface > CreateModelCopyConverter()
Creates a JSON model converter intended for model copying.

References ModelView::CreateModelCopyConverter().

Referenced by TestUtils::ModelToJsonString().

Here is the call graph for this function:

◆ ToString()

std::string ModelView::JsonUtils::ToString ( const RealLimits limits)

Returns string representation of RealLimits.

Definition at line 42 of file jsonutils.cpp.

43 {
44  if (limits.isLimitless())
45  return text_limitless;
46  else if (limits.isPositive())
47  return text_positive;
48  else if (limits.isNonnegative())
49  return text_nonnegative;
50  else if (limits.isLowerLimited())
51  return text_lowerlimited;
52  else if (limits.isUpperLimited())
53  return text_upperlimited;
54  else if (limits.isLimited())
55  return text_limited;
56  else
57  throw std::runtime_error("JsonUtils::ToString() -> Unknown type");
58 }
bool isLimited() const
Definition: reallimits.cpp:151
bool isLowerLimited() const
Definition: reallimits.cpp:141
bool isPositive() const
Definition: reallimits.cpp:130
bool isNonnegative() const
Definition: reallimits.cpp:136
bool isLimitless() const
Definition: reallimits.cpp:125
bool isUpperLimited() const
Definition: reallimits.cpp:146

References ModelView::RealLimits::isLimited(), ModelView::RealLimits::isLimitless(), ModelView::RealLimits::isLowerLimited(), ModelView::RealLimits::isNonnegative(), ModelView::RealLimits::isPositive(), and ModelView::RealLimits::isUpperLimited().

Referenced by TEST_F().

Here is the call graph for this function: