~thopiekar/zypper/libzypp-manual-import

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*---------------------------------------------------------------------\
|                          ____ _   __ __ ___                          |
|                         |__  / \ / / . \ . \                         |
|                           / / \ V /|  _/  _/                         |
|                          / /__ | | | | | |                           |
|                         /_____||_| |_| |_|                           |
|                                                                      |
\---------------------------------------------------------------------*/
/** \file	zypp/CapMatch.h
 *
*/
#ifndef ZYPP_CAPMATCH_H
#define ZYPP_CAPMATCH_H

#include <iosfwd>

///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////

  ///////////////////////////////////////////////////////////////////
  //
  //	CLASS NAME : CapMatch
  //
  /** Tri state Capability match result.
   *
   * CapMatch::irrelevant denotes a result value that should be ignored.
   * Therfore it behaves neutral when used in <tt>! && ||</tt> expressions.
   *
   * \code
   *   CapMatch any
   *   (CapMatch::irrelevant && any) == any                  // true
   *   (CapMatch::irrelevant || any) == any                  // true
   *   ( !CapMatch::irrelevant )     == CapMatch::irrelevant // true
   * \endcode
  */
  class CapMatch
  {
    enum Result { NOMATCH, MATCH, IRRELEVANT };

  public:

    CapMatch()
    : _result( IRRELEVANT )
    {}

    CapMatch( bool val_r )
    : _result( val_r ? MATCH : NOMATCH )
    {}

    static const CapMatch yes;
    static const CapMatch no;
    static const CapMatch irrelevant;

    friend bool operator==( const CapMatch & lhs, const CapMatch & rhs )
    { return lhs._result == rhs._result; }

    friend bool operator!=( const CapMatch & lhs, const CapMatch & rhs )
    { return lhs._result != rhs._result; }

    friend CapMatch operator!( const CapMatch & lhs )
    {
      if ( lhs._result == CapMatch::IRRELEVANT )
        return lhs;
      return !(lhs._result == CapMatch::MATCH);
    }

    friend CapMatch operator&&( const CapMatch & lhs, const CapMatch & rhs )
    {
      if ( lhs._result == CapMatch::IRRELEVANT )
        return rhs;
      if ( rhs._result == CapMatch::IRRELEVANT )
        return lhs;
      return    (lhs._result == CapMatch::MATCH)
             && (rhs._result == CapMatch::MATCH);
    }

    friend CapMatch operator||( const CapMatch & lhs, const CapMatch & rhs )
    {
      if ( lhs._result == CapMatch::IRRELEVANT )
        return rhs;
      if ( rhs._result == CapMatch::IRRELEVANT )
        return lhs;
      return    (lhs._result == CapMatch::MATCH)
             || (rhs._result == CapMatch::MATCH);
    }

    friend std::ostream & operator<<( std::ostream & str, const CapMatch & obj );

  private:
    Result _result;
  };
  ///////////////////////////////////////////////////////////////////

  /** \relates CapMatch Stream output */
  std::ostream & operator<<( std::ostream & str, const CapMatch & obj );

  /////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
#endif // ZYPP_CAPMATCH_H