1 //          Copyright Joakim Karlsson & Kim Gräsman 2010-2012.
2 // Distributed under the Boost Software License, Version 1.0.
3 //    (See accompanying file LICENSE_1_0.txt or copy at
4 //          http://www.boost.org/LICENSE_1_0.txt)
5 
6 #ifndef SNOWHOUSE_ISLESSTHANOREQUALTOCONSTRAINT_H
7 #define SNOWHOUSE_ISLESSTHANOREQUALTOCONSTRAINT_H
8 
9 #include "expressions/expression.h"
10 
11 namespace snowhouse
12 {
13   template<typename ExpectedType>
14   struct IsLessThanOrEqualToConstraint : Expression<IsLessThanOrEqualToConstraint<ExpectedType> >
15   {
IsLessThanOrEqualToConstraintIsLessThanOrEqualToConstraint16     IsLessThanOrEqualToConstraint(const ExpectedType& expected)
17         : m_expected(expected)
18     {
19     }
20 
21     template<typename ActualType>
operatorIsLessThanOrEqualToConstraint22     bool operator()(const ActualType& actual) const
23     {
24       return (actual <= m_expected);
25     }
26 
27     ExpectedType m_expected;
28   };
29 
30   template<typename ExpectedType>
IsLessThanOrEqualTo(const ExpectedType & expected)31   inline IsLessThanOrEqualToConstraint<ExpectedType> IsLessThanOrEqualTo(const ExpectedType& expected)
32   {
33     return IsLessThanOrEqualToConstraint<ExpectedType>(expected);
34   }
35 
IsLessThanOrEqualTo(const char * expected)36   inline IsLessThanOrEqualToConstraint<std::string> IsLessThanOrEqualTo(const char* expected)
37   {
38     return IsLessThanOrEqualToConstraint<std::string>(expected);
39   }
40 
41   template<typename ExpectedType>
42   struct Stringizer<IsLessThanOrEqualToConstraint<ExpectedType> >
43   {
44     static std::string ToString(const IsLessThanOrEqualToConstraint<ExpectedType>& constraint)
45     {
46       std::ostringstream builder;
47       builder << "less than or equal to " << snowhouse::Stringize(constraint.m_expected);
48 
49       return builder.str();
50     }
51   };
52 }
53 
54 #endif
55