summaryrefslogtreecommitdiff
path: root/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/andoperator.h
blob: 39670632a9c2b1633574858a23a4fa4822756527 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//          Copyright Joakim Karlsson & Kim Gräsman 2010-2012.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#ifndef IGLOO_ANDOPERATOR_H
#define IGLOO_ANDOPERATOR_H

namespace snowhouse {
  
  struct AndOperator : public ConstraintOperator
  {
    template <typename ConstraintListType, typename ActualType>
    void Evaluate(ConstraintListType& list, ResultStack& result, OperatorStack& operators, const ActualType& actual)
    {
      EvaluateOperatorsWithLessOrEqualPrecedence(*this, operators, result);
      
      operators.push(this);
      
      EvaluateConstraintList(list.m_tail, result, operators, actual);
    }
    
    void PerformOperation(ResultStack& result)
    {
      if(result.size() < 2)
      {
        throw InvalidExpressionException("The expression contains an and operator with too few operands");
      }
      
      bool right = result.top();
      result.pop();
      bool left = result.top();
      result.pop();
      
      result.push(left && right);
    }
    
    int Precedence() const
    {
      return 3;
    }
  };
  
   template<>
   struct Stringizer<AndOperator>
   {
      static std::string ToString(const AndOperator&)
      {
        return "and";
      }
   };
}
#endif