00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_NAMEKINDPROXY_H
00013 #define ZYPP_NAMEKINDPROXY_H
00014
00015 #include <iosfwd>
00016 #include <set>
00017
00018 #include "zypp/ResPool.h"
00019
00021 namespace zypp
00022 {
00023
00024 namespace name_kind_proxy_details
00025 {
00026 struct IOrder : public std::binary_function<PoolItem,PoolItem,bool>
00027 {
00028
00029
00030
00032 bool operator()( const PoolItem & lhs, const PoolItem & rhs ) const
00033 {
00034
00035
00036 int res = lhs->arch().compare( rhs->arch() );
00037 if ( res )
00038 return res > 0;
00039 res = lhs->edition().compare( rhs->edition() );
00040 if ( res )
00041 return res > 0;
00042
00043
00044
00045
00046 return lhs.resolvable() < rhs.resolvable();
00047 }
00048 };
00049
00050 struct AOrder : public std::binary_function<PoolItem,PoolItem,bool>
00051 {
00052
00053
00054
00055
00056
00057 bool operator()( const PoolItem & lhs, const PoolItem & rhs ) const
00058 {
00059 int res = lhs->arch().compare( rhs->arch() );
00060 if ( res )
00061 return res > 0;
00062 res = lhs->edition().compare( rhs->edition() );
00063 if ( res )
00064 return res > 0;
00065
00066
00067
00068
00069 return lhs.resolvable() < rhs.resolvable();
00070 }
00071 };
00072 }
00073
00075
00076
00077
00087 class NameKindProxy
00088 {
00089 typedef name_kind_proxy_details::IOrder IOrder;
00090 typedef name_kind_proxy_details::AOrder AOrder;
00091 public:
00092 typedef std::set<PoolItem,IOrder> InstalledSet;
00093 typedef InstalledSet::iterator Installed_iterator;
00094 typedef InstalledSet::const_iterator Installed_const_iterator;
00095 typedef InstalledSet::size_type Installed_size_type;
00096
00097 typedef std::set<PoolItem,AOrder> AvailableSet;
00098 typedef AvailableSet::iterator Available_iterator;
00099 typedef AvailableSet::const_iterator Available_const_iterator;
00100 typedef AvailableSet::size_type Available_size_type;
00101
00102 public:
00103 NameKindProxy( ResPool pool_r,
00104 const std::string & name_r, Resolvable::Kind kind_r );
00105
00106 public:
00107 ResObject::Kind kind() const
00108 { return _kind; }
00109
00110 const std::string & name() const
00111 { return _name; }
00112
00113 public:
00114 Installed_size_type installedSize() const
00115 { return _installed.size(); }
00116
00117 bool installedEmpty() const
00118 { return _installed.empty(); }
00119
00120 Installed_const_iterator installedBegin() const
00121 { return _installed.begin(); }
00122
00123 Installed_const_iterator installedEnd() const
00124 { return _installed.end(); }
00125
00126 public:
00127 Available_size_type availableSize() const
00128 { return _available.size(); }
00129
00130 bool availableEmpty() const
00131 { return _available.empty(); }
00132
00133 Available_const_iterator availableBegin() const
00134 { return _available.begin(); }
00135
00136 Available_const_iterator availableEnd() const
00137 { return _available.end(); }
00138
00139 public:
00140
00141
00142
00143 private:
00144 ResObject::Kind _kind;
00145 std::string _name;
00146 InstalledSet _installed;
00147 AvailableSet _available;
00148 };
00150
00152 std::ostream & operator<<( std::ostream & str, const NameKindProxy & obj );
00153
00155 template<class _Res>
00156 inline NameKindProxy nameKindProxy( ResPool pool_r, const std::string & name_r )
00157 { return NameKindProxy( pool_r, name_r, ResTraits<_Res>::kind ); }
00158
00160 }
00162 #endif // ZYPP_NAMEKINDPROXY_H