importing my current diff
[platform/upstream/libzypp.git] / zypp / Dep.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/Dep.h
10  *
11 */
12 #ifndef ZYPP_DEP_H
13 #define ZYPP_DEP_H
14
15 #include <iostream>
16 #include <string>
17
18 ///////////////////////////////////////////////////////////////////
19 namespace zypp
20 { /////////////////////////////////////////////////////////////////
21
22   ///////////////////////////////////////////////////////////////////
23   //
24   //    CLASS NAME : Dep
25   //
26   /** Enumeration class of dependency types.
27    * \ingroup g_EnumerationClass
28   */
29   struct Dep
30   {
31     friend bool operator==( const Dep & lhs, const Dep & rhs );
32     friend bool operator!=( const Dep & lhs, const Dep & rhs );
33     /** Arbitrary order to allow Dep as key in std::container. */
34     friend bool operator<( const Dep & lhs, const Dep & rhs );
35
36     /** \name Dependency types
37      * These are the \em real dependency type contants to
38      * use. Don't mind that it's not an enum.
39      * \see \ref zypp::Dep::inSwitch
40     */
41     //@{
42     static const Dep PROVIDES;
43     static const Dep PREREQUIRES;
44     static const Dep REQUIRES;
45     static const Dep CONFLICTS;
46     static const Dep OBSOLETES;
47     static const Dep RECOMMENDS;
48     static const Dep SUGGESTS;
49     static const Dep FRESHENS;
50     static const Dep ENHANCES;
51     static const Dep SUPPLEMENTS;
52     //@}
53
54     /** Enumarators provided \b only for use \ref inSwitch statement.
55      * \see inSwitch
56     */
57     enum for_use_in_switch {
58       PROVIDES_e,
59       PREREQUIRES_e,
60       REQUIRES_e,
61       CONFLICTS_e,
62       OBSOLETES_e,
63       RECOMMENDS_e,
64       SUGGESTS_e,
65       FRESHENS_e,
66       ENHANCES_e,
67       SUPPLEMENTS_e,
68     };
69
70     /** Ctor from string.
71      * Legal values for \a strval_r are the constants names
72      * (case insignificant).
73      *
74      * \throw PARSE if \a strval_r is not legal.
75      * \todo refine exceptions and check throw.
76     */
77     explicit
78     Dep( const std::string & strval_r );
79
80     /** String representation of dependency type.
81      * \return The constants names lowercased.
82     */
83     const std::string & asString() const;
84
85     /** Enumarator provided for use in \c switch statement. */
86     for_use_in_switch inSwitch() const
87     { return _type; }
88
89   private:
90     /** Ctor to initialize the dependency type contants. */
91     Dep( for_use_in_switch type_r )
92     : _type( type_r )
93     {}
94     /** The operator. */
95     for_use_in_switch _type;
96   };
97   ///////////////////////////////////////////////////////////////////
98
99   /** \relates Dep Stream output */
100   inline std::ostream & operator<<( std::ostream & str, const Dep & obj )
101   { return str << obj.asString(); }
102
103   ///////////////////////////////////////////////////////////////////
104
105   /** \relates Dep */
106   inline bool operator==( const Dep & lhs, const Dep & rhs )
107   { return lhs._type == rhs._type; }
108
109   /** \relates Dep */
110   inline bool operator!=( const Dep & lhs, const Dep & rhs )
111   { return lhs._type != rhs._type; }
112
113   /** \relates Dep */
114   inline bool operator<( const Dep & lhs, const Dep & rhs )
115   { return lhs._type < rhs._type; }
116
117   /////////////////////////////////////////////////////////////////
118 } // namespace zypp
119 ///////////////////////////////////////////////////////////////////
120 #endif // ZYPP_DEP_H