1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ui/SelectableTraits.h
12 #ifndef ZYPP_UI_SELECTABLETRAITS_H
13 #define ZYPP_UI_SELECTABLETRAITS_H
18 #include "zypp/base/Iterator.h"
19 #include "zypp/PoolItem.h"
20 #include "zypp/pool/ByIdent.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
31 // CLASS NAME : SelectableTraits
34 struct SelectableTraits
36 /** Oder on AvailableItemSet.
37 * \li repository priority
38 * \li best Arch (arch/noarch changes are ok)
41 * \li ResObject::constPtr as fallback.
43 struct AVOrder : public std::binary_function<PoolItem,PoolItem,bool>
45 // NOTE: operator() provides LESS semantics to order the set.
46 // So LESS means 'prior in set'. We want 'better' archs and
47 // 'better' editions at the beginning of the set. So we return
48 // TRUE if (lhs > rhs)!
50 bool operator()( const PoolItem & lhs, const PoolItem & rhs ) const
52 int lprio = lhs->satSolvable().repository().satInternalPriority();
53 int rprio = rhs->satSolvable().repository().satInternalPriority();
55 return( lprio > rprio );
57 // arch/noarch changes are ok.
58 if ( lhs->arch() != Arch_noarch && rhs->arch() != Arch_noarch )
60 int res = lhs->arch().compare( rhs->arch() );
65 int res = lhs->edition().compare( rhs->edition() );
69 lprio = lhs->buildtime();
70 rprio = rhs->buildtime();
72 return( lprio > rprio );
74 lprio = lhs->satSolvable().repository().satInternalSubPriority();
75 rprio = rhs->satSolvable().repository().satInternalSubPriority();
77 return( lprio > rprio );
79 // no more criteria, still equal: sort by id
80 return lhs.satSolvable().id() < rhs.satSolvable().id();
84 /** Oder on InstalledItemSet.
87 * \li newer install time
88 * \li ResObject::constPtr as fallback.
90 struct IOrder : public std::binary_function<PoolItem,PoolItem,bool>
92 // NOTE: operator() provides LESS semantics to order the set.
93 // So LESS means 'prior in set'. We want 'newer' install time
94 // at the beginning of the set.
96 bool operator()( const PoolItem & lhs, const PoolItem & rhs ) const
98 int res = lhs->arch().compare( rhs->arch() );
101 res = lhs->edition().compare( rhs->edition() );
104 Date ldate = lhs->installtime();
105 Date rdate = rhs->installtime();
106 if ( ldate != rdate )
107 return( ldate > rdate );
109 // no more criteria, still equal: sort by id
110 return lhs.satSolvable().id() < rhs.satSolvable().id();
114 typedef std::set<PoolItem,AVOrder> AvailableItemSet;
115 typedef AvailableItemSet::iterator available_iterator;
116 typedef AvailableItemSet::const_iterator available_const_iterator;
117 typedef AvailableItemSet::size_type available_size_type;
119 typedef std::set<PoolItem,IOrder> InstalledItemSet;
120 typedef AvailableItemSet::iterator installed_iterator;
121 typedef AvailableItemSet::const_iterator installed_const_iterator;
122 typedef AvailableItemSet::size_type installed_size_type;
124 typedef std::vector<PoolItem> PickList;
125 typedef PickList::const_iterator picklist_iterator;
126 typedef PickList::size_type picklist_size_type;
128 ///////////////////////////////////////////////////////////////////
130 /////////////////////////////////////////////////////////////////
132 ///////////////////////////////////////////////////////////////////
133 /////////////////////////////////////////////////////////////////
135 ///////////////////////////////////////////////////////////////////
136 #endif // ZYPP_UI_SELECTABLETRAITS_H