From 9fd34b8cdc98ee757fc047216bd51c698cb7b82f Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Wed, 2 May 2012 00:03:59 +1000 Subject: Fix up some memory leaking issues. --- impl/main.cpp | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'impl/main.cpp') diff --git a/impl/main.cpp b/impl/main.cpp index db3d0f7..a0c6bea 100644 --- a/impl/main.cpp +++ b/impl/main.cpp @@ -4,8 +4,8 @@ #include "Operator.hpp" #include "Expression.hpp" -#include "EquationSystem.hpp" #include "MaxStrategy.hpp" +#include "EquationSystem.hpp" using namespace std; @@ -17,39 +17,50 @@ typedef Minimum Min; std::vector< Expression* > empty; int main () { + { EquationSystem sys; Variable* x = sys.newVariable("x"); Variable* y = sys.newVariable("y"); Variable* z = sys.newVariable("z"); Args xPlusArgs; - xPlusArgs.push_back(new E(x, empty)); + xPlusArgs.push_back(sys.newExpression(x, empty)); + Args xMinArgs; - xMinArgs.push_back(new E(new A(-1), xPlusArgs)); - xMinArgs.push_back(new E(y, empty)); + xMinArgs.push_back(sys.newExpression(new A(-1), xPlusArgs)); + xMinArgs.push_back(sys.newExpression(y, empty)); + Args xMaxArgs; - xMaxArgs.push_back(new E(new C(0), empty)); - xMaxArgs.push_back(new E(new Min(), xMinArgs)); + xMaxArgs.push_back(sys.newExpression(new C(0), empty)); + xMaxArgs.push_back(sys.newExpression(new Min(), xMinArgs)); + sys[*x] = sys.newMaxExpression(xMaxArgs); // x = max(0, min(x-1, y)) + Args yPlusArgs; - yPlusArgs.push_back(new E(x, empty)); + yPlusArgs.push_back(sys.newExpression(x, empty)); + Args yMaxArgs; - yMaxArgs.push_back(new E(new C(0), empty)); - yMaxArgs.push_back(new E(new A(5), yPlusArgs)); - yMaxArgs.push_back(new E(x, empty)); + yMaxArgs.push_back(sys.newExpression(new C(0), empty)); + yMaxArgs.push_back(sys.newExpression(new A(5), yPlusArgs)); + yMaxArgs.push_back(sys.newExpression(x, empty)); + sys[*y] = sys.newMaxExpression(yMaxArgs); // y = max(0, x+5, x) + Args zPlusArgs1; - zPlusArgs1.push_back(new E(z, empty)); + zPlusArgs1.push_back(sys.newExpression(z, empty)); + Args zPlusArgs2; - zPlusArgs2.push_back(new E(x, empty)); + zPlusArgs2.push_back(sys.newExpression(x, empty)); + Args zMaxArgs; - zMaxArgs.push_back(new E(new C(0), empty)); - zMaxArgs.push_back(new E(new A(1), zPlusArgs1)); - zMaxArgs.push_back(new E(new A(0), zPlusArgs2)); + zMaxArgs.push_back(sys.newExpression(new C(0), empty)); + zMaxArgs.push_back(sys.newExpression(new A(1), zPlusArgs1)); + zMaxArgs.push_back(sys.newExpression(new A(0), zPlusArgs2)); + sys[*z] = sys.newMaxExpression(zMaxArgs); // z = max(0, z+1, x) @@ -63,6 +74,7 @@ int main () { cout << "x = " << fixpoint[*x] << endl; cout << "y = " << fixpoint[*y] << endl; cout << "z = " << fixpoint[*z] << endl; + } return 0; } -- cgit v1.2.3