diff options
author | Carlo Zancanaro <carlo@carlo-laptop> | 2012-05-03 15:35:39 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@carlo-laptop> | 2012-05-03 15:35:39 +1000 |
commit | fcecd0e7dc0bf103986c02e2f29fb518cd5571c5 (patch) | |
tree | 518bf3fcb3733bb8cc2ef584346aa409ea618a77 /impl/Operator.hpp | |
parent | 9fd34b8cdc98ee757fc047216bd51c698cb7b82f (diff) |
Add a parser for linear equations
(Also add the antlr jar and C runtime)
Diffstat (limited to 'impl/Operator.hpp')
-rw-r--r-- | impl/Operator.hpp | 21 |
1 files changed, 16 insertions, 5 deletions
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<typename T> T infinity() { } - template<> float infinity() { return INFINITY; @@ -60,12 +59,24 @@ struct Constant : public Operator<T> { template<typename T> struct Addition: public Operator<T> { - Addition(int i) : _value(i) { } T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& 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<typename T> +struct Subtraction: public Operator<T> { + T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& 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" |