libzypp: zypp/ui/SelectableTraits.h Source File

libzypp 17.38.8

SelectableTraits.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_UI_SELECTABLETRAITS_H
13#define ZYPP_UI_SELECTABLETRAITS_H
14
15#include <set>
16#include <vector>
17
18#include <zypp-core/base/Iterator.h>
19#include <zypp/PoolItem.h>
20#include <zypp/pool/ByIdent.h>
21
23namespace zypp
24{
26 namespace ui
27 {
28
30 //
31 // CLASS NAME : SelectableTraits
32 //
34 struct SelectableTraits
35 {
44 struct AVOrder
45 {
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)!
50 //
51 bool operator()( const PoolItem & lhs, const PoolItem & rhs ) const
52 {
53 if ( lhs.isBlacklisted() != rhs.isBlacklisted() )
54 return rhs.isBlacklisted();
55
56 int lprio = lhs->satSolvable().repository().satInternalPriority();
57 int rprio = rhs->satSolvable().repository().satInternalPriority();
58 if ( lprio != rprio )
59 return( lprio > rprio );
60
61 // arch/noarch changes are ok.
62 if ( lhs->arch() != Arch_noarch && rhs->arch() != Arch_noarch )
63 {
64 int res = lhs->arch().compare( rhs->arch() );
65 if ( res )
66 return res > 0;
67 }
68
69 int res = lhs->edition().compare( rhs->edition() );
70 if ( res )
71 return res > 0;
72
73 lprio = lhs->buildtime();
74 rprio = rhs->buildtime();
75 if ( lprio != rprio )
76 return( lprio > rprio );
77
78 lprio = lhs->satSolvable().repository().satInternalSubPriority();
79 rprio = rhs->satSolvable().repository().satInternalSubPriority();
80 if ( lprio != rprio )
81 return( lprio > rprio );
82
83 // no more criteria, still equal: sort by id
84 return lhs.satSolvable().id() < rhs.satSolvable().id();
85 }
86 };
87
94 struct IOrder
95 {
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.
99 //
100 bool operator()( const PoolItem & lhs, const PoolItem & rhs ) const
101 {
102 int res = lhs->arch().compare( rhs->arch() );
103 if ( res )
104 return res > 0;
105 res = lhs->edition().compare( rhs->edition() );
106 if ( res )
107 return res > 0;
108 Date ldate = lhs->installtime();
109 Date rdate = rhs->installtime();
110 if ( ldate != rdate )
111 return( ldate > rdate );
112
113 // no more criteria, still equal: sort by id
114 return lhs.satSolvable().id() < rhs.satSolvable().id();
115 }
116 };
117
118 using AvailableItemSet = std::set<PoolItem, AVOrder>;
119 using available_iterator = AvailableItemSet::iterator;
120 using available_const_iterator = AvailableItemSet::const_iterator;
121 using available_size_type = AvailableItemSet::size_type;
122
123 using InstalledItemSet = std::set<PoolItem, IOrder>;
124 using installed_iterator = AvailableItemSet::iterator;
125 using installed_const_iterator = AvailableItemSet::const_iterator;
126 using installed_size_type = AvailableItemSet::size_type;
127
128 using PickList = std::vector<PoolItem>;
129 using picklist_iterator = PickList::const_iterator;
130 using picklist_size_type = PickList::size_type;
131 };
132
133
135 } // namespace ui
138} // namespace zypp
140#endif // ZYPP_UI_SELECTABLETRAITS_H
ByIdent.h
Iterator.h
PoolItem.h
zypp::Date
Store and operate on date (time_t).
Definition Date.h:33
zypp::PoolItem
Combining sat::Solvable and ResStatus.
Definition PoolItem.h:51
zypp::sat::Solvable::id
IdType id() const
Expert backdoor.
Definition Solvable.h:464
zypp::ui
Definition SolvIterMixin.cc:77
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::sat::SolvableType::isBlacklisted
bool isBlacklisted() const
Definition SolvableType.h:90
zypp::sat::SolvableType::satSolvable
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition SolvableType.h:57
zypp::ui::SelectableTraits::AVOrder
Oder on AvailableItemSet.
Definition SelectableTraits.h:45
zypp::ui::SelectableTraits::AVOrder::operator()
bool operator()(const PoolItem &lhs, const PoolItem &rhs) const
Definition SelectableTraits.h:51
zypp::ui::SelectableTraits::IOrder
Oder on InstalledItemSet.
Definition SelectableTraits.h:95
zypp::ui::SelectableTraits::IOrder::operator()
bool operator()(const PoolItem &lhs, const PoolItem &rhs) const
Definition SelectableTraits.h:100
zypp::ui::SelectableTraits
Definition SelectableTraits.h:35
zypp::ui::SelectableTraits::available_size_type
AvailableItemSet::size_type available_size_type
Definition SelectableTraits.h:121
zypp::ui::SelectableTraits::AvailableItemSet
std::set< PoolItem, AVOrder > AvailableItemSet
Definition SelectableTraits.h:118
zypp::ui::SelectableTraits::available_iterator
AvailableItemSet::iterator available_iterator
Definition SelectableTraits.h:119
zypp::ui::SelectableTraits::picklist_iterator
PickList::const_iterator picklist_iterator
Definition SelectableTraits.h:129
zypp::ui::SelectableTraits::picklist_size_type
PickList::size_type picklist_size_type
Definition SelectableTraits.h:130
zypp::ui::SelectableTraits::installed_const_iterator
AvailableItemSet::const_iterator installed_const_iterator
Definition SelectableTraits.h:125
zypp::ui::SelectableTraits::PickList
std::vector< PoolItem > PickList
Definition SelectableTraits.h:128
zypp::ui::SelectableTraits::installed_iterator
AvailableItemSet::iterator installed_iterator
Definition SelectableTraits.h:124
zypp::ui::SelectableTraits::available_const_iterator
AvailableItemSet::const_iterator available_const_iterator
Definition SelectableTraits.h:120
zypp::ui::SelectableTraits::installed_size_type
AvailableItemSet::size_type installed_size_type
Definition SelectableTraits.h:126
zypp::ui::SelectableTraits::InstalledItemSet
std::set< PoolItem, IOrder > InstalledItemSet
Definition SelectableTraits.h:123