1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/NameKindProxy.h
12 #ifndef ZYPP_NAMEKINDPROXY_H
13 #define ZYPP_NAMEKINDPROXY_H
18 #include "zypp/ResPool.h"
20 ///////////////////////////////////////////////////////////////////
22 { /////////////////////////////////////////////////////////////////
24 namespace name_kind_proxy_details
26 struct IOrder : public std::binary_function<PoolItem,PoolItem,bool>
28 // NOTE: operator() provides LESS semantics to order the set.
29 // So LESS means 'prior in set'. We want the last item installed
31 /** \todo let ResObject provide installtime */
32 bool operator()( const PoolItem & lhs, const PoolItem & rhs ) const
34 // top should be installtime!
36 int res = lhs->arch().compare( rhs->arch() );
39 res = lhs->edition().compare( rhs->edition() );
43 // no more criteria, still equal:
44 // use the ResObject::constPtr (the poiner value)
45 // (here it's arbitrary whether < or > )
46 return lhs.resolvable() < rhs.resolvable();
50 struct AOrder : public std::binary_function<PoolItem,PoolItem,bool>
52 // NOTE: operator() provides LESS semantics to order the set.
53 // So LESS means 'prior in set'. We want 'better' archs and
54 // 'better' editions at the beginning of the set. So we return
55 // TRUE if (lhs > rhs)!
57 bool operator()( const PoolItem & lhs, const PoolItem & rhs ) const
59 int res = lhs->arch().compare( rhs->arch() );
62 res = lhs->edition().compare( rhs->edition() );
66 // no more criteria, still equal:
67 // use the ResObject::constPtr (the poiner value)
68 // (here it's arbitrary whether < or > )
69 return lhs.resolvable() < rhs.resolvable();
74 ///////////////////////////////////////////////////////////////////
76 // CLASS NAME : NameKindProxy
78 /** Retrieve and maintain PoolItem of a certain name and kind.
80 * Installed PoolItems are sorted according to their installtime
81 * (last installed first).
83 * Available PoolItems are sorted 'best first'.
85 * \todo provide status query and manipulation methods
89 typedef name_kind_proxy_details::IOrder IOrder;
90 typedef name_kind_proxy_details::AOrder AOrder;
92 typedef std::set<PoolItem,IOrder> InstalledSet;
93 typedef InstalledSet::iterator Installed_iterator;
94 typedef InstalledSet::const_iterator Installed_const_iterator;
95 typedef InstalledSet::size_type Installed_size_type;
97 typedef std::set<PoolItem,AOrder> AvailableSet;
98 typedef AvailableSet::iterator Available_iterator;
99 typedef AvailableSet::const_iterator Available_const_iterator;
100 typedef AvailableSet::size_type Available_size_type;
103 NameKindProxy( ResPool pool_r, IdString name_r, ResKind kind_r );
104 NameKindProxy( ResPool pool_r, const C_Str & name_r, ResKind kind_r );
110 IdString name() const
114 Installed_size_type installedSize() const
115 { return _installed.size(); }
117 bool installedEmpty() const
118 { return _installed.empty(); }
120 Installed_const_iterator installedBegin() const
121 { return _installed.begin(); }
123 Installed_const_iterator installedEnd() const
124 { return _installed.end(); }
127 Available_size_type availableSize() const
128 { return _available.size(); }
130 bool availableEmpty() const
131 { return _available.empty(); }
133 Available_const_iterator availableBegin() const
134 { return _available.begin(); }
136 Available_const_iterator availableEnd() const
137 { return _available.end(); }
141 // status query and manip stuff...
146 InstalledSet _installed;
147 AvailableSet _available;
149 ///////////////////////////////////////////////////////////////////
151 /** \relates NameKindProxy Stream output. */
152 std::ostream & operator<<( std::ostream & str, const NameKindProxy & obj );
154 /** \relates NameKindProxy Convenience construction. */
156 inline NameKindProxy nameKindProxy( ResPool pool_r, IdString name_r )
157 { return NameKindProxy( pool_r, name_r, ResTraits<_Res>::kind ); }
159 inline NameKindProxy nameKindProxy( ResPool pool_r, const C_Str & name_r )
160 { return NameKindProxy( pool_r, name_r, ResTraits<_Res>::kind ); }
162 /////////////////////////////////////////////////////////////////
164 ///////////////////////////////////////////////////////////////////
165 #endif // ZYPP_NAMEKINDPROXY_H