From c527646ddbb9bdf6c4e61538e062e6567204c542 Mon Sep 17 00:00:00 2001 From: sjunges Date: Tue, 13 Sep 2016 11:06:14 +0200 Subject: [PATCH] Added convenience operator overloads for more readable code :) Former-commit-id: 082f19bede7b6a9bc0c207cc35cfd90037f19072 [formerly 94b4f6284f043854e3f27dbeb2f3868f95642283] Former-commit-id: c95b0dc93f3b44e980a5caf3ffb38c20844e2257 --- src/storage/expressions/Expression.cpp | 15 +++++++++++++++ src/storage/expressions/Expression.h | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/src/storage/expressions/Expression.cpp b/src/storage/expressions/Expression.cpp index 3d6094d8b..410b613ec 100644 --- a/src/storage/expressions/Expression.cpp +++ b/src/storage/expressions/Expression.cpp @@ -185,11 +185,26 @@ namespace storm { return Expression(std::shared_ptr(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(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) { assertSameManager(first.getBaseExpression(), second.getBaseExpression()); return Expression(std::shared_ptr(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(new IntegerLiteralExpression(first.getBaseExpression().getManager(), second))); + } + + Expression operator-(int64_t first, Expression const& second) { + return Expression(std::shared_ptr(new IntegerLiteralExpression(second.getBaseExpression().getManager(), first))) - second; } + Expression operator-(Expression const& first) { return Expression(std::shared_ptr(new UnaryNumericalFunctionExpression(first.getBaseExpression().getManager(), first.getType().minus(), first.getBaseExpressionPointer(), UnaryNumericalFunctionExpression::OperatorType::Minus))); } diff --git a/src/storage/expressions/Expression.h b/src/storage/expressions/Expression.h index 40fcaa572..176d9316d 100644 --- a/src/storage/expressions/Expression.h +++ b/src/storage/expressions/Expression.h @@ -23,7 +23,11 @@ namespace storm { template friend class SubstitutionVisitor; 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, int64_t second); + friend Expression operator-(int64_t first, Expression const& second); friend Expression operator-(Expression const& first); 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. 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, int64_t second); + Expression operator-(int64_t first, Expression const& second); Expression operator-(Expression const& first); Expression operator*(Expression const& first, Expression const& second); Expression operator/(Expression const& first, Expression const& second);