From fcecd0e7dc0bf103986c02e2f29fb518cd5571c5 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Thu, 3 May 2012 15:35:39 +1000 Subject: Add a parser for linear equations (Also add the antlr jar and C runtime) --- impl/Operator.hpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'impl/Operator.hpp') diff --git a/impl/Operator.hpp b/impl/Operator.hpp index 2c5af75..c9b4a06 100644 --- a/impl/Operator.hpp +++ b/impl/Operator.hpp @@ -3,7 +3,6 @@ template T infinity() { } - template<> float infinity() { return INFINITY; @@ -60,12 +59,24 @@ struct Constant : public Operator { template struct Addition: public Operator { - Addition(int i) : _value(i) { } T operator() (const std::vector< Expression* >& args, const VariableAssignment& ass) const { - return (*args[0])(ass) + _value; + T sum = (*args[0])(ass); + for (unsigned int i = 1, size = args.size(); i < size; ++i) { + sum += (*args[i])(ass); + } + return sum; + } +}; + +template +struct Subtraction: public Operator { + T operator() (const std::vector< Expression* >& args, const VariableAssignment& ass) const { + T sum = (*args[0])(ass); + for (unsigned int i = 1, size = args.size(); i < size; ++i) { + sum -= (*args[i])(ass); + } + return sum; } - private: - int _value; }; #include "VariableAssignment.hpp" -- cgit v1.2.3