Browse Source

Added convenience operator overloads for more readable code :)

Former-commit-id: 082f19bede [formerly 94b4f6284f]
Former-commit-id: c95b0dc93f
tempestpy_adaptions
sjunges 8 years ago
parent
commit
c527646ddb
  1. 15
      src/storage/expressions/Expression.cpp
  2. 8
      src/storage/expressions/Expression.h

15
src/storage/expressions/Expression.cpp

@ -185,11 +185,26 @@ namespace storm {
return Expression(std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(first.getManager(), first.getType().plusMinusTimes(second.getType()), first.getBaseExpressionPointer(), second.getBaseExpressionPointer(), BinaryNumericalFunctionExpression::OperatorType::Plus))); return Expression(std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(first.getManager(), first.getType().plusMinusTimes(second.getType()), first.getBaseExpressionPointer(), second.getBaseExpressionPointer(), BinaryNumericalFunctionExpression::OperatorType::Plus)));
} }
Expression operator+(Expression const& first, int64_t second) {
return first + Expression(std::shared_ptr<BaseExpression>(new IntegerLiteralExpression(first.getBaseExpression().getManager(), second)));
}
Expression operator+(int64_t first, Expression const& second) {
return second + first;
}
Expression operator-(Expression const& first, Expression const& second) { Expression operator-(Expression const& first, Expression const& second) {
assertSameManager(first.getBaseExpression(), second.getBaseExpression()); assertSameManager(first.getBaseExpression(), second.getBaseExpression());
return Expression(std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(first.getBaseExpression().getManager(), first.getType().plusMinusTimes(second.getType()), first.getBaseExpressionPointer(), second.getBaseExpressionPointer(), BinaryNumericalFunctionExpression::OperatorType::Minus))); return Expression(std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(first.getBaseExpression().getManager(), first.getType().plusMinusTimes(second.getType()), first.getBaseExpressionPointer(), second.getBaseExpressionPointer(), BinaryNumericalFunctionExpression::OperatorType::Minus)));
} }
Expression operator-(Expression const& first, int64_t second) {
return first - Expression(std::shared_ptr<BaseExpression>(new IntegerLiteralExpression(first.getBaseExpression().getManager(), second)));
}
Expression operator-(int64_t first, Expression const& second) {
return Expression(std::shared_ptr<BaseExpression>(new IntegerLiteralExpression(second.getBaseExpression().getManager(), first))) - second; }
Expression operator-(Expression const& first) { Expression operator-(Expression const& first) {
return Expression(std::shared_ptr<BaseExpression>(new UnaryNumericalFunctionExpression(first.getBaseExpression().getManager(), first.getType().minus(), first.getBaseExpressionPointer(), UnaryNumericalFunctionExpression::OperatorType::Minus))); return Expression(std::shared_ptr<BaseExpression>(new UnaryNumericalFunctionExpression(first.getBaseExpression().getManager(), first.getType().minus(), first.getBaseExpressionPointer(), UnaryNumericalFunctionExpression::OperatorType::Minus)));
} }

8
src/storage/expressions/Expression.h

@ -23,7 +23,11 @@ namespace storm {
template<typename MapType> friend class SubstitutionVisitor; template<typename MapType> friend class SubstitutionVisitor;
friend Expression operator+(Expression const& first, Expression const& second); friend Expression operator+(Expression const& first, Expression const& second);
friend Expression operator+(Expression const& first, int64_t second);
friend Expression operator+(int64_t first, Expression const& second);
friend Expression operator-(Expression const& first, Expression const& second); friend Expression operator-(Expression const& first, Expression const& second);
friend Expression operator-(Expression const& first, int64_t second);
friend Expression operator-(int64_t first, Expression const& second);
friend Expression operator-(Expression const& first); friend Expression operator-(Expression const& first);
friend Expression operator*(Expression const& first, Expression const& second); friend Expression operator*(Expression const& first, Expression const& second);
friend Expression operator/(Expression const& first, Expression const& second); friend Expression operator/(Expression const& first, Expression const& second);
@ -328,7 +332,11 @@ namespace storm {
// Provide operator overloads to conveniently construct new expressions from other expressions. // Provide operator overloads to conveniently construct new expressions from other expressions.
Expression operator+(Expression const& first, Expression const& second); Expression operator+(Expression const& first, Expression const& second);
Expression operator+(Expression const& first, int64_t second);
Expression operator+(int64_t first, Expression const& second);
Expression operator-(Expression const& first, Expression const& second); Expression operator-(Expression const& first, Expression const& second);
Expression operator-(Expression const& first, int64_t second);
Expression operator-(int64_t first, Expression const& second);
Expression operator-(Expression const& first); Expression operator-(Expression const& first);
Expression operator*(Expression const& first, Expression const& second); Expression operator*(Expression const& first, Expression const& second);
Expression operator/(Expression const& first, Expression const& second); Expression operator/(Expression const& first, Expression const& second);

Loading…
Cancel
Save