libzypp  17.1.1
Comparison using relational operator zypp::Rel.

Classes

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

Functions

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

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 ); // 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

◆ compareByRel() [1/2]

template<class Tp , class TCompare >
bool zypp::compareByRel ( Rel  op,
const Tp &  lhs,
const Tp &  rhs,
TCompare  compare 
)
inline

Comparison of two elements using relational operator op.

Expects TCompare 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.

◆ compareByRel() [2/2]

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 144 of file RelCompare.h.