ignore
[platform/upstream/libzypp.git] / zypp / CapMatch.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/CapMatch.h
10  *
11 */
12 #ifndef ZYPP_CAPMATCH_H
13 #define ZYPP_CAPMATCH_H
14
15 #include <iosfwd>
16
17 ///////////////////////////////////////////////////////////////////
18 namespace zypp
19 { /////////////////////////////////////////////////////////////////
20
21   ///////////////////////////////////////////////////////////////////
22   //
23   //    CLASS NAME : CapMatch
24   //
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.
28    * \code
29    *   CapMatch any
30    *   (CapMatch::irrelevant && any) == any                  // true
31    *   (CapMatch::irrelevant || any) == any                  // true
32    *   ( !CapMatch::irrelevant )     == CapMatch::irrelevant // true
33    * \endcode
34   */
35   class CapMatch
36   {
37     enum Result { NOMATCH, MATCH, IRRELEVANT };
38
39   public:
40
41     CapMatch( bool val_r )
42     : _result( val_r ? MATCH : NOMATCH )
43     {}
44
45     static const CapMatch yes;
46     static const CapMatch no;
47     static const CapMatch irrelevant;
48
49     friend bool operator==( const CapMatch & lhs, const CapMatch & rhs )
50     { return lhs._result == rhs._result; }
51
52     friend bool operator!=( const CapMatch & lhs, const CapMatch & rhs )
53     { return lhs._result != rhs._result; }
54
55     friend CapMatch operator!( const CapMatch & lhs )
56     {
57       if ( lhs._result == CapMatch::IRRELEVANT )
58         return lhs;
59       return !(lhs._result == CapMatch::MATCH);
60     }
61
62     friend CapMatch operator&&( const CapMatch & lhs, const CapMatch & rhs )
63     {
64       if ( lhs._result == CapMatch::IRRELEVANT )
65         return rhs;
66       if ( rhs._result == CapMatch::IRRELEVANT )
67         return lhs;
68       return    (lhs._result == CapMatch::MATCH)
69              && (rhs._result == CapMatch::MATCH);
70     }
71
72     friend CapMatch operator||( const CapMatch & lhs, const CapMatch & rhs )
73     {
74       if ( lhs._result == CapMatch::IRRELEVANT )
75         return rhs;
76       if ( rhs._result == CapMatch::IRRELEVANT )
77         return lhs;
78       return    (lhs._result == CapMatch::MATCH)
79              || (rhs._result == CapMatch::MATCH);
80     }
81
82     friend std::ostream & operator<<( std::ostream & str, const CapMatch & obj );
83
84   private:
85     CapMatch()
86     : _result( IRRELEVANT )
87     {}
88
89     Result _result;
90   };
91   ///////////////////////////////////////////////////////////////////
92
93   /** \relates CapMatch Stream output */
94   std::ostream & operator<<( std::ostream & str, const CapMatch & obj );
95
96   /////////////////////////////////////////////////////////////////
97 } // namespace zypp
98 ///////////////////////////////////////////////////////////////////
99 #endif // ZYPP_CAPMATCH_H