1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/CapMatch.h
12 #ifndef ZYPP_CAPMATCH_H
13 #define ZYPP_CAPMATCH_H
17 ///////////////////////////////////////////////////////////////////
19 { /////////////////////////////////////////////////////////////////
21 ///////////////////////////////////////////////////////////////////
23 // CLASS NAME : CapMatch
25 /** Tri state Capability match result.
26 * CapMatch::irrelevant denotes a result value that should be ignored.
27 * Therfore it behaves neutral when used in <tt>! && ||</tt> expressions.
30 * (CapMatch::irrelevant && any) == any // true
31 * (CapMatch::irrelevant || any) == any // true
32 * ( !CapMatch::irrelevant ) == CapMatch::irrelevant // true
37 enum Result { NOMATCH, MATCH, IRRELEVANT };
41 CapMatch( bool val_r )
42 : _result( val_r ? MATCH : NOMATCH )
45 static const CapMatch yes;
46 static const CapMatch no;
47 static const CapMatch irrelevant;
49 friend bool operator==( const CapMatch & lhs, const CapMatch & rhs )
50 { return lhs._result == rhs._result; }
52 friend bool operator!=( const CapMatch & lhs, const CapMatch & rhs )
53 { return lhs._result != rhs._result; }
55 friend CapMatch operator!( const CapMatch & lhs )
57 if ( lhs._result == CapMatch::IRRELEVANT )
59 return !(lhs._result == CapMatch::MATCH);
62 friend CapMatch operator&&( const CapMatch & lhs, const CapMatch & rhs )
64 if ( lhs._result == CapMatch::IRRELEVANT )
66 if ( rhs._result == CapMatch::IRRELEVANT )
68 return (lhs._result == CapMatch::MATCH)
69 && (rhs._result == CapMatch::MATCH);
72 friend CapMatch operator||( const CapMatch & lhs, const CapMatch & rhs )
74 if ( lhs._result == CapMatch::IRRELEVANT )
76 if ( rhs._result == CapMatch::IRRELEVANT )
78 return (lhs._result == CapMatch::MATCH)
79 || (rhs._result == CapMatch::MATCH);
82 friend std::ostream & operator<<( std::ostream & str, const CapMatch & obj );
86 : _result( IRRELEVANT )
91 ///////////////////////////////////////////////////////////////////
93 /** \relates CapMatch Stream output */
94 std::ostream & operator<<( std::ostream & str, const CapMatch & obj );
96 /////////////////////////////////////////////////////////////////
98 ///////////////////////////////////////////////////////////////////
99 #endif // ZYPP_CAPMATCH_H