summaryrefslogtreecommitdiff
path: root/vendor/bandit/bandit/assertion_frameworks/matchers/MatchProxy.h
blob: b637ef0df006dee0c8c82007ef487e9a2159b24f (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
#ifndef BANDIT_MATCHPROXY_H
#define BANDIT_MATCHPROXY_H

#include "MatcherException.h"

namespace bandit { namespace Matchers
{
    template<typename T> class ValueProxy;

    template<typename T>
    class MatchProxy
    {
    private:
        template<typename U>
        MatchProxy(const MatchProxy<U>&);

        template<typename U>
        MatchProxy& operator=(const MatchProxy<U>&);

    public:
        explicit MatchProxy(const ValueProxy<T>& value, bool negate_ = false) : _value(value), _negate(negate_) {}

        template<typename MatcherType>
	void operator()(const MatcherType& matcher) const
        {
	    if( matcher.matches(_value._value) == _negate )
	    {
		throw MatcherException(_value._filename, _value._lineNumber, matcher.failure_message(_value._value, _negate));
	    }
        }

        MatchProxy<T> negate() const
        {
            return MatchProxy<T>(_value, !_negate);
        }

    private:
        const ValueProxy<T>& _value;
        bool _negate;
    };
}}

#endif	// BANDIT_MATCHPROXY_H