Rel.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_REL_H
00013 #define ZYPP_REL_H
00014
00015 #include <iosfwd>
00016 #include <string>
00017
00019 namespace zypp
00020 {
00021
00023
00024
00025
00043 struct Rel
00044 {
00050 static const Rel EQ;
00051 static const Rel NE;
00052 static const Rel LT;
00053 static const Rel LE;
00054 static const Rel GT;
00055 static const Rel GE;
00056 static const Rel ANY;
00057 static const Rel NONE;
00059
00065 enum for_use_in_switch {
00066 NONE_e = 0U,
00067 GT_e = 1U,
00068 EQ_e = 2U,
00069 LT_e = 4U,
00070 GE_e = GT_e|EQ_e,
00071 LE_e = LT_e|EQ_e,
00072 NE_e = GT_e|LT_e,
00073 ANY_e = GT_e|EQ_e|LT_e,
00074 };
00075
00077 Rel()
00078 : _op( ANY_e )
00079 {}
00080
00091 explicit
00092 Rel( const std::string & strval_r );
00093
00097 Rel( const std::string & strval_r, const Rel & default_r );
00098
00102 bool parseFrom( const std::string & strval_r );
00103
00105 explicit
00106 Rel( unsigned bits_r )
00107 : _op( for_use_in_switch(bits_r & ANY_e) )
00108 {}
00109
00111 static bool isRel( unsigned bits_r )
00112 { return (bits_r & ANY_e) == bits_r; }
00113
00117 const std::string & asString() const;
00119 const char * c_str() const
00120 { return asString().c_str(); }
00121
00141 for_use_in_switch inSwitch() const
00142 { return _op; }
00143
00145 unsigned bits() const
00146 { return _op; }
00147
00148 private:
00150 Rel( for_use_in_switch op_r )
00151 : _op( op_r )
00152 {}
00154 for_use_in_switch _op;
00155 };
00157
00159 inline std::ostream & operator<<( std::ostream & str, const Rel & obj )
00160 { return str << obj.asString(); }
00161
00163
00165 inline bool operator==( const Rel & lhs, const Rel & rhs )
00166 { return lhs.inSwitch() == rhs.inSwitch(); }
00167
00169 inline bool operator!=( const Rel & lhs, const Rel & rhs )
00170 { return ! ( lhs == rhs ); }
00171
00173 }
00175 #endif // ZYPP_REL_H