Comparison using relational operator zypp::Rel.

More...


Classes

struct  zypp::Compare< _Tp >
 General compare functor returning -1, 0, 1. More...
struct  zypp::CompareBy< _Tp, _Compare >
 Functor to compare two elements by Rel based on a general _Compare functor. More...
struct  zypp::CompareByEQ< _Tp, _Compare >
struct  zypp::CompareByNE< _Tp, _Compare >
struct  zypp::CompareByLT< _Tp, _Compare >
struct  zypp::CompareByLE< _Tp, _Compare >
struct  zypp::CompareByGT< _Tp, _Compare >
struct  zypp::CompareByGE< _Tp, _Compare >
struct  zypp::CompareByANY< _Tp, _Compare >
struct  zypp::CompareByNONE< _Tp, _Compare >

Functions

template<class _Tp , class _Compare >
bool zypp::compareByRel (Rel op, const _Tp &lhs, const _Tp &rhs, _Compare compare)
 Comparison of two elements using relational operator op.
template<class _Tp >
bool zypp::compareByRel (Rel op, const _Tp &lhs, const _Tp &rhs)
 compareByRel convenience using Compare<_Tp> as general compare functor.


Detailed Description

Take a class like zypp::Edition. Editions are comaprable. You can compare them lexicographical, or according to their version and release values, or match them (i.e. taking empty version or release values as wildcard).

No matter which way is appropriate within a certain context. You need functions to compare, and may want to use classes like zypp::Range, based on the desired comparison.

All the class has to do, is providing a general comparison method (preferably static)

     // Compare two elements returning -1, 0, 1
     //  if the elemants compare <,==,>.
     static int compare( const _Tp & lhs, const _Tp & rhs );

Compare<_Tp> provides a functor wrapping compare. In case the general comparison method is named differently, the class, or you, have to provide an approriate functor.

compareByRel then compares two elements using a certain operator and general comparison method.

 compareByRel( Rel::EQ, lhs, rhs, Edition::compare );
 compareByRel( Rel::EQ, lhs, rhs, Edition::match );
 compareByRel( Rel::EQ, lhs, rhs ); // defaults to Compare<Edition>
                                    // thus Edition::compare

Furthermore a bunch of functors using a certain opertator is defined. All templated by type and general comparison method (defaults to Compare<_Tp>).

 // Editions sets use lexicographical order per default:
 std::set<Edition>

 // An Edition set using Edition::compare as order:
 std::set<Edition,CompareByLT<Edition> >;

 // Edition::match is not transitive, thus not an appropriate
 // order relation for std::set or std::map.

Classes like zypp:Range are templated by by type and general comparison method as well. Thus you may use Edition ranges based on Edition::Compare, as well as ranges based on Edition::Match (Edition provides these two functors).

Again: Everything a class has to provide is the general comparison method. Comparison functors and ranges are then immediately available.


Function Documentation

template<class _Tp , class _Compare >
bool zypp::compareByRel ( Rel  op,
const _Tp &  lhs,
const _Tp &  rhs,
_Compare  compare 
) [inline]

Comparison of two elements using relational operator op.

Expects _Compare to be a binary operator returning -1, 0, 1 if the elemants compare <,==,>.

     // Signature of compare function or functor:
     int compare( const _Tp & lhs, const _Tp & rhs );
  • If op is Rel::ANY, the expression is always true.
  • If op is Rel::NONE, the expression is always false.
  • Otherwise the expression is evaluated using compare.

Definition at line 108 of file RelCompare.h.

References zypp::Rel::ANY_e, zypp::Rel::EQ_e, zypp::Rel::GE_e, zypp::Rel::GT_e, zypp::Rel::inSwitch(), zypp::Rel::LE_e, zypp::Rel::LT_e, zypp::Rel::NE_e, and zypp::Rel::NONE_e.

Referenced by zypp::compareByRel(), zypp::detail::PoolQueryMatcher::isAMatch(), zypp::CompareByNONE< _Tp, _Compare >::operator()(), zypp::CompareByANY< _Tp, _Compare >::operator()(), zypp::CompareByGE< _Tp, _Compare >::operator()(), zypp::CompareByGT< _Tp, _Compare >::operator()(), zypp::CompareByLE< _Tp, _Compare >::operator()(), zypp::CompareByLT< _Tp, _Compare >::operator()(), zypp::CompareByNE< _Tp, _Compare >::operator()(), zypp::CompareByEQ< _Tp, _Compare >::operator()(), and zypp::CompareBy< _Tp, _Compare >::operator()().

template<class _Tp >
bool zypp::compareByRel ( Rel  op,
const _Tp &  lhs,
const _Tp &  rhs 
) [inline]

compareByRel convenience using Compare<_Tp> as general compare functor.

Definition at line 145 of file RelCompare.h.

References zypp::compareByRel().


doxygen