-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperators.hpp
110 lines (101 loc) · 3.08 KB
/
operators.hpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// Copyright Mathieu Champlon 2010
//
// 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 MOCK_OPERATORS_HPP_INCLUDED
#define MOCK_OPERATORS_HPP_INCLUDED
#include "constraint.hpp"
#include "log.hpp"
namespace mock
{
namespace detail
{
template< typename Constraint1, typename Constraint2 >
class and_
{
public:
and_( const Constraint1& c1, const Constraint2& c2 )
: c1_( c1 )
, c2_( c2 )
{}
template< typename Actual >
bool operator()( const Actual& actual ) const
{
return c1_( actual ) && c2_( actual );
}
friend std::ostream& operator<<( std::ostream& s, const and_& a )
{
return s << "( " << mock::format( a.c1_ )
<< " && " << mock::format( a.c2_ ) << " )";
}
private:
Constraint1 c1_;
Constraint2 c2_;
};
template< typename Constraint1, typename Constraint2 >
class or_
{
public:
or_( const Constraint1& c1, const Constraint2& c2 )
: c1_( c1 )
, c2_( c2 )
{}
template< typename Actual >
bool operator()( const Actual& actual ) const
{
return c1_( actual ) || c2_( actual );
}
friend std::ostream& operator<<( std::ostream& s, const or_& o )
{
return s << "( " << mock::format( o.c1_ )
<< " || " << mock::format( o.c2_ )<< " )";
}
private:
Constraint1 c1_;
Constraint2 c2_;
};
template< typename Constraint >
class not_
{
public:
explicit not_( const Constraint& f )
: f_( f )
{}
template< typename Actual >
bool operator()( const Actual& actual ) const
{
return ! f_( actual );
}
friend std::ostream& operator<<( std::ostream& s, const not_& n )
{
return s << "! " << mock::format( n.f_ );
}
private:
Constraint f_;
};
}
template< typename Constraint1, typename Constraint2 >
const constraint< detail::or_< Constraint1, Constraint2 > >
operator||( const constraint< Constraint1 >& lhs,
const constraint< Constraint2 >& rhs )
{
return detail::or_< Constraint1, Constraint2 >( lhs.f_, rhs.f_ );
}
template< typename Constraint1, typename Constraint2 >
const constraint< detail::and_< Constraint1, Constraint2 > >
operator&&( const constraint< Constraint1 >& lhs,
const constraint< Constraint2 >& rhs )
{
return detail::and_< Constraint1, Constraint2 >( lhs.f_, rhs.f_ );
}
template< typename Constraint >
const constraint< detail::not_< Constraint > >
operator!( const constraint< Constraint >& c )
{
return detail::not_< Constraint >( c.f_ );
}
}
#endif // MOCK_OPERATORS_HPP_INCLUDED