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_ISLESSTHANCONSTRAINT_H
7 #define SNOWHOUSE_ISLESSTHANCONSTRAINT_H
8 
9 #include "expressions/expression.h"
10 
11 namespace snowhouse
12 {
13   template<typename ExpectedType>
14   struct IsLessThanConstraint : Expression<IsLessThanConstraint<ExpectedType> >
15   {
IsLessThanConstraintIsLessThanConstraint16     IsLessThanConstraint(const ExpectedType& expected)
17         : m_expected(expected)
18     {
19     }
20 
21     template<typename ActualType>
operatorIsLessThanConstraint22     bool operator()(const ActualType& actual) const
23     {
24       return (actual < m_expected);
25     }
26 
27     ExpectedType m_expected;
28   };
29 
30   template<typename ExpectedType>
IsLessThan(const ExpectedType & expected)31   inline IsLessThanConstraint<ExpectedType> IsLessThan(const ExpectedType& expected)
32   {
33     return IsLessThanConstraint<ExpectedType>(expected);
34   }
35 
IsLessThan(const char * expected)36   inline IsLessThanConstraint<std::string> IsLessThan(const char* expected)
37   {
38     return IsLessThanConstraint<std::string>(expected);
39   }
40 
41   template<typename ExpectedType>
42   struct Stringizer<IsLessThanConstraint<ExpectedType> >
43   {
44     static std::string ToString(const IsLessThanConstraint<ExpectedType>& constraint)
45     {
46       std::ostringstream builder;
47       builder << "less than " << snowhouse::Stringize(constraint.m_expected);
48 
49       return builder.str();
50     }
51   };
52 }
53 #endif
54