1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
18 ///////////////////////////////////////////////////////////////////
20 { /////////////////////////////////////////////////////////////////
22 ///////////////////////////////////////////////////////////////////
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.
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
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.
41 * \ingroup g_EnumerationClass
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
57 static const Rel NONE;
60 /** Enumarators provided \b only for use \ref inSwitch statement.
63 enum for_use_in_switch { EQ_e, NE_e, LT_e, LE_e, GT_e, GE_e, ANY_e, NONE_e };
65 /** DefaultCtor ANY. */
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).
75 * Lower case names are accepted as well.
77 * \throw PARSE if \a strval_r is not legal.
78 * \todo refine exceptions and check throw.
81 Rel( const std::string & strval_r );
83 /** String representation of relational operator.
84 * \return "==", "!=", "<", "<=", ">", ">=", "ANY" or "NONE"
86 const std::string & asString() const;
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
95 * switch ( op.inSwitch() )
103 * // No default! Let compiler warn if case is missing
107 for_use_in_switch inSwitch() const
111 /** Ctor to initialize the relational operator contants. */
112 Rel( for_use_in_switch op_r )
116 for_use_in_switch _op;
118 ///////////////////////////////////////////////////////////////////
120 /** \relates Rel Stream output. */
121 inline std::ostream & operator<<( std::ostream & str, const Rel & obj )
122 { return str << obj.asString(); }
124 ///////////////////////////////////////////////////////////////////
127 inline bool operator==( const Rel & lhs, const Rel & rhs )
128 { return lhs.inSwitch() == rhs.inSwitch(); }
131 inline bool operator!=( const Rel & lhs, const Rel & rhs )
132 { return ! ( lhs == rhs ); }
134 /////////////////////////////////////////////////////////////////
136 ///////////////////////////////////////////////////////////////////