8#include <framework/core/ModuleCondition.h>
9#include <framework/core/Path.h>
10#include <framework/utilities/Conversion.h>
12#include <boost/algorithm/string/erase.hpp>
14#include <boost/python/class.hpp>
15#include <boost/python/docstring_options.hpp>
21using namespace boost::python;
25 m_conditionPath(
std::move(conditionPath)),
26 m_afterConditionPath(afterConditionPath)
29 std::map<std::string, EConditionOperators> m_conditionOperatorMap;
30 m_conditionOperatorMap[
">"] =
c_GT;
31 m_conditionOperatorMap[
"<"] =
c_ST;
32 m_conditionOperatorMap[
">="] =
c_GE;
33 m_conditionOperatorMap[
"<="] =
c_SE;
34 m_conditionOperatorMap[
"="] =
c_EQ;
35 m_conditionOperatorMap[
"=="] =
c_EQ;
36 m_conditionOperatorMap[
"!="] =
c_NE;
39 boost::erase_all(expression,
" ");
42 unsigned int iOperator = 0;
43 while ((iOperator < expression.length()) && (!isdigit(expression[iOperator]) && (expression[iOperator] !=
'-'))) iOperator++;
45 throw std::runtime_error(
"Invalid condition: could not parse condition: '" + expression +
"'!");
46 std::string opString = expression.substr(0, iOperator);
49 auto foundIter = m_conditionOperatorMap.find(opString);
50 if (foundIter == m_conditionOperatorMap.end())
51 throw std::runtime_error(
"Invalid condition: could not parse condition: '" + expression +
"'!");
55 m_conditionValue = convertString<int>(expression.substr(iOperator, expression.length() - 1));
73 std::string output =
"(? ";
75 case c_GT: output +=
">";
break;
76 case c_ST: output +=
"<";
break;
77 case c_GE: output +=
">=";
break;
78 case c_SE: output +=
"<=";
break;
79 case c_NE: output +=
"!=";
break;
80 case c_EQ: output +=
"==";
break;
81 default: output +=
"???";
91 std::shared_ptr<Path> _getPathPython(
ModuleCondition* m) {
return m->getPath(); };
96 docstring_options options(
true,
true,
false);
99 class_<ModuleCondition, boost::noncopyable>(
"ModuleCondition", no_init)
104 .def(
"get_path", &_getPathPython)
Wraps a condition set on a Module instance.
bool evaluate(int value) const
evaluate the condition using the given value.
std::shared_ptr< Path > m_conditionPath
The path which which will be executed if the condition is evaluated to true.
EConditionOperators m_conditionOperator
The operator of the condition (set by parsing the condition expression).
@ c_GE
Greater or equal than: ">=".
@ c_SE
Smaller or equal than: "<=".
std::string getString() const
A string representation of this condition.
EAfterConditionPath
Different options for behaviour after a conditional path was executed.
EConditionOperators getConditionOperator() const
Returns the value of the condition.
int m_conditionValue
Numeric value used in the condition (set by parsing the condition expression).
int getConditionValue() const
Returns the value of the condition.
EAfterConditionPath getAfterConditionPath() const
What to do after a conditional path is finished.
static void exposePythonAPI()
Exposes methods of the ModuleCondition class to Python.
ModuleCondition()=delete
no default constructed objects.
Abstract base class for different kinds of events.