@ -960,30 +960,15 @@ GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Ne, !=, "not equal to");
# undef GMOCK_IMPLEMENT_COMPARISON2_MATCHER_
// TODO(vladl@google.com): Move Impl outside of NotMatcher and rename it
// NotMatcherImpl to reduce compilation overhead and the size of the binary.
// This also applies to BothOfMatcher::Impl and EitherOfMatcher::Impl.
//
// Implements the Not(m) matcher, which matches a value that doesn't
// match matcher m.
template < typename InnerMatcher >
class NotMatcher {
public :
explicit NotMatcher ( InnerMatcher matcher ) : matcher_ ( matcher ) { }
// This template type conversion operator allows Not(m) to be used
// to match any type m can match.
template < typename T >
operator Matcher < T > ( ) const {
return Matcher < T > ( new Impl < T > ( matcher_ ) ) ;
}
private :
// Implements the Not(...) matcher for a particular argument type T.
template < typename T >
class Impl : public MatcherInterface < T > {
// Implements the Not(...) matcher for a particular argument type T.
// We do not nest it inside the NotMatcher class template, as that
// will prevent different instantiations of NotMatcher from sharing
// the same NotMatcherImpl<T> class.
template < typename T >
class NotMatcherImpl : public MatcherInterface < T > {
public :
explicit Impl ( InnerMatcher matcher )
: matcher_ ( SafeMatcherCast < T > ( matcher ) ) { }
explicit NotMatcherImpl ( const Matcher < T > & matcher )
: matcher_ ( matcher ) { }
virtual bool Matches ( T x ) const {
return ! matcher_ . Matches ( x ) ;
@ -1002,35 +987,34 @@ class NotMatcher {
}
private :
const Matcher < T > matcher_ ;
} ;
InnerMatcher matcher_ ;
} ;
// Used for implementing the AllOf(m_1, ..., m_n) matcher, which
// matches a value that matches all of the matchers m_1, ..., and m_n .
template < typename Matcher1 , typename Matcher2 >
class BothOf Matcher {
// Implements the Not(m) matcher, which matches a value that doesn't
// match matcher m.
template < typename InnerMatcher >
class Not Matcher {
public :
BothOfMatcher ( Matcher1 matcher1 , Matcher2 matcher2 )
: matcher1_ ( matcher1 ) , matcher2_ ( matcher2 ) { }
explicit NotMatcher ( InnerMatcher matcher ) : matcher_ ( matcher ) { }
// This template type conversion operator allows a
// BothOfMatcher<Matcher1, Matcher2> object to match any type that
// both Matcher1 and Matcher2 can match.
// This template type conversion operator allows Not(m) to be used
// to match any type m can match.
template < typename T >
operator Matcher < T > ( ) const {
return Matcher < T > ( new Impl < T > ( matcher1_ , matcher2_ ) ) ;
return Matcher < T > ( new NotMatcher Impl< T > ( SafeMatcherCast < T > ( matcher_ ) ) ) ;
}
private :
// Implements the AllOf(m1, m2) matcher for a particular argument
// type T.
template < typename T >
class Impl : public MatcherInterface < T > {
InnerMatcher matcher_ ;
} ;
// Implements the AllOf(m1, m2) matcher for a particular argument type
// T. We do not nest it inside the BothOfMatcher class template, as
// that will prevent different instantiations of BothOfMatcher from
// sharing the same BothOfMatcherImpl<T> class.
template < typename T >
class BothOfMatcherImpl : public MatcherInterface < T > {
public :
Impl ( Matcher1 matcher1 , Matcher2 matcher2 )
: matcher1_ ( SafeMatcherCast < T > ( matcher1 ) ) ,
matcher2_ ( SafeMatcherCast < T > ( matcher2 ) ) { }
BothOfMatcherImpl ( const Matcher < T > & matcher1 , const Matcher < T > & matcher2 )
: matcher1_ ( matcher1 ) , matcher2_ ( matcher2 ) { }
virtual bool Matches ( T x ) const {
return matcher1_ . Matches ( x ) & & matcher2_ . Matches ( x ) ;
@ -1082,37 +1066,38 @@ class BothOfMatcher {
private :
const Matcher < T > matcher1_ ;
const Matcher < T > matcher2_ ;
} ;
Matcher1 matcher1_ ;
Matcher2 matcher2_ ;
} ;
// Used for implementing the AnyOf(m_1, ..., m_n) matcher, which
// matches a value that matches at least one of the matchers m_1, ...,
// and m_n.
// Used for implementing the AllOf(m_1, ..., m_n) matcher, which
// matches a value that matches all of the matchers m_1, ..., and m_n.
template < typename Matcher1 , typename Matcher2 >
class Either OfMatcher {
class Both OfMatcher {
public :
Either OfMatcher( Matcher1 matcher1 , Matcher2 matcher2 )
Both OfMatcher( Matcher1 matcher1 , Matcher2 matcher2 )
: matcher1_ ( matcher1 ) , matcher2_ ( matcher2 ) { }
// This template type conversion operator allows a
// Either OfMatcher<Matcher1, Matcher2> object to match any type that
// Both OfMatcher<Matcher1, Matcher2> object to match any type that
// both Matcher1 and Matcher2 can match.
template < typename T >
operator Matcher < T > ( ) const {
return Matcher < T > ( new Impl < T > ( matcher1_ , matcher2_ ) ) ;
return Matcher < T > ( new BothOfMatcherImpl < T > ( SafeMatcherCast < T > ( matcher1_ ) ,
SafeMatcherCast < T > ( matcher2_ ) ) ) ;
}
private :
// Implements the AnyOf(m1, m2) matcher for a particular argument
// type T.
template < typename T >
class Impl : public MatcherInterface < T > {
Matcher1 matcher1_ ;
Matcher2 matcher2_ ;
} ;
// Implements the AnyOf(m1, m2) matcher for a particular argument type
// T. We do not nest it inside the AnyOfMatcher class template, as
// that will prevent different instantiations of AnyOfMatcher from
// sharing the same EitherOfMatcherImpl<T> class.
template < typename T >
class EitherOfMatcherImpl : public MatcherInterface < T > {
public :
Impl ( Matcher1 matcher1 , Matcher2 matcher2 )
: matcher1_ ( SafeMatcherCast < T > ( matcher1 ) ) ,
matcher2_ ( SafeMatcherCast < T > ( matcher2 ) ) { }
EitherOfMatcherImpl ( const Matcher < T > & matcher1 , const Matcher < T > & matcher2 )
: matcher1_ ( matcher1 ) , matcher2_ ( matcher2 ) { }
virtual bool Matches ( T x ) const {
return matcher1_ . Matches ( x ) | | matcher2_ . Matches ( x ) ;
@ -1163,8 +1148,26 @@ class EitherOfMatcher {
private :
const Matcher < T > matcher1_ ;
const Matcher < T > matcher2_ ;
} ;
} ;
// Used for implementing the AnyOf(m_1, ..., m_n) matcher, which
// matches a value that matches at least one of the matchers m_1, ...,
// and m_n.
template < typename Matcher1 , typename Matcher2 >
class EitherOfMatcher {
public :
EitherOfMatcher ( Matcher1 matcher1 , Matcher2 matcher2 )
: matcher1_ ( matcher1 ) , matcher2_ ( matcher2 ) { }
// This template type conversion operator allows a
// EitherOfMatcher<Matcher1, Matcher2> object to match any type that
// both Matcher1 and Matcher2 can match.
template < typename T >
operator Matcher < T > ( ) const {
return Matcher < T > ( new EitherOfMatcherImpl < T > ( SafeMatcherCast < T > ( matcher1_ ) ,
SafeMatcherCast < T > ( matcher2_ ) ) ) ;
}
private :
Matcher1 matcher1_ ;
Matcher2 matcher2_ ;
} ;