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.
38 * \li repository priority
39 * \li best Arch (arch/noarch changes are ok)
42 * \li ResObject::constPtr as fallback.
44 struct AVOrder : public std::binary_function<PoolItem,PoolItem,bool>
46 // NOTE: operator() provides LESS semantics to order the set.
47 // So LESS means 'prior in set'. We want 'better' archs and
48 // 'better' editions at the beginning of the set. So we return
49 // TRUE if (lhs > rhs)!
51 bool operator()( const PoolItem & lhs, const PoolItem & rhs ) const
53 if ( lhs.isRetracted() != rhs.isRetracted() )
54 return rhs.isRetracted();
56 int lprio = lhs->satSolvable().repository().satInternalPriority();
57 int rprio = rhs->satSolvable().repository().satInternalPriority();
59 return( lprio > rprio );
61 // arch/noarch changes are ok.
62 if ( lhs->arch() != Arch_noarch && rhs->arch() != Arch_noarch )
64 int res = lhs->arch().compare( rhs->arch() );
69 int res = lhs->edition().compare( rhs->edition() );
73 lprio = lhs->buildtime();
74 rprio = rhs->buildtime();
76 return( lprio > rprio );
78 lprio = lhs->satSolvable().repository().satInternalSubPriority();
79 rprio = rhs->satSolvable().repository().satInternalSubPriority();
81 return( lprio > rprio );
83 // no more criteria, still equal: sort by id
84 return lhs.satSolvable().id() < rhs.satSolvable().id();
88 /** Oder on InstalledItemSet.
91 * \li newer install time
92 * \li ResObject::constPtr as fallback.
94 struct IOrder : public std::binary_function<PoolItem,PoolItem,bool>
96 // NOTE: operator() provides LESS semantics to order the set.
97 // So LESS means 'prior in set'. We want 'newer' install time
98 // at the beginning of the set.
100 bool operator()( const PoolItem & lhs, const PoolItem & rhs ) const
102 int res = lhs->arch().compare( rhs->arch() );
105 res = lhs->edition().compare( rhs->edition() );
108 Date ldate = lhs->installtime();
109 Date rdate = rhs->installtime();
110 if ( ldate != rdate )
111 return( ldate > rdate );
113 // no more criteria, still equal: sort by id
114 return lhs.satSolvable().id() < rhs.satSolvable().id();
118 typedef std::set<PoolItem,AVOrder> AvailableItemSet;
119 typedef AvailableItemSet::iterator available_iterator;
120 typedef AvailableItemSet::const_iterator available_const_iterator;
121 typedef AvailableItemSet::size_type available_size_type;
123 typedef std::set<PoolItem,IOrder> InstalledItemSet;
124 typedef AvailableItemSet::iterator installed_iterator;
125 typedef AvailableItemSet::const_iterator installed_const_iterator;
126 typedef AvailableItemSet::size_type installed_size_type;
128 typedef std::vector<PoolItem> PickList;
129 typedef PickList::const_iterator picklist_iterator;
130 typedef PickList::size_type picklist_size_type;
132 ///////////////////////////////////////////////////////////////////
134 /////////////////////////////////////////////////////////////////
136 ///////////////////////////////////////////////////////////////////
137 /////////////////////////////////////////////////////////////////
139 ///////////////////////////////////////////////////////////////////
140 #endif // ZYPP_UI_SELECTABLETRAITS_H