- Create the cache directly from the schema (installed) file.
[platform/upstream/libzypp.git] / zypp / Rel.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Rel.h
10  *
11 */
12 #ifndef ZYPP_REL_H
13 #define ZYPP_REL_H
14
15 #include <iosfwd>
16 #include <string>
17
18 ///////////////////////////////////////////////////////////////////
19 namespace zypp
20 { /////////////////////////////////////////////////////////////////
21
22   ///////////////////////////////////////////////////////////////////
23   //
24   //    CLASS NAME : Rel
25   //
26   /** Relational operators.
27    * Yes, it could as well be simply an \c enum.<BR>
28    * Yes, you can use the relational operators as if it was an \c enum.<BR>
29    * Except for use in a \c switch statement; see \ref inSwitch for this.
30    *
31    * But we want to construct them from a string representation, as well as
32    * providing one. And this way they are wrapped into a namespace, which is
33    * a good idea anyway.
34    *
35    * \ref ANY and \ref NONE are somewhat special. \ref ANY is the
36    * operator created by the default ctor, and it should always resolve
37    * to \c true. This may be handy in queries when you're looking for a
38    * Resolvable in \c ANY Edition if no operator was specified.
39    * While \ref NONE should always resolve to \c false.
40    *
41    * \ingroup g_EnumerationClass
42   */
43   struct Rel
44   {
45     /** \name Relational operators
46      * These are the \em real relational operator contants to
47      * use. Don't mind that it's not an enum. See also: \ref zypp::Rel::inSwitch
48     */
49     //@{
50     static const Rel EQ;
51     static const Rel NE;
52     static const Rel LT;
53     static const Rel LE;
54     static const Rel GT;
55     static const Rel GE;
56     static const Rel ANY;
57     static const Rel NONE;
58     //@}
59
60     /** Enumarators provided \b only for use \ref inSwitch statement.
61      * \see inSwitch
62     */
63     enum for_use_in_switch { EQ_e, NE_e, LT_e, LE_e, GT_e, GE_e, ANY_e, NONE_e };
64
65     /** DefaultCtor ANY. */
66     Rel()
67     : _op( ANY_e )
68     {}
69
70     /** Ctor from string.
71      * Legal values for \a strval_r are: "==", "!=", "<", "<=", ">", ">=",<BR>
72      * as well as "EQ", "NE", "LT", "LE", "GT", "GE", "ANY", "NONE"<BR>
73      * and "" (empty string resolves to ANY).
74      *
75      * Lower case names are accepted as well.
76      *
77      * \throw PARSE if \a strval_r is not legal.
78      * \todo refine exceptions and check throw.
79     */
80     explicit
81     Rel( const std::string & strval_r );
82
83     /** String representation of relational operator.
84      * \return "==", "!=", "<", "<=", ">", ">=", "ANY" or "NONE"
85     */
86     const std::string & asString() const;
87
88     /** Enumarator provided for use in \c switch statement.
89      * The sole reason for providing enum \ref for_use_in_switch is,
90      * that we may want to use the relational operators in a \c switch
91      * statement. Tht's the only case where you should have to use the
92      * enumarator.
93      * \code
94      *   Rel op;
95      *   switch ( op.inSwitch() )
96      *     {
97      *     case Rel::EQ_e:
98      *       ...
99      *       break;
100      *     case Rel::NE_e:
101      *       ...
102      *
103      *     // No default! Let compiler warn if case is missing
104      *     }
105      * \endcode
106     */
107     for_use_in_switch inSwitch() const
108     { return _op; }
109
110   private:
111     /** Ctor to initialize the relational operator contants. */
112     Rel( for_use_in_switch op_r )
113     : _op( op_r )
114     {}
115     /** The operator. */
116     for_use_in_switch _op;
117   };
118   ///////////////////////////////////////////////////////////////////
119
120   /** \relates Rel Stream output. */
121   inline std::ostream & operator<<( std::ostream & str, const Rel & obj )
122   { return str << obj.asString(); }
123
124   ///////////////////////////////////////////////////////////////////
125
126   /** \relates Rel */
127   inline bool operator==( const Rel & lhs, const Rel & rhs )
128   { return lhs.inSwitch() == rhs.inSwitch(); }
129
130   /** \relates Rel */
131   inline bool operator!=( const Rel & lhs, const Rel & rhs )
132   { return ! ( lhs == rhs ); }
133
134   /////////////////////////////////////////////////////////////////
135 } // namespace zypp
136 ///////////////////////////////////////////////////////////////////
137 #endif // ZYPP_REL_H