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.
27 * CapMatch::irrelevant denotes a result value that should be ignored.
28 * Therfore it behaves neutral when used in <tt>! && ||</tt> expressions.
32 * (CapMatch::irrelevant && any) == any // true
33 * (CapMatch::irrelevant || any) == any // true
34 * ( !CapMatch::irrelevant ) == CapMatch::irrelevant // true
39 enum Result { NOMATCH, MATCH, IRRELEVANT };
44 : _result( IRRELEVANT )
47 CapMatch( bool val_r )
48 : _result( val_r ? MATCH : NOMATCH )
51 static const CapMatch yes;
52 static const CapMatch no;
53 static const CapMatch irrelevant;
55 friend bool operator==( const CapMatch & lhs, const CapMatch & rhs )
56 { return lhs._result == rhs._result; }
58 friend bool operator!=( const CapMatch & lhs, const CapMatch & rhs )
59 { return lhs._result != rhs._result; }
61 friend CapMatch operator!( const CapMatch & lhs )
63 if ( lhs._result == CapMatch::IRRELEVANT )
65 return !(lhs._result == CapMatch::MATCH);
68 friend CapMatch operator&&( const CapMatch & lhs, const CapMatch & rhs )
70 if ( lhs._result == CapMatch::IRRELEVANT )
72 if ( rhs._result == CapMatch::IRRELEVANT )
74 return (lhs._result == CapMatch::MATCH)
75 && (rhs._result == CapMatch::MATCH);
78 friend CapMatch operator||( const CapMatch & lhs, const CapMatch & rhs )
80 if ( lhs._result == CapMatch::IRRELEVANT )
82 if ( rhs._result == CapMatch::IRRELEVANT )
84 return (lhs._result == CapMatch::MATCH)
85 || (rhs._result == CapMatch::MATCH);
88 friend std::ostream & operator<<( std::ostream & str, const CapMatch & obj );
93 ///////////////////////////////////////////////////////////////////
95 /** \relates CapMatch Stream output */
96 std::ostream & operator<<( std::ostream & str, const CapMatch & obj );
98 /////////////////////////////////////////////////////////////////
100 ///////////////////////////////////////////////////////////////////
101 #endif // ZYPP_CAPMATCH_H