libzypp  10.5.0
CapMatch.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_CAPMATCH_H
00013 #define ZYPP_CAPMATCH_H
00014 
00015 #include <iosfwd>
00016 
00018 namespace zypp
00019 { 
00020 
00022   //
00023   //    CLASS NAME : CapMatch
00024   //
00037   class CapMatch
00038   {
00039     enum Result { NOMATCH, MATCH, IRRELEVANT };
00040 
00041   public:
00042 
00043     CapMatch()
00044     : _result( IRRELEVANT )
00045     {}
00046 
00047     CapMatch( bool val_r )
00048     : _result( val_r ? MATCH : NOMATCH )
00049     {}
00050 
00051     static const CapMatch yes;
00052     static const CapMatch no;
00053     static const CapMatch irrelevant;
00054 
00055     friend bool operator==( const CapMatch & lhs, const CapMatch & rhs )
00056     { return lhs._result == rhs._result; }
00057 
00058     friend bool operator!=( const CapMatch & lhs, const CapMatch & rhs )
00059     { return lhs._result != rhs._result; }
00060 
00061     friend CapMatch operator!( const CapMatch & lhs )
00062     {
00063       if ( lhs._result == CapMatch::IRRELEVANT )
00064         return lhs;
00065       return !(lhs._result == CapMatch::MATCH);
00066     }
00067 
00068     friend CapMatch operator&&( const CapMatch & lhs, const CapMatch & rhs )
00069     {
00070       if ( lhs._result == CapMatch::IRRELEVANT )
00071         return rhs;
00072       if ( rhs._result == CapMatch::IRRELEVANT )
00073         return lhs;
00074       return    (lhs._result == CapMatch::MATCH)
00075              && (rhs._result == CapMatch::MATCH);
00076     }
00077 
00078     friend CapMatch operator||( const CapMatch & lhs, const CapMatch & rhs )
00079     {
00080       if ( lhs._result == CapMatch::IRRELEVANT )
00081         return rhs;
00082       if ( rhs._result == CapMatch::IRRELEVANT )
00083         return lhs;
00084       return    (lhs._result == CapMatch::MATCH)
00085              || (rhs._result == CapMatch::MATCH);
00086     }
00087 
00088     friend std::ostream & operator<<( std::ostream & str, const CapMatch & obj );
00089 
00090   private:
00091     Result _result;
00092   };
00094 
00096   std::ostream & operator<<( std::ostream & str, const CapMatch & obj );
00097 
00099 } // namespace zypp
00101 #endif // ZYPP_CAPMATCH_H