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;
24 m_conditionPath(
std::move(conditionPath)),
25 m_afterConditionPath(afterConditionPath)
28 std::map<std::string, EConditionOperators> m_conditionOperatorMap;
29 m_conditionOperatorMap[
">"] = c_GT;
30 m_conditionOperatorMap[
"<"] = c_ST;
31 m_conditionOperatorMap[
">="] = c_GE;
32 m_conditionOperatorMap[
"<="] = c_SE;
33 m_conditionOperatorMap[
"="] = c_EQ;
34 m_conditionOperatorMap[
"=="] = c_EQ;
35 m_conditionOperatorMap[
"!="] = c_NE;
38 boost::erase_all(expression,
" ");
41 unsigned int iOperator = 0;
42 while ((iOperator < expression.length()) && (!isdigit(expression[iOperator]) && (expression[iOperator] !=
'-'))) iOperator++;
44 throw std::runtime_error(
"Invalid condition: could not parse condition: '" + expression +
"'!");
45 std::string opString = expression.substr(0, iOperator);
48 auto foundIter = m_conditionOperatorMap.find(opString);
49 if (foundIter == m_conditionOperatorMap.end())
50 throw std::runtime_error(
"Invalid condition: could not parse condition: '" + expression +
"'!");
52 m_conditionOperator = foundIter->second;
54 m_conditionValue = convertString<int>(expression.substr(iOperator, expression.length() - 1));
72 std::string output =
"(? ";
74 case c_GT: output +=
">";
break;
75 case c_ST: output +=
"<";
break;
76 case c_GE: output +=
">=";
break;
77 case c_SE: output +=
"<=";
break;
78 case c_NE: output +=
"!=";
break;
79 case c_EQ: output +=
"==";
break;
80 default: output +=
"???";
90 std::shared_ptr<Path> _getPathPython(
ModuleCondition* m) {
return m->getPath(); };
95 docstring_options options(
true,
true,
false);
98 class_<ModuleCondition, boost::noncopyable>(
"ModuleCondition", no_init)
103 .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.
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.
std::shared_ptr< Path > PathPtr
Defines a pointer to a path object as a boost shared pointer.
Abstract base class for different kinds of events.