11#include <boost/algorithm/string.hpp>
12#include <boost/lexical_cast.hpp>
19 QString functionIndex;
20 QString parameterName = paramName;
21 int j = paramName.lastIndexOf(
'.');
24 functionIndex = paramName.mid(0, j);
25 parameterName = paramName.mid(j);
27 return std::make_pair(functionIndex, parameterName);
31 if (prefix.isEmpty() || !fun) {
34 auto compFun = std::dynamic_pointer_cast<CompositeFunction>(fun);
36 throw std::runtime_error(
"Function " + fun->name() +
" is not composite");
38 auto j = prefix.indexOf(
'.');
40 throw std::runtime_error(
"Error in fit function prefix: " + prefix.toStdString() +
"\nIt must end with a dot (.)");
42 if (j < 2 || prefix[0] !=
'f') {
43 throw std::runtime_error(
"Error in fit function prefix: " + prefix.toStdString() +
44 "\nIt must start with an 'f' followed by an integer.");
46 auto funIndex = prefix.mid(1, j - 1).toInt();
56 return std::make_pair(
"", -1);
57 auto j = prefix.lastIndexOf(
'.', -2);
58 auto parentPrefix = prefix.left(j > 0 ? j + 1 : 0);
59 auto funIndex = prefix.mid(j + 2, prefix.size() - j - 3).toInt();
60 return std::make_pair(parentPrefix, funIndex);
68 std::pair<QString, std::pair<QString, QString>>
error;
69 if (constraint.isEmpty())
71 QString lowerBoundStr;
72 QString upperBoundStr;
75 expr.
parse(constraint.toStdString());
76 if (expr.
name() !=
"==") {
79 if (expr.
size() == 3) {
82 boost::lexical_cast<double>(expr[0].str());
83 boost::lexical_cast<double>(expr[2].str());
84 if (expr[1].operator_name() ==
"<" && expr[2].operator_name() ==
"<") {
85 lowerBoundStr = QString::fromStdString(expr[0].str());
86 upperBoundStr = QString::fromStdString(expr[2].str());
88 lowerBoundStr = QString::fromStdString(expr[2].str());
89 upperBoundStr = QString::fromStdString(expr[0].str());
91 paramName = QString::fromStdString(expr[1].str());
95 }
else if (expr.
size() == 2) {
99 boost::lexical_cast<double>(expr[1].name());
107 upperBoundStr = QString::fromStdString(expr[1].str());
109 lowerBoundStr = QString::fromStdString(expr[1].str());
111 paramName = QString::fromStdString(expr[0].str());
114 boost::lexical_cast<double>(expr[0].name());
119 lowerBoundStr = QString::fromStdString(expr[0].str());
121 upperBoundStr = QString::fromStdString(expr[0].str());
123 paramName = QString::fromStdString(expr[1].str());
126 return std::make_pair(paramName, std::make_pair(lowerBoundStr, upperBoundStr));
130 return !str.empty() && str.find_first_not_of(
"0123456789.-") == std::string::npos;
133std::vector<std::string>
splitStringBy(std::string
const &str, std::string
const &delimiter) {
134 std::vector<std::string> subStrings;
135 boost::split(subStrings, str, boost::is_any_of(delimiter));
136 subStrings.erase(std::remove_if(subStrings.begin(), subStrings.end(),
137 [](std::string
const &subString) { return subString.empty(); }),
144 if (
index < subStrings.size()) {
146 if (functionIndex.size() == 1 &&
isNumber(functionIndex[0]))
147 return std::stoull(functionIndex[0]);
150 throw std::invalid_argument(
"No function index was found.");
std::map< DeltaEMode::Type, std::string > index
This class represents an expression made up of names, binary operators and brackets.
std::string name() const
Returns the name of the expression which is a function or variable name.
std::string operator_name() const
Returns the the expression's binary operator on its left.
void parse(const std::string &str)
Parse a string and create an expression.
size_t size() const
Returns the number of argumens.
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class